Merge pull request '增加群消息本机搜索和加密收藏' (#28) from xhgit/group-search-favorites into main
Reviewed-on: http://git.xhmcl.com/xhgit/XHChat/pulls/28
This commit was merged in pull request #28.
This commit is contained in:
commit
2c8a2c8788
5 files changed
+109
-13
No files matched your search
@@ -22,7 +22,7 @@
|
||||
| 加密群聊 | 创建群组、邀请联系人和管理成员。每个账号选一台已核验设备参与 MLS 加密文字聊天。 |
|
||||
| 加密附件 | 两端可在私聊和群聊发送、下载最多 8 MiB 的文件,并在本机预览图片和视频。 |
|
||||
| 加密语音 | 两端可在私聊和群聊录制、取消或发送最长 60 秒的语音消息,接收方在本机解密播放。 |
|
||||
| 消息管理 | 私聊和群聊支持引用回复、编辑文字和撤回。私聊还支持可选加密已读回执、转发、本机搜索和收藏。 |
|
||||
| 消息管理 | 私聊和群聊支持引用回复、编辑文字、撤回、本机搜索和收藏。私聊还支持可选加密已读回执和转发。 |
|
||||
| Chromium 浏览器 | Windows 端支持独立窗口、多标签、导航、搜索、书签、历史、下载和隐私窗口,网页运行在独立会话中。 |
|
||||
|
||||
当前为开发预览。大文件分片、音视频和多设备历史同步仍在开发,Windows 安装包尚未发布。 [开发进度与验收记录](docs/progress.md)
|
||||
|
||||
+7
-1
@@ -19,7 +19,7 @@ Web 和 Electron 共用 Vue 客户端,独立接入同一 Go API。真实 Postg
|
||||
## 尚待实现
|
||||
|
||||
- 阶段一还需邮箱和手机号注册、验证码服务、找回密码和双重验证。真实联调需要 SMTP 与短信供应商配置。
|
||||
- 阶段二与三还需分片附件、群聊转发与收藏、多设备可信授权、加密备份与跨设备历史同步。群聊和私聊的文字及小附件已进入开发预览。
|
||||
- 阶段二与三还需分片附件、群聊转发、多设备可信授权、加密备份与跨设备历史同步。群聊和私聊的文字及小附件已进入开发预览。
|
||||
- 阶段四还需 WebRTC 音视频、TURN、SFU、屏幕共享及媒体 E2EE。
|
||||
- 阶段五还需反钓鱼及聊天联动。
|
||||
- 阶段六到八还需社交、扩展生态、独立管理后台、推送、生产部署与备份演练、压力测试、安全评估、签名安装包和发布流程。
|
||||
@@ -126,3 +126,9 @@ Windows Electron 与 Edge 集成测试使用虚拟麦克风验证双向播放和
|
||||
Windows 与 Web 可在当前加密会话引用消息、编辑自己发送的文字及撤回自己发送的消息。客户端按原消息 ID、MLS 会话及发送设备校验编辑和撤回。引用片段、更新类型及目标标识留在 MLS 密文中。此前缓存且未记录会话标识的消息,以及旧会话中的消息仍可查看。撤回更新聊天显示,成员已经下载或复制的内容仍可能保留。
|
||||
|
||||
Windows Electron 与 Edge 验证引用渲染、编辑补收、文字与图片撤回、其他成员不可操作及旧会话的操作限制。私聊和服务端密文投递回归通过。
|
||||
|
||||
## 群消息本机搜索和收藏
|
||||
|
||||
在群聊中可组合使用关键词和「只看收藏」,搜索本机已解密的消息文本、引用与附件名。收藏状态保存在设备的加密存储中,保留超过最近 1,000 条的收藏记录,撤回会取消收藏。附件仍受原会话权限和服务端保留期限制。跨设备收藏同步待实现。
|
||||
|
||||
Windows Electron 与 Edge 集成测试覆盖搜索引用和附件名、离开群页后恢复收藏、设备间收藏独立、撤回取消收藏和会话变更后的历史搜索。私聊和服务端投递回归通过。
|
||||
@@ -190,20 +190,60 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
await chat(removed).getByRole('button', { name: '启用本机群聊' }).click()
|
||||
await chat(removed).getByText(edited, { exact: true }).waitFor()
|
||||
|
||||
const keyword = chat(owner).getByRole('searchbox', { name: '搜索本机群消息' })
|
||||
const favorites = chat(owner).getByRole('checkbox', { name: '只看收藏' })
|
||||
const searchedRequests = []
|
||||
const trackSearch = (request) => searchedRequests.push({ url: request.url(), method: request.method() })
|
||||
owner.on('request', trackSearch)
|
||||
await keyword.fill(first.toUpperCase())
|
||||
await chat(owner).getByRole('listitem').filter({ hasText: reply }).waitFor()
|
||||
assert.equal(await incomingEdit.count(), 0)
|
||||
await keyword.fill(edited)
|
||||
await incomingEdit.getByRole('button', { name: '收藏', exact: true }).click()
|
||||
await incomingEdit.getByRole('button', { name: '取消收藏', exact: true }).waitFor()
|
||||
await favorites.check()
|
||||
assert.equal(await chat(owner).getByRole('listitem').count(), 1)
|
||||
const unmatched = '没有匹配的验收关键词 ' + id()
|
||||
await keyword.fill(unmatched)
|
||||
await chat(owner).getByText('没有匹配的群消息。').waitFor()
|
||||
owner.off('request', trackSearch)
|
||||
assert.ok(searchedRequests.filter(({ url }) => url.includes('/groups/')).every(({ url, method }) =>
|
||||
method === 'GET' && !/search|favorite/i.test(new URL(url).pathname) && !decodeURIComponent(url).includes(unmatched)))
|
||||
await work(owner).getByRole('link', { name: '联系人' }).click()
|
||||
await work(owner).getByRole('link', { name: '群组' }).click()
|
||||
await owner.getByRole('link', { name: new RegExp(group) }).click()
|
||||
await chat(owner).getByRole('button', { name: '启用本机群聊' }).click()
|
||||
await favorites.check()
|
||||
await incomingEdit.getByRole('button', { name: '取消收藏', exact: true }).click()
|
||||
await chat(owner).getByText('没有匹配的群消息。').waitFor()
|
||||
await favorites.uncheck()
|
||||
assert.equal(await chat(windows).getByRole('listitem').filter({ hasText: edited })
|
||||
.getByRole('button', { name: '取消收藏', exact: true }).count(), 0)
|
||||
|
||||
const temporary = '待撤回群消息 ' + id()
|
||||
assert.equal(await send(windows, temporary), epoch)
|
||||
const outgoing = chat(windows).getByRole('listitem').filter({ hasText: temporary })
|
||||
await chat(owner).getByText(temporary, { exact: true }).waitFor()
|
||||
const incoming = chat(owner).getByRole('listitem').filter({ hasText: temporary })
|
||||
await incoming.getByRole('button', { name: '收藏', exact: true }).click()
|
||||
await incoming.getByRole('button', { name: '取消收藏', exact: true }).waitFor()
|
||||
await outgoing.getByRole('button', { name: '撤回', exact: true }).click()
|
||||
await chat(windows).getByRole('button', { name: '确认撤回' }).click()
|
||||
for (const page of pages) {
|
||||
await chat(page).getByText('消息已撤回', { exact: true }).waitFor()
|
||||
assert.equal(await chat(page).getByText(temporary, { exact: true }).count(), 0)
|
||||
}
|
||||
await favorites.check()
|
||||
await chat(owner).getByText('没有匹配的群消息。').waitFor()
|
||||
await favorites.uncheck()
|
||||
|
||||
const contents = Buffer.from('Windows 群文件内容 ' + id() + '\n'.repeat(9000))
|
||||
const filename = '群附件-' + id() + '.txt'
|
||||
await sendFile(windows, filename, 'text/plain', contents)
|
||||
await keyword.fill(filename.toUpperCase())
|
||||
await chat(owner).getByRole('button', { name: '下载 ' + filename }).waitFor()
|
||||
assert.equal(await chat(owner).getByRole('listitem').count(), 1)
|
||||
await keyword.clear()
|
||||
const fileDownload = owner.waitForEvent('download')
|
||||
const fileResponse = owner.waitForResponse((item) => item.url().includes('/attachments/') && item.request().method() === 'GET')
|
||||
await chat(owner).getByRole('button', { name: '下载 ' + filename }).click()
|
||||
@@ -276,6 +316,11 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
const history = chat(windows).getByRole('listitem').filter({ hasText: edited })
|
||||
assert.equal(await history.count(), 1)
|
||||
assert.equal(await history.getByRole('button', { name: '编辑', exact: true }).count(), 0)
|
||||
await chat(windows).getByRole('searchbox', { name: '搜索本机群消息' }).fill(edited)
|
||||
await history.getByRole('button', { name: '收藏', exact: true }).click()
|
||||
await chat(windows).getByRole('checkbox', { name: '只看收藏' }).check()
|
||||
await history.getByRole('button', { name: '取消收藏', exact: true }).waitFor()
|
||||
assert.equal(await chat(windows).getByRole('listitem').count(), 1)
|
||||
} catch (error) {
|
||||
const status = await Promise.all(pages.map((page) => page.locator('[role=alert], .group-chat [role=status]').allTextContents()))
|
||||
throw new Error(JSON.stringify(status), { cause: error })
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -14,7 +14,7 @@ type Outgoing = { id: string; epoch: string; wire: string }
|
||||
type Packet = Outgoing & { sequence: string; senderDevice: string; createdAt: string; attachmentId?: string }
|
||||
export type GroupLine = {
|
||||
id: string; user: string; sender: string; name: string; text: string; time: string; epoch?: string
|
||||
attachment?: Attachment; quote?: string; edited?: boolean; recalled?: boolean
|
||||
attachment?: Attachment; quote?: string; edited?: boolean; recalled?: boolean; favorite?: boolean
|
||||
}
|
||||
type LineRef = Pick<GroupLine, 'id' | 'sender' | 'epoch'>
|
||||
type GroupContent = string | File | { text: string; reply: LineRef } | (Mutation & { epoch: string })
|
||||
@@ -47,7 +47,27 @@ function finishPending(chat: GroupChatState, pending: NonNullable<GroupChatState
|
||||
|
||||
function applyGroupMutation(chat: GroupChatState, epoch: string, sender: string, mutation: Mutation) {
|
||||
const target = chat.lines.find((line) => line.id === mutation.id && line.epoch === epoch && line.sender === sender)
|
||||
if (target) applyMutation(target, mutation)
|
||||
if (!target) return
|
||||
applyMutation(target, mutation)
|
||||
if (target.recalled) delete target.favorite
|
||||
}
|
||||
|
||||
function trimHistory(chat: GroupChatState) {
|
||||
const cutoff = Math.max(0, chat.lines.length - 1000)
|
||||
chat.lines = [...chat.lines.slice(0, cutoff).filter((line) => line.favorite), ...chat.lines.slice(cutoff)]
|
||||
}
|
||||
|
||||
export function setGroupFavorite(identity: ChatIdentity, group: GroupDetail, message: LineRef, favorite: boolean) {
|
||||
return update(identity, async (state, save) => {
|
||||
const chat = state.groupChats?.[group.id]
|
||||
const line = chat?.lines.find((item) => item.id === message.id && item.epoch === message.epoch && item.sender === message.sender)
|
||||
if (!chat || !line || line.recalled) throw new Error('此群消息无法收藏')
|
||||
if (favorite) line.favorite = true
|
||||
else delete line.favorite
|
||||
trimHistory(chat)
|
||||
await save(state)
|
||||
return chat.lines
|
||||
})
|
||||
}
|
||||
|
||||
export function groupQuote(line: GroupLine) {
|
||||
@@ -241,7 +261,7 @@ export function synchronizeGroup(identity: ChatIdentity, group: GroupDetail, cal
|
||||
chat.cursor = item.sequence
|
||||
}
|
||||
if (chat.cursor !== previousCursor) {
|
||||
chat.lines = chat.lines.slice(-1000)
|
||||
trimHistory(chat)
|
||||
await save(state)
|
||||
}
|
||||
if (Date.now() - (state.packageChecked ?? 0) >= 60_000) {
|
||||
|
||||
Reference in new issue
Block a user