diff --git a/README.md b/README.md index 9a74dea..4477b59 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 66076a1..4cf3400 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -19,7 +19,7 @@ Web 和 Electron 共用 Vue 客户端,独立接入同一 Go API。真实 Postg ## 尚待实现 - 阶段一还需邮箱和手机号注册、验证码服务、找回密码和双重验证。真实联调需要 SMTP 与短信供应商配置。 -- 阶段二与三还需分片附件、群聊转发、多设备可信授权、加密备份与跨设备历史同步。群聊和私聊的文字及小附件已进入开发预览。 +- 阶段二与三还需分片附件、私聊转发至群聊、多设备可信授权、加密备份与跨设备历史同步。群聊和私聊的文字及小附件已进入开发预览。 - 阶段四还需 WebRTC 音视频、TURN、SFU、屏幕共享及媒体 E2EE。 - 阶段五还需反钓鱼及聊天联动。 - 阶段六到八还需社交、扩展生态、独立管理后台、推送、生产部署与备份演练、压力测试、安全评估、签名安装包和发布流程。 @@ -132,3 +132,9 @@ Windows Electron 与 Edge 验证引用渲染、编辑补收、文字与图片撤 在群聊中可组合使用关键词和「只看收藏」,搜索本机已解密的消息文本、引用与附件名。收藏状态保存在设备的加密存储中,保留超过最近 1,000 条的收藏记录,撤回会取消收藏。附件仍受原会话权限和服务端保留期限制。跨设备收藏同步待实现。 Windows Electron 与 Edge 集成测试覆盖搜索引用和附件名、离开群页后恢复收藏、设备间收藏独立、撤回取消收藏和会话变更后的历史搜索。私聊和服务端投递回归通过。 + +## 群消息转发 + +双端可将群消息转发到其他已加入且已核验的群加密会话,或转发到已核验的联系人设备。转发携带文字正文或附件。图片、视频和语音保留原有媒体类型。附件经本机完整性校验和解密,再以新的附件标识、文件密钥与随机数加密上传。待投递的群转发可在目标群继续重试。原消息的引用片段和发送人信息不随转发发送。 + +Windows Electron 与 Edge 验证向尚无加密会话的群转发会被拒绝、转发群文件后附件标识和密文不同且下载内容逐字节相同,以及群文字转发到联系人私聊。私聊附件转发回归通过。 diff --git a/tests/group-chat.test.mjs b/tests/group-chat.test.mjs index 337de10..e20b160 100644 --- a/tests/group-chat.test.mjs +++ b/tests/group-chat.test.mjs @@ -321,6 +321,58 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员 await chat(windows).getByRole('checkbox', { name: '只看收藏' }).check() await history.getByRole('button', { name: '取消收藏', exact: true }).waitFor() assert.equal(await chat(windows).getByRole('listitem').count(), 1) + await chat(windows).getByRole('searchbox', { name: '搜索本机群消息' }).clear() + await chat(windows).getByRole('checkbox', { name: '只看收藏' }).uncheck() + + const targetGroup = '转发目标 ' + id() + await owner.getByLabel('群名称', { exact: true }).fill(targetGroup) + await owner.getByRole('button', { name: '创建群组' }).click() + await owner.getByRole('heading', { name: targetGroup }).waitFor() + await owner.getByLabel('邀请联系人').selectOption({ label: names[1] }) + await owner.getByRole('button', { name: '发送邀请' }).click() + await windows.getByRole('link', { name: new RegExp(targetGroup) }).click() + await windows.getByRole('button', { name: '接受邀请' }).click() + await owner.getByRole('list', { name: '群成员' }).getByRole('listitem').getByText(names[1] + ' · 成员', { exact: true }).waitFor() + await windows.getByRole('link', { name: new RegExp(group) }).click() + await chat(windows).getByRole('button', { name: '启用本机群聊' }).click() + const forwardPanel = chat(windows).getByRole('form', { name: '转发群消息' }) + const forwardFile = chat(windows).getByRole('listitem').filter({ hasText: filename }).getByRole('button', { name: '转发', exact: true }) + await forwardFile.click() + await forwardPanel.getByLabel('转发给').selectOption({ label: targetGroup }) + await forwardPanel.getByRole('button', { name: '确认转发' }).click() + await chat(windows).getByRole('alert').getByText('请先在目标群加入加密会话').waitFor() + await forwardPanel.getByRole('button', { name: '取消', exact: true }).click() + await windows.getByRole('link', { name: new RegExp(targetGroup) }).click() + await chat(windows).getByRole('button', { name: '启用本机群聊' }).click() + await chat(owner).getByRole('button', { name: '启用本机群聊' }).click() + await publish(owner, [owner, windows]) + await windows.getByRole('link', { name: new RegExp(group) }).click() + await chat(windows).getByRole('button', { name: '启用本机群聊' }).click() + + const forwarded = windows.waitForResponse((item) => /\/groups\/[^/]+\/attachments\/[^/]+\?epoch=/.test(item.url()) && + item.request().method() === 'POST') + await forwardFile.click() + await forwardPanel.getByLabel('转发给').selectOption({ label: targetGroup }) + await forwardPanel.getByRole('button', { name: '确认转发' }).click() + const newBlob = await forwarded + assert.equal(newBlob.status(), 204) + assert.notEqual(new URL(newBlob.url()).pathname.split('/').at(-1), new URL(response.url()).pathname.split('/').at(-1)) + await chat(windows).getByText('已转发到群聊', { exact: true }).waitFor() + const newResponse = owner.waitForResponse((item) => item.url().endsWith(new URL(newBlob.url()).pathname) && item.request().method() === 'GET') + const newDownload = owner.waitForEvent('download') + await chat(owner).getByRole('button', { name: '下载 ' + filename }).click() + assert.notDeepEqual(await (await newResponse).body(), ciphertext) + assert.deepEqual(await readFile(await (await newDownload).path()), contents) + + await chat(windows).getByRole('listitem').filter({ hasText: edited }).getByRole('button', { name: '转发', exact: true }).click() + await forwardPanel.getByLabel('转发给').selectOption({ label: names[0] }) + await forwardPanel.getByLabel('目标设备').waitFor() + await forwardPanel.getByRole('button', { name: '确认转发' }).click() + await chat(windows).getByText('已提交转发', { exact: true }).waitFor() + await work(owner).getByRole('link', { name: '消息', exact: true }).click() + await owner.getByRole('link', { name: names[1] }).click() + await owner.getByRole('button', { name: '启用本机加密聊天' }).click() + await owner.getByText(edited, { exact: true }).waitFor() } 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 1fc8da3..9f681ac 100644 --- a/web/src/chat/GroupChat.vue +++ b/web/src/chat/GroupChat.vue @@ -4,11 +4,12 @@ import { useSession } from '../session' import { downloadAttachment } from './attachments' import type { Attachment } from './attachments' import MediaPreview from './MediaPreview.vue' +import GroupForward from './GroupForward.vue' import VoiceMessage from './VoiceMessage.vue' import VoiceRecorder from './VoiceRecorder.vue' import { enableChat, trust } from './chat' -import { discardPendingGroupMessage, groupAttachmentPath, groupQuote, publishGroup, sendGroupMessage, setGroupFavorite, synchronizeGroup } from './group-chat' -import type { GroupDetail, GroupDevice, GroupLine } from './group-chat' +import { discardPendingGroupMessage, forwardGroupMessage, groupAttachmentPath, groupQuote, publishGroup, sendGroupMessage, setGroupFavorite, synchronizeGroup } from './group-chat' +import type { ForwardDestination, GroupDetail, GroupDevice, GroupLine } from './group-chat' const props = defineProps<{ group: GroupDetail }>() const session = useSession() @@ -22,6 +23,8 @@ const favoritesOnly = ref(false) const replying = ref() const editing = ref() const recalling = ref() +const forwarding = ref() +const forwardStatus = ref('') const file = ref() const pendingVoice = ref<{ file: File; epoch: string }>() const busy = ref(false) @@ -158,6 +161,20 @@ function favorite(line: GroupLine) { }) } +function beginForward(line: GroupLine) { + forwardStatus.value = '' + forwarding.value = line +} + +function forward(destination: ForwardDestination) { + const identity = session.identity + const source = forwarding.value + if (identity && source) void run(async () => { + forwardStatus.value = await forwardGroupMessage(identity, props.group, source, destination, session.authorized) + forwarding.value = undefined + }) +} + function discard() { const identity = session.identity if (identity) void run(async () => { @@ -197,6 +214,7 @@ onBeforeUnmount(() => clearInterval(timer))

群消息

+

{{ forwardStatus }}