支持私聊消息加密转发到群聊

This commit is contained in:
xhgit committed 2026-11-14 14:52:22 +08:00
1 parent 20e179a877
commit 9028ba0eed
8 files changed
+99 -62

No files matched your search

+51
View File
@@ -373,6 +373,57 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
await owner.getByRole('link', { name: names[1] }).click()
await owner.getByRole('button', { name: '启用本机加密聊天' }).click()
await owner.getByText(edited, { exact: true }).waitFor()
await owner.getByRole('listitem').filter({ hasText: edited }).getByRole('button', { name: '转发', exact: true }).click()
const privateForward = owner.getByRole('form', { name: '转发私聊消息' })
await privateForward.getByLabel('转发给').selectOption({ label: targetGroup })
await privateForward.getByRole('button', { name: '确认转发' }).click()
await owner.getByText('已转发到群聊', { exact: true }).waitFor()
await windows.getByRole('link', { name: new RegExp(targetGroup) }).click()
await chat(windows).getByRole('button', { name: '启用本机群聊' }).click()
await chat(windows).getByText(edited, { exact: true }).waitFor()
const pendingGroup = '待加密群 ' + id()
await windows.getByLabel('群名称', { exact: true }).fill(pendingGroup)
await windows.getByRole('button', { name: '创建群组' }).click()
await windows.getByRole('heading', { name: pendingGroup }).waitFor()
await work(windows).getByRole('link', { name: '消息', exact: true }).click()
await windows.getByRole('link', { name: names[0] }).click()
await windows.getByRole('button', { name: '启用本机加密聊天' }).click()
const privateFile = '私聊文件-' + id() + '.txt'
const originalUpload = windows.waitForResponse((item) => /\/api\/v1\/attachments\//.test(item.url()) && item.request().method() === 'POST')
await windows.getByLabel('发送附件').setInputFiles({ name: privateFile, mimeType: 'text/plain', buffer: contents })
const originalFile = await originalUpload
assert.equal(originalFile.status(), 204)
const originalBytes = originalFile.request().postDataBuffer()
assert.ok(originalBytes && originalBytes.length === contents.length + 16)
await windows.getByRole('listitem').filter({ hasText: privateFile }).getByRole('button', { name: '转发', exact: true }).click()
const desktopForward = windows.getByRole('form', { name: '转发私聊消息' })
const writes = []
const recordWrite = (req) => { if (req.method() === 'POST' && req.url().includes('/groups/')) writes.push(req.url()) }
windows.on('request', recordWrite)
await desktopForward.getByLabel('转发给').selectOption({ label: pendingGroup })
await desktopForward.getByRole('button', { name: '确认转发' }).click()
await windows.getByRole('alert').getByText('请先在目标群加入加密会话').waitFor()
windows.off('request', recordWrite)
assert.deepEqual(writes, [])
await desktopForward.getByLabel('转发给').selectOption({ label: targetGroup })
const groupUpload = windows.waitForResponse((item) => item.url().includes('/groups/') && item.url().includes('/attachments/') && item.request().method() === 'POST')
await desktopForward.getByRole('button', { name: '确认转发' }).click()
const targetFile = await groupUpload
assert.equal(targetFile.status(), 204)
assert.notEqual(new URL(targetFile.url()).pathname.split('/').at(-1), new URL(originalFile.url()).pathname.split('/').at(-1))
await windows.getByText('已转发到群聊', { exact: true }).waitFor()
await work(owner).getByRole('link', { name: '群组' }).click()
await owner.getByRole('link', { name: new RegExp(targetGroup) }).click()
await chat(owner).getByRole('button', { name: '启用本机群聊' }).click()
const groupDownload = owner.waitForEvent('download')
const groupFileResponse = owner.waitForResponse((item) => item.url().endsWith(new URL(targetFile.url()).pathname) && item.request().method() === 'GET')
await chat(owner).getByRole('button', { name: '下载 ' + privateFile, exact: true }).click()
assert.notDeepEqual(await (await groupFileResponse).body(), originalBytes)
assert.deepEqual(await readFile(await (await groupDownload).path()), contents)
} 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 })