增加群聊置顶、免打扰和应用内提醒

This commit is contained in:
xhgit committed 2026-11-14 16:00:46 +08:00
1 parent ced6e9030d
commit f54077ce46
17 files changed
+228 -42

No files matched your search

+25 -1
View File
@@ -62,6 +62,7 @@ test('群组邀请、授权、成员移除、版本变更与实时提示', { tim
const other = await register()
const group = await json('/groups', 'POST', owner.token, { name: '发布验收群' }, 201)
const path = '/groups/' + group.id
const preferences = path + '/preferences'
const act = async (actor, action, target, expected = 204, name) => {
const reply = await call(path, 'POST', actor.token, { action, target, name })
assert.equal(reply.status, expected, await reply.text())
@@ -81,6 +82,8 @@ test('群组邀请、授权、成员移除、版本变更与实时提示', { tim
await expectHint([ownerSocket, memberSocket], () => act(owner, 'invite', member.user.id))
const invitation = await json(path, 'GET', member.token)
assert.equal(invitation.state, 'invited')
await json(preferences, 'POST', member.token, { muted: true }, 404)
await json(preferences, 'POST', other.token, { pinned: true }, 404)
assert.deepEqual(invitation.members, [])
assert.equal(invitation.membershipVersion, '1')
await expectHint([ownerSocket, memberSocket], () => act(member, 'decline'))
@@ -88,6 +91,21 @@ test('群组邀请、授权、成员移除、版本变更与实时提示', { tim
await expectHint([ownerSocket, memberSocket], () => act(owner, 'invite', member.user.id))
await expectHint([ownerSocket, memberSocket], () => act(member, 'accept'))
const active = await json(path, 'GET', member.token)
assert.equal(active.pinned, false)
assert.equal(active.muted, false)
const preferenceHint = once(memberSocket, 'message', { signal: AbortSignal.timeout(4000) })
assert.deepEqual(await json(preferences, 'POST', member.token, { pinned: true, muted: true }), { pinned: true, muted: true })
assert.deepEqual(JSON.parse((await preferenceHint)[0]), { type: 'group_list_changed' })
const [ownView, otherView] = await Promise.all([member, owner].map((actor) => json(path, 'GET', actor.token)))
assert.deepEqual([ownView.pinned, ownView.muted, otherView.pinned, otherView.muted], [true, true, false, false])
let nextGroup
await expectHint([memberSocket], async () => {
nextGroup = await json('/groups', 'POST', member.token, { name: '较新的群' }, 201)
})
assert.deepEqual((await json('/groups', 'GET', member.token)).map((item) => item.id), [group.id, nextGroup.id])
await expectHint([memberSocket], async () => {
assert.equal((await call('/groups/' + nextGroup.id, 'POST', member.token, { action: 'disband' })).status, 204)
})
assert.equal(active.membershipVersion, '2')
assert.deepEqual(active.members.map((item) => item.role).sort(), ['member', 'owner'])
await act(member, 'remove', owner.user.id, 409)
@@ -182,7 +200,9 @@ test('群密文和实时提示只投递到名单设备,移除或撤销阻断
await publish(member, { ...second, devices: [{ device: member.device.id }, { device: owner.device.id, wire: welcome }] }, 409)
const [ownerSocket, memberSocket, outsiderSocket] = await Promise.all([owner, member, outsider].map((actor) => watchRealtime(actor, t)))
const outsiderEvents = []
const memberEvents = []
outsiderSocket.on('message', (data) => outsiderEvents.push(JSON.parse(data)))
memberSocket.on('message', (data) => memberEvents.push(JSON.parse(data)))
const hint = { type: 'group_changed', groupId: group.id }
const epochHint = once(memberSocket, 'message', { signal: AbortSignal.timeout(4000) })
await publish(owner, second)
@@ -196,11 +216,13 @@ test('群密文和实时提示只投递到名单设备,移除或撤销阻断
const message = { id: randomUUID(), epoch: second.id, wire: frame() }
const messageHint = once(ownerSocket, 'message', { signal: AbortSignal.timeout(4000) })
const sequence = await json(path + '/messages', 'POST', member.token, message)
assert.deepEqual(JSON.parse((await messageHint)[0]), hint)
assert.deepEqual(JSON.parse((await messageHint)[0]), { ...hint, notify: true })
assert.deepEqual(await json(path + '/messages', 'POST', member.token, message), sequence)
const received = await json(path + '/messages', 'GET', member.token)
assert.deepEqual(received.map((item) => item.wire), [message.wire])
await json(path + '/preferences', 'POST', member.token, { muted: true })
const attachmentId = randomUUID()
const attachment = path + '/attachments/' + attachmentId
const bytes = randomBytes(16_384)
@@ -246,6 +268,8 @@ test('群密文和实时提示只投递到名单设备,移除或撤销阻断
assert.equal((await json(path + '/epochs', 'GET', owner.token)).every((epoch) => !epoch.current), true)
await change(owner, 'disband')
await json(attachment, 'GET', owner.token, undefined, 404)
assert.ok(memberEvents.some((event) => event.type === 'group_changed' && event.groupId === group.id))
assert.ok(memberEvents.every((event) => event.notify === undefined))
assert.deepEqual(outsiderEvents, [])
})
+31 -4
View File
@@ -155,6 +155,25 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
await owner.getByRole('heading', { name: group }).waitFor()
await invite(owner, windows, names[1], group)
await invite(owner, removed, names[2], group)
const settings = (page, name) => page.getByRole('button', { name, exact: true })
await settings(removed, '群聊免打扰').click()
await removed.getByRole('button', { name: '群聊免打扰', pressed: true }).waitFor()
assert.equal(await settings(owner, '群聊免打扰').getAttribute('aria-pressed'), 'false')
await settings(owner, '置顶群聊').click()
await owner.getByRole('button', { name: '置顶群聊', pressed: true }).waitFor()
const ownerCompanion = await browser.newPage()
await ownerCompanion.goto(base)
await ownerCompanion.getByLabel('用户名').fill(names[0])
await ownerCompanion.getByLabel('密码', { exact: true }).fill(password)
await ownerCompanion.locator('button.primary').click()
await ownerCompanion.getByText('实时连接已建立').waitFor()
await work(ownerCompanion).getByRole('link', { name: '群组' }).click()
await ownerCompanion.getByRole('link', { name: new RegExp(group + '.*已置顶') }).click()
await settings(ownerCompanion, '群聊免打扰').click()
await owner.getByRole('button', { name: '群聊免打扰', pressed: true }).waitFor({ timeout: 4500 })
await settings(ownerCompanion, '群聊免打扰').click()
await owner.getByRole('button', { name: '群聊免打扰', pressed: false }).waitFor({ timeout: 4500 })
await ownerCompanion.close()
const codes = await Promise.all(pages.map(async (page) => {
await chat(page).getByRole('button', { name: '启用本机群聊' }).click()
const code = page.locator('.group-security-code')
@@ -180,6 +199,7 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
holdConnection = false
await owner.getByText('实时连接已建立', { exact: true }).waitFor()
await Promise.all([owner, windows].map((page) => chat(page).getByText(first, { exact: true }).waitFor({ timeout: 3500 })))
assert.equal(await removed.getByRole('link', { name: '有新的群消息' }).count(), 0)
await work(removed).getByRole('link', { name: '群组' }).click()
await removed.getByRole('link', { name: new RegExp(group) }).click()
await chat(removed).getByRole('button', { name: '启用本机群聊' }).click()
@@ -193,15 +213,18 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
assert.equal(await send(owner, reply), epoch)
const receivedReply = chat(windows).getByRole('listitem').filter({ hasText: reply })
await receivedReply.locator('blockquote').getByText(first, { exact: true }).waitFor({ timeout: 3500 })
await settings(removed, '群聊免打扰').click()
await removed.getByRole('button', { name: '群聊免打扰', pressed: false }).waitFor()
await work(removed).getByRole('link', { name: '联系人' }).click()
const own = chat(windows).getByRole('listitem').filter({ has: windows.getByText(first, { exact: true }) }).first()
await own.getByRole('button', { name: '编辑', exact: true }).click()
const edited = '已修改群消息 ' + id()
assert.equal(await send(windows, edited, '保存编辑'), epoch)
const notice = removed.getByRole('link', { name: '有新的群消息' })
await notice.waitFor({ timeout: 4500 })
const incomingEdit = chat(owner).getByRole('listitem').filter({ has: owner.getByText(edited, { exact: true }) })
await incomingEdit.getByText('已编辑', { exact: true }).waitFor()
await work(removed).getByRole('link', { name: '群组' }).click()
await removed.getByRole('link', { name: new RegExp(group) }).click()
await notice.click()
await chat(removed).getByRole('button', { name: '启用本机群聊' }).click()
await chat(removed).getByText(edited, { exact: true }).waitFor()
@@ -343,6 +366,7 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
await owner.getByLabel('群名称', { exact: true }).fill(targetGroup)
await owner.getByRole('button', { name: '创建群组' }).click()
await owner.getByRole('heading', { name: targetGroup }).waitFor()
assert.match(await owner.getByRole('complementary', { name: '群组列表' }).getByRole('link').first().textContent(), /已置顶/)
await owner.getByLabel('邀请联系人').selectOption({ label: names[1] })
await owner.getByRole('button', { name: '发送邀请' }).click()
await windows.getByRole('link', { name: new RegExp(targetGroup) }).click()
@@ -407,8 +431,11 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
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
const attachmentInput = windows.locator('input[type=file]:enabled')
const [originalFile] = await Promise.all([
originalUpload,
attachmentInput.setInputFiles({ name: privateFile, mimeType: 'text/plain', buffer: contents }),
])
assert.equal(originalFile.status(), 204)
const originalBytes = originalFile.request().postDataBuffer()
assert.ok(originalBytes && originalBytes.length === contents.length + 16)