From 52c0e52ffdd07d820993f814ac4b0e8ca158bc32 Mon Sep 17 00:00:00 2001 From: xhgit Date: Sun, 15 Nov 2026 17:11:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BE=A4=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E3=80=81=E5=9B=BE=E7=89=87=E5=92=8C=E8=A7=86=E9=A2=91=E8=A7=86?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/progress.md | 6 ++++ tests/group-chat.test.mjs | 64 +++++++++++++++++++++++++++++++++++--- web/src/chat/GroupChat.vue | 43 ++++++++++++++++++++----- 4 files changed, 102 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 13f6ca3..cd6af3e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ | 联系人 | 按用户名查找、处理好友申请、管理备注与分组,以及拉黑。变更可在双端实时同步。 | | 加密文字聊天 | 在两个已核验设备之间发送 MLS 加密消息,支持离线接收。 | | 加密群聊 | 创建群组、邀请联系人和管理成员。群列表显示本机未读,并按账号同步置顶和免打扰。每个账号选一台已核验设备参与 MLS 加密文字聊天。 | -| 加密附件 | 两端可在私聊和群聊发送、下载最多 8 MiB 的文件,并在本机预览图片和视频。 | +| 加密附件 | 两端可在私聊和群聊发送、下载最多 8 MiB 的文件,并在本机预览图片和视频。群聊提供文件、图片和视频的分类视图。 | | 加密语音 | 两端可在私聊和群聊录制、取消或发送最长 60 秒的语音消息,接收方在本机解密播放。 | | 消息管理 | 私聊和群聊支持引用回复、编辑文字、撤回、本机搜索和收藏。消息可转发到已建立加密会话的群或已核验的联系人设备。私聊支持可选加密已读回执。 | | Chromium 浏览器 | Windows 端支持独立窗口、多标签、导航、搜索、书签、历史、下载和隐私窗口,网页运行在独立会话中。 | diff --git a/docs/progress.md b/docs/progress.md index a246150..10c6f30 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -115,6 +115,12 @@ Windows 和 Web 已接入群设备核验、MLS Welcome 校验、文字加解密 Windows 和 Web 可发送和下载最多 8 MiB 的群附件,并在本机预览常见图片和视频。接口验收覆盖大小限制、上传幂等、未发布附件隔离、发送设备绑定、移除和重新入群后的历史下载隔离。双端验收覆盖 Windows 发送文件到 Edge、逐字节核对下载、拒绝篡改的密文,以及 Edge 发送 PNG 到 Windows 预览。群附件分片和断点续传仍待实现。 +## 群文件、图片和视频视图 + +两端可在群聊切换到群文件、群图片或群视频,按文件名搜索,或只显示本机收藏。分类从本机已同步并解密的群消息中读取,优先显示较新的附件,每次展示 24 条,可继续加载本机记录。打开预览或下载时才向服务端请求附件密文。撤回附件会将它移出分类视图。 + +Windows Electron 和 Edge 验证进入文件视图与搜索时未请求附件密文、下载字节一致、篡改拒绝、PNG 预览、WebM 解码播放、切换视图关闭预览以及图片撤回后从分类移除。 + ## 加密群语音 双端在群聊录制最长 60 秒的 Opus 语音。取消录音即释放麦克风,不产生上传。语音按群附件加密,群世代变更会取消当前录音或拒绝发送上一个世代的录音。接收设备下载并验证密文后,通过本机播放器播放、暂停或拖动进度。语音转写及未听提醒待实现。 diff --git a/tests/group-chat.test.mjs b/tests/group-chat.test.mjs index c11c420..bc7786b 100644 --- a/tests/group-chat.test.mjs +++ b/tests/group-chat.test.mjs @@ -10,6 +10,7 @@ import { _electron, chromium } from 'playwright' const base = process.env.XHCHAT_TEST_URL ?? 'http://127.0.0.1:8080' const work = (page) => page.getByRole('navigation', { name: '工作区' }) const chat = (page) => page.getByRole('region', { name: '群消息' }) +const historyView = (page, name) => chat(page).getByRole('group', { name: '群历史视图' }).getByRole('button', { name, exact: true }) const id = () => randomBytes(6).toString('hex') async function register(page, username, password) { @@ -286,9 +287,19 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员 await chat(owner).getByRole('button', { name: '下载 ' + filename }).waitFor() assert.equal(await chat(owner).getByRole('listitem').count(), 1) await keyword.clear() + const attachmentRequests = [] + const trackAttachment = (request) => { if (request.url().includes('/attachments/')) attachmentRequests.push(request.url()) } + owner.on('request', trackAttachment) + await historyView(owner, '群文件').click() + const fileShelf = chat(owner).getByRole('list', { name: '群文件' }) + await keyword.fill(filename.toUpperCase()) + const fileButton = fileShelf.getByRole('button', { name: '下载 ' + filename }) + await fileButton.waitFor() + assert.deepEqual(attachmentRequests, []) + owner.off('request', trackAttachment) 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() + await fileButton.click() const response = await fileResponse assert.equal(response.status(), 200) const ciphertext = await response.body() @@ -303,23 +314,66 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员 tampered[0] ^= 1 await route.fulfill({ status: 200, contentType: 'application/octet-stream', body: tampered }) }, { times: 1 }) - await chat(owner).getByRole('button', { name: '下载 ' + filename }).click() + await fileButton.click() await chat(owner).getByRole('alert').getByText('附件完整性校验失败').waitFor() + await keyword.clear() + await historyView(owner, '消息').click() const photo = '群图片-' + id() + '.png' const pixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aX2sAAAAASUVORK5CYII=', 'base64') await sendFile(owner, photo, 'image/png', pixel) - await chat(windows).getByRole('button', { name: '预览 ' + photo }).click() + await historyView(windows, '群图片').click() + const gallery = chat(windows).getByRole('list', { name: '群图片' }) + assert.equal(await gallery.getByText(filename, { exact: false }).count(), 0) + await gallery.getByRole('button', { name: '预览 ' + photo }).click() const image = chat(windows).getByRole('img', { name: photo }) await image.evaluate((element) => element.decode()) assert.equal(await image.evaluate((element) => element.naturalWidth), 1) - await chat(windows).getByRole('button', { name: '关闭预览' }).click() + await historyView(windows, '群视频').click() await image.waitFor({ state: 'detached' }) + await chat(windows).getByText('没有匹配的群视频。', { exact: true }).waitFor() + await historyView(windows, '群图片').click() + await gallery.getByRole('button', { name: '预览 ' + photo }).waitFor() const photoLine = chat(owner).getByRole('listitem').filter({ hasText: photo }) assert.equal(await photoLine.getByRole('button', { name: '编辑', exact: true }).count(), 0) await photoLine.getByRole('button', { name: '撤回', exact: true }).click() await chat(owner).getByRole('button', { name: '确认撤回' }).click() - await chat(windows).getByRole('button', { name: '预览 ' + photo }).waitFor({ state: 'detached' }) + await chat(windows).getByText('没有匹配的群图片。', { exact: true }).waitFor() + + const clip = '群视频-' + id() + '.webm' + const videoBytes = await owner.evaluate(async () => { + const canvas = document.createElement('canvas') + canvas.width = 32 + canvas.height = 24 + const paint = canvas.getContext('2d') + const stream = canvas.captureStream(15) + const recorder = new MediaRecorder(stream, { mimeType: 'video/webm;codecs=vp8' }) + const recorded = new Promise((resolve, reject) => { + const chunks = [] + recorder.ondataavailable = ({ data }) => chunks.push(data) + recorder.onstop = async () => resolve(Array.from(new Uint8Array(await new Blob(chunks).arrayBuffer()))) + recorder.onerror = () => reject(new Error('无法生成验收视频')) + }) + recorder.start() + for (const color of ['#108760', '#2052a4', '#f5a12f']) { + paint.fillStyle = color + paint.fillRect(0, 0, 32, 24) + await new Promise((resolve) => setTimeout(resolve, 150)) + } + recorder.stop() + stream.getTracks().forEach((track) => track.stop()) + return recorded + }) + await sendFile(owner, clip, 'video/webm', Buffer.from(videoBytes)) + await historyView(windows, '群视频').click() + const videos = chat(windows).getByRole('list', { name: '群视频' }) + await videos.getByRole('button', { name: '预览 ' + clip }).click() + const player = videos.locator('video') + await player.evaluate((element) => element.play()) + assert.equal(await player.evaluate((element) => element.videoWidth), 32) + assert.match(await player.getAttribute('src'), /^blob:/) + await historyView(windows, '消息').click() + await player.waitFor({ state: 'detached' }) const voiceUploads = [] windows.on('request', (request) => { diff --git a/web/src/chat/GroupChat.vue b/web/src/chat/GroupChat.vue index 2210708..332a3bf 100644 --- a/web/src/chat/GroupChat.vue +++ b/web/src/chat/GroupChat.vue @@ -22,6 +22,15 @@ const selected = ref>({}) const draft = ref('') const search = ref('') const favoritesOnly = ref(false) +const historyViews = [ + { id: 'messages', label: '消息', empty: '没有匹配的群消息。' }, + { id: 'files', label: '群文件', empty: '没有匹配的群文件。' }, + { id: 'images', label: '群图片', empty: '没有匹配的群图片。' }, + { id: 'videos', label: '群视频', empty: '没有匹配的群视频。' }, +] as const +const historyView = ref(historyViews[0]) +const mediaPageSize = 24 +const mediaLimit = ref(mediaPageSize) const replying = ref() const editing = ref() const recalling = ref() @@ -35,10 +44,19 @@ const ready = computed(() => view.value?.ready && view.value.current?.membership 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 mode = historyView.value.id + const matches = (view.value?.lines ?? []).filter((line) => { + if (favoritesOnly.value && !line.favorite) return false + if (mode === 'messages') { + return !query || [line.text, line.quote, line.attachment?.name].some((part) => part?.toLowerCase().includes(query)) + } + const attachment = line.attachment + if (line.recalled || !attachment || attachment.voice || !attachment.name.toLowerCase().includes(query)) return false + return mode === 'files' || attachment.media?.startsWith(mode === 'images' ? 'image/' : 'video/') + }) + return mode === 'messages' ? matches : matches.reverse() }) +const visibleLines = computed(() => historyView.value.id === 'messages' ? lines.value : lines.value.slice(0, mediaLimit.value)) 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))))) @@ -216,6 +234,7 @@ function discard() { } watch(() => props.group.membershipVersion, queueRefresh) +watch([historyView, search, favoritesOnly], () => { mediaLimit.value = mediaPageSize }) watch(() => session.groupChange, (event) => { if (event?.groupId === props.group.id) queueRefresh() }) watch(() => session.connection, (connection) => { if (connection === '实时连接已建立') queueRefresh() }) watch(currentEpoch, (epoch, previous) => { @@ -289,13 +308,18 @@ onBeforeUnmount(() => { - +
@@ -366,6 +391,10 @@ onBeforeUnmount(() => { .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-history-views { display: flex; flex-wrap: wrap; gap: .4rem; } +.group-history-views [aria-pressed='true'] { background: var(--green-soft); color: var(--green); } +.group-media { grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); align-items: start; } +.group-media li { min-width: 0; padding: .7rem; border: 1px solid var(--line); border-radius: .45rem; } .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; }