增加群消息本机搜索和加密收藏

This commit is contained in:
xhgit committed 2026-11-14 09:30:34 +08:00
1 parent 5b7c03e4ec
commit 2e51827a07
5 files changed
+109 -13

No files matched your search

+33 -8
View File
@@ -7,7 +7,7 @@ import MediaPreview from './MediaPreview.vue'
import VoiceMessage from './VoiceMessage.vue'
import VoiceRecorder from './VoiceRecorder.vue'
import { enableChat, trust } from './chat'
import { discardPendingGroupMessage, groupAttachmentPath, groupQuote, publishGroup, sendGroupMessage, synchronizeGroup } from './group-chat'
import { discardPendingGroupMessage, groupAttachmentPath, groupQuote, publishGroup, sendGroupMessage, setGroupFavorite, synchronizeGroup } from './group-chat'
import type { GroupDetail, GroupDevice, GroupLine } from './group-chat'
const props = defineProps<{ group: GroupDetail }>()
@@ -17,6 +17,8 @@ const code = ref('')
const codes = ref<Record<string, string>>({})
const selected = ref<Record<string, string>>({})
const draft = ref('')
const search = ref('')
const favoritesOnly = ref(false)
const replying = ref<GroupLine>()
const editing = ref<GroupLine>()
const recalling = ref<GroupLine>()
@@ -26,6 +28,12 @@ const busy = ref(false)
const error = ref('')
const ready = computed(() => view.value?.ready && view.value.current?.membershipVersion === props.group.membershipVersion)
const currentEpoch = computed(() => ready.value ? view.value?.current?.id : undefined)
const lines = computed(() => {
const query = search.value.trim().toLowerCase()
return (view.value?.lines ?? []).filter((line) =>
(!favoritesOnly.value || line.favorite) &&
(!query || [line.text, line.quote, line.attachment?.name].some((part) => part?.toLowerCase().includes(query))))
})
const members = computed(() => props.group.members.filter((member) => member.state === 'active' && member.id !== session.identity?.user.id))
const canPublish = computed(() => Boolean(view.value && !view.value.current && members.value.every((member) =>
view.value?.devices.some((device) => device.user === member.id && device.id === selected.value[member.id] && pinned(device)))))
@@ -142,6 +150,14 @@ function download(attachment: Attachment) {
void run(() => downloadAttachment(attachment, session.authorized, groupAttachmentPath(props.group, attachment.id)))
}
function favorite(line: GroupLine) {
const identity = session.identity
if (identity) void run(async () => {
const updated = await setGroupFavorite(identity, props.group, line, !line.favorite)
if (view.value) view.value.lines = updated
})
}
function discard() {
const identity = session.identity
if (identity) void run(async () => {
@@ -212,8 +228,13 @@ onBeforeUnmount(() => clearInterval(timer))
</div>
<button v-if="group.role === 'owner' && !view?.current" class="primary" :disabled="busy || !canPublish" @click="establish">建立群加密会话</button>
</details>
<ul v-if="view?.lines.length" class="group-chat-lines" aria-label="群消息记录">
<li v-for="line in view.lines" :key="[line.epoch, line.sender, line.id].join('/')">
<div v-if="view?.lines.length || search || favoritesOnly" class="group-chat-search">
<label>搜索本机群消息<input v-model="search" type="search" maxlength="120"></label>
<label class="chat-checkbox"><input v-model="favoritesOnly" type="checkbox">只看收藏</label>
</div>
<p v-if="!lines.length && (search.trim() || favoritesOnly)" class="muted" role="status">没有匹配的群消息。</p>
<ul v-if="lines.length" class="group-chat-lines" aria-label="群消息记录">
<li v-for="line in lines" :key="[line.epoch, line.sender, line.id].join('/')">
<small>{{ line.name }} · {{ new Date(line.time).toLocaleString() }}</small>
<blockquote v-if="line.quote">{{ line.quote }}</blockquote>
<p v-if="line.recalled" class="muted">消息已撤回</p>
@@ -225,11 +246,14 @@ onBeforeUnmount(() => clearInterval(timer))
</template>
<p v-else>{{ line.text }}</p>
<small v-if="line.edited && !line.recalled" class="muted">已编辑</small>
<div v-if="currentEpoch && line.epoch === currentEpoch && !line.recalled" class="message-actions">
<button type="button" class="plain" :disabled="busy || view.hasPending || !!editing" @click="replying = line">引用</button>
<template v-if="line.sender === session.identity?.device.id">
<button v-if="!line.attachment" type="button" class="plain" :disabled="busy || view.hasPending" @click="edit(line)">编辑</button>
<button type="button" class="plain" :disabled="busy || view.hasPending" @click="recalling = line">撤回</button>
<div v-if="!line.recalled" class="message-actions">
<button type="button" class="plain" :disabled="busy" @click="favorite(line)">{{ line.favorite ? '取消收藏' : '收藏' }}</button>
<template v-if="currentEpoch && line.epoch === currentEpoch">
<button type="button" class="plain" :disabled="busy || view?.hasPending || !!editing" @click="replying = line">引用</button>
<template v-if="line.sender === session.identity?.device.id">
<button v-if="!line.attachment" type="button" class="plain" :disabled="busy || view?.hasPending" @click="edit(line)">编辑</button>
<button type="button" class="plain" :disabled="busy || view?.hasPending" @click="recalling = line">撤回</button>
</template>
</template>
</div>
</li>
@@ -277,6 +301,7 @@ onBeforeUnmount(() => clearInterval(timer))
.group-chat-lines { display: grid; gap: .75rem; max-height: 24rem; overflow-y: auto; margin: 0; padding: .7rem 0; list-style: none; }
.group-chat-lines p { white-space: pre-wrap; overflow-wrap: anywhere; }
.group-chat-lines blockquote { margin: .25rem 0; padding-inline-start: .5rem; border-inline-start: 2px solid currentColor; overflow-wrap: anywhere; }
.group-chat-search { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem; }
.group-chat-composer { display: grid; gap: .55rem; }
.group-chat-composer textarea { display: block; width: 100%; resize: vertical; font: inherit; }
.group-chat button { justify-self: start; }