接入私聊消息通知和联系人免打扰

This commit is contained in:
xhgit committed 2026-11-15 22:27:58 +08:00
1 parent 5c882ac855
commit 7e165ba9b4
23 files changed
+286 -97

No files matched your search

+77
View File
@@ -123,6 +123,7 @@ test('Web 与 Windows 安全码校验、加密互发、离线接收和状态恢
await windows.getByLabel('发送已读回执').check()
await sentLine.getByText('已读', { exact: true }).waitFor({ timeout: 15_000 })
assert.ok(receiptPackets.length > 0)
assert.ok(receiptPackets.every((item) => item.silent === true))
assert.ok(receiptPackets.every((item) => !JSON.stringify(item).includes(packet.messageId)))
const reply = 'Windows 到 Web ' + randomBytes(8).toString('hex')
await windows.getByRole('listitem').filter({ hasText: text }).getByRole('button', { name: '引用', exact: true }).click()
@@ -235,6 +236,82 @@ test('Web 与 Windows 安全码校验、加密互发、离线接收和状态恢
} finally { db.close() }
})
assert.deepEqual(stored, [{ wrapped: true, encrypted: true, fields: ['iv', 'key', 'sealed'] }])
const systemToggle = (page) => page.getByRole('button', { name: '消息系统通知', exact: true })
const privateNotice = (page) => page.getByRole('link', { name: '有新的私聊消息', exact: true })
const muteToggle = (page) => page.getByRole('button', { name: '消息免打扰', exact: true })
await desktop.evaluate(({ Notification }) => {
const nativeShow = Notification.prototype.show
globalThis.privateNotificationLog = []
Notification.prototype.show = function () {
globalThis.privateNotificationLog.push({ title: this.title, body: this.body })
return nativeShow.call(this)
}
})
await systemToggle(windows).click()
await windows.getByText('已在本设备启用消息系统通知', { exact: true }).waitFor()
await work(windows).getByRole('link', { name: '设备管理' }).click()
const desktopNoticeText = 'Windows 后台私聊 ' + randomBytes(8).toString('hex')
await desktop.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows()[0].minimize())
try {
await send(web, desktopNoticeText)
const toast = await desktop.evaluate(async () => {
for (let attempt = 0; attempt < 30 && !globalThis.privateNotificationLog.length; attempt++) {
await new Promise((resolve) => setTimeout(resolve, 150))
}
return globalThis.privateNotificationLog[0]
})
assert.deepEqual(toast, { title: 'XHChat', body: '有新的私聊消息' })
} finally {
await desktop.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows()[0].restore())
}
await privateNotice(windows).click()
await windows.waitForURL(windowsChat)
await enable(windows)
await windows.getByText(desktopNoticeText, { exact: true }).waitFor()
assert.equal(await systemToggle(web).getAttribute('aria-pressed'), 'false')
await web.context().grantPermissions(['notifications'], { origin: base })
await web.evaluate(() => {
const BrowserNotification = window.Notification
window.privateNotificationLog = []
window.Notification = class extends BrowserNotification {
constructor(title, options) {
super(title, options)
window.privateNotificationLog.push({ title, body: options.body, tag: options.tag })
}
}
document.hasFocus = () => false
})
await systemToggle(web).click()
await web.getByText('已在本设备启用消息系统通知', { exact: true }).waitFor()
const webChat = web.url()
await work(web).getByRole('link', { name: '设备管理' }).click()
const webNoticeText = 'Edge 后台私聊 ' + randomBytes(8).toString('hex')
await send(windows, webNoticeText)
await privateNotice(web).waitFor()
await web.waitForFunction(() => window.privateNotificationLog.length === 1)
assert.deepEqual(await web.evaluate(() => window.privateNotificationLog[0]),
{ title: 'XHChat', body: '有新的私聊消息', tag: 'xhchat-private' })
await privateNotice(web).click()
await web.waitForURL(webChat)
await enable(web)
await web.getByText(webNoticeText, { exact: true }).waitFor()
await muteToggle(web).click()
await web.getByRole('button', { name: '消息免打扰', pressed: true }).waitFor()
assert.equal(await muteToggle(windows).getAttribute('aria-pressed'), 'false')
await work(web).getByRole('link', { name: '联系人' }).click()
await web.getByRole('button', { name: new RegExp(b) }).click()
await web.getByRole('button', { name: '消息免打扰', pressed: true }).waitFor()
const mutedText = '免打扰仍能同步 ' + randomBytes(8).toString('hex')
await send(windows, mutedText)
await web.getByRole('link', { name: '打开加密聊天' }).click()
await enable(web)
await web.getByText(mutedText, { exact: true }).waitFor()
assert.equal(await privateNotice(web).count(), 0)
assert.equal(await web.evaluate(() => window.privateNotificationLog.length), 1)
const link = base + '/healthz'
await send(web, link)
const webLink = web.getByRole('link', { name: link, exact: true })