接入群消息实时提醒和重连补拉
This commit is contained in:
1 parent
5ace82b0d7
commit
b2e04e8174
10 files changed
+122
-33
No files matched your search
+19
-1
@@ -42,6 +42,15 @@ async function contact(actor, target, action) {
|
||||
assert.equal(reply.status, 204, await reply.text())
|
||||
}
|
||||
|
||||
async function watchRealtime(actor, t) {
|
||||
const { ticket } = await json('/realtime/ticket', 'POST', actor.token)
|
||||
const ws = new WebSocket(base.replace(/^http/, 'ws') + '/api/v1/realtime', ['xhchat.v1', 'ticket.' + ticket], { origin: base })
|
||||
t.after(() => ws.terminate())
|
||||
assert.deepEqual(JSON.parse((await once(ws, 'message', { signal: AbortSignal.timeout(4000) }))[0]),
|
||||
{ type: 'ready', deviceId: actor.device.id })
|
||||
return ws
|
||||
}
|
||||
|
||||
// Opaque fixture with the MLS header. Crypto interoperability is tested separately in crypto/.
|
||||
function frame() {
|
||||
return Buffer.concat([Buffer.from([0, 1, 0, 2]), randomBytes(96)]).toString('base64')
|
||||
@@ -89,7 +98,7 @@ test('群组邀请、授权、成员移除与版本变更', { timeout: 25_000 },
|
||||
await json(path, 'GET', owner.token, undefined, 404)
|
||||
})
|
||||
|
||||
test('群密文只投递到当前名单中的设备,离开或撤销后阻断旧世代', { timeout: 25_000 }, async () => {
|
||||
test('群密文和实时提示只投递到名单设备,移除或撤销阻断旧世代', { timeout: 25_000 }, async (t) => {
|
||||
const enroll = async () => {
|
||||
const keys = generateKeyPairSync('ed25519')
|
||||
const actor = await register(keys)
|
||||
@@ -145,7 +154,13 @@ test('群密文只投递到当前名单中的设备,离开或撤销后阻断
|
||||
] }
|
||||
await publish(owner, { ...second, devices: [second.devices[0], { device: outsider.device.id, wire: welcome }] }, 409)
|
||||
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 = []
|
||||
outsiderSocket.on('message', (data) => outsiderEvents.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)
|
||||
assert.deepEqual(JSON.parse((await epochHint)[0]), hint)
|
||||
await publish(owner, second)
|
||||
await publish(owner, { ...second, id: randomUUID() }, 409)
|
||||
const epochs = await json(path + '/epochs', 'GET', member.token)
|
||||
@@ -153,7 +168,9 @@ test('群密文只投递到当前名单中的设备,离开或撤销后阻断
|
||||
roster: [owner.device.id, member.device.id].sort() }])
|
||||
await json(path + '/messages', 'GET', outsider.token, undefined, 404)
|
||||
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(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])
|
||||
@@ -203,6 +220,7 @@ 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.deepEqual(outsiderEvents, [])
|
||||
})
|
||||
|
||||
test('设备密文投递、幂等、离线补拉、实时提示和撤销', { timeout: 25000 }, async () => {
|
||||
|
||||
Reference in new issue
Block a user