diff --git a/README.md b/README.md index 83638fc..9a74dea 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ | 加密群聊 | 创建群组、邀请联系人和管理成员。每个账号选一台已核验设备参与 MLS 加密文字聊天。 | | 加密附件 | 两端可在私聊和群聊发送、下载最多 8 MiB 的文件,并在本机预览图片和视频。 | | 加密语音 | 两端可在私聊和群聊录制、取消或发送最长 60 秒的语音消息,接收方在本机解密播放。 | -| 消息管理 | 私聊和群聊支持引用回复、编辑文字和撤回。私聊还支持可选加密已读回执、转发、本机搜索和收藏。 | +| 消息管理 | 私聊和群聊支持引用回复、编辑文字、撤回、本机搜索和收藏。私聊还支持可选加密已读回执和转发。 | | Chromium 浏览器 | Windows 端支持独立窗口、多标签、导航、搜索、书签、历史、下载和隐私窗口,网页运行在独立会话中。 | 当前为开发预览。大文件分片、音视频和多设备历史同步仍在开发,Windows 安装包尚未发布。 [开发进度与验收记录](docs/progress.md) diff --git a/docs/progress.md b/docs/progress.md index d5a37be..66076a1 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -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 集成测试覆盖搜索引用和附件名、离开群页后恢复收藏、设备间收藏独立、撤回取消收藏和会话变更后的历史搜索。私聊和服务端投递回归通过。 diff --git a/tests/group-chat.test.mjs b/tests/group-chat.test.mjs index 7cdd1be..337de10 100644 --- a/tests/group-chat.test.mjs +++ b/tests/group-chat.test.mjs @@ -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 }) diff --git a/web/src/chat/GroupChat.vue b/web/src/chat/GroupChat.vue index c07305e..1fc8da3 100644 --- a/web/src/chat/GroupChat.vue +++ b/web/src/chat/GroupChat.vue @@ -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>({}) const selected = ref>({}) const draft = ref('') +const search = ref('') +const favoritesOnly = ref(false) const replying = ref() const editing = ref() const recalling = ref() @@ -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)) -
    -
  • + +

    没有匹配的群消息。

    +
      +
    • {{ line.name }} · {{ new Date(line.time).toLocaleString() }}
      {{ line.quote }}

      消息已撤回

      @@ -225,11 +246,14 @@ onBeforeUnmount(() => clearInterval(timer))

      {{ line.text }}

      已编辑 -
      - -