增加加密引用回复和本机消息管理

This commit is contained in:
xhgit committed 2026-11-13 19:17:13 +08:00
1 parent c24960d22a
commit c27ad52dab
7 files changed
+121 -8

No files matched your search

+53 -4
View File
@@ -2,7 +2,8 @@
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useSession } from '../session'
import { enableChat, send, synchronize, trust } from '../chat/chat'
import { enableChat, localMessageAction, send, synchronize, trust } from '../chat/chat'
import type { ChatLine } from '../chat/chat'
import { downloadAttachment } from '../chat/attachments'
import type { Attachment } from '../chat/attachments'
@@ -12,6 +13,10 @@ const ownCode = ref('')
const code = ref('')
const selected = ref('')
const draft = ref('')
const search = ref('')
const favoritesOnly = ref(false)
const reply = ref<ChatLine>()
const deleting = ref<ChatLine>()
const error = ref('')
const busy = ref(false)
const view = ref<Awaited<ReturnType<typeof synchronize>>>()
@@ -19,7 +24,12 @@ const target = computed(() => typeof route.params.user === 'string' ? route.para
const peer = computed(() => view.value?.peers.find((item) => item.id === selected.value))
const trusted = computed(() => peer.value && view.value?.pinned[peer.value.id] === peer.value.publicKey)
const changed = computed(() => peer.value && view.value?.pinned[peer.value.id] && !trusted.value)
const lines = computed(() => (view.value?.lines ?? []).filter((line) => line.peer === selected.value))
const lines = computed(() => {
const query = search.value.trim().toLowerCase()
return (view.value?.lines ?? []).filter((line) => line.peer === selected.value &&
(!favoritesOnly.value || line.favorite) &&
(!query || [line.text, line.attachment?.name, line.quote].some((part) => part?.toLowerCase().includes(query))))
})
let timer: ReturnType<typeof setInterval>
async function execute(action: () => Promise<void>) {
@@ -65,8 +75,9 @@ function confirm() {
function submit() {
void execute(async () => {
if (!session.identity || !peer.value) return
await send(session.identity, target.value, peer.value, draft.value, session.authorized)
await send(session.identity, target.value, peer.value, draft.value, session.authorized, reply.value)
draft.value = ''
reply.value = undefined
await refresh()
})
}
@@ -87,6 +98,16 @@ function saveAttachment(attachment: Attachment) {
void execute(() => downloadAttachment(attachment, session.authorized))
}
function localAction(line: ChatLine, action: 'favorite' | 'remove') {
void execute(async () => {
if (!session.identity) return
await localMessageAction(session.identity, line, action)
deleting.value = undefined
if (action === 'remove' && reply.value?.id === line.id) reply.value = undefined
await refresh()
})
}
function sync() {
if (ownCode.value) void execute(refresh)
}
@@ -98,6 +119,12 @@ watch(target, () => {
draft.value = ''
sync()
})
watch(selected, () => {
search.value = ''
favoritesOnly.value = false
reply.value = undefined
deleting.value = undefined
})
watch(() => [session.inboxChanges, session.contactChanges, session.connection], sync)
onMounted(() => { timer = setInterval(sync, 10_000) })
onBeforeUnmount(() => clearInterval(timer))
@@ -135,14 +162,36 @@ onBeforeUnmount(() => clearInterval(timer))
<p class="verified-label">设备已验证</p>
<p v-if="view?.deliveryError" class="error">{{ view.deliveryError }}</p>
<p v-if="view?.rejected" class="muted">已拒绝 {{ view.rejected }} 个无法验证的封包。</p>
<div class="chat-filters">
<label>搜索本机消息<input v-model="search" type="search" maxlength="120"></label>
<label class="chat-checkbox"><input v-model="favoritesOnly" type="checkbox">只看收藏</label>
</div>
<ol class="chat-lines" aria-label="消息记录" aria-live="polite">
<li v-for="line in lines" :key="line.id" :class="{ own: line.own }">
<li v-for="line in lines" :key="line.peer + ':' + line.own + ':' + line.id" :class="{ own: line.own }">
<blockquote v-if="line.quote">{{ line.quote }}</blockquote>
<button v-if="line.attachment" type="button" class="plain" :disabled="busy"
@click="saveAttachment(line.attachment)">下载 {{ line.attachment.name }}</button>
<span v-else>{{ line.text }}</span><small v-if="view?.unsent.includes(line.id)">待发送</small>
<div class="message-actions">
<button type="button" class="plain" :disabled="busy" @click="reply = line">引用</button>
<button type="button" class="plain" :disabled="busy" @click="localAction(line, 'favorite')">
{{ line.favorite ? '取消收藏' : '收藏' }}
</button>
<button type="button" class="plain" :disabled="busy || view?.unsent.includes(line.id)" @click="deleting = line">本机删除</button>
</div>
</li>
</ol>
<p v-if="(search || favoritesOnly) && !lines.length" class="muted">没有匹配的消息。</p>
<div v-if="deleting" class="confirmation">
<p>从本机删除这条消息?</p>
<button type="button" class="plain" :disabled="busy" @click="localAction(deleting, 'remove')">确认删除</button>
<button type="button" class="plain" @click="deleting = undefined">取消</button>
</div>
<form class="chat-compose" @submit.prevent="submit">
<div v-if="reply" class="chat-quote">
<span>引用 {{ (reply.text || reply.attachment?.name || '').slice(0, 80) }}</span>
<button type="button" class="plain" @click="reply = undefined">取消引用</button>
</div>
<label>发送附件<input type="file" :disabled="busy" @change="attach"></label>
<label>消息<textarea v-model="draft" required rows="3" maxlength="4000"></textarea></label>
<button class="primary" :disabled="busy || !draft.trim()">发送</button>