增加会话导航与可选加密已读回执

This commit is contained in:
xhgit committed 2026-11-13 23:35:26 +08:00
1 parent 6786158a3e
commit 149028267e
8 files changed
+218 -17

No files matched your search

+2 -1
View File
@@ -47,13 +47,14 @@ async function unsealKey(value: VaultRecord['key']) {
}
}
export async function withVault<T, R>(device: string, update: (state: T | undefined, save: (state: T) => Promise<void>) => Promise<R>) {
export async function withVault<T, R>(device: string, update: (state: T | undefined, save: (state: T) => Promise<void>) => Promise<R>, readOnly = false) {
const scope = (window.xhchat?.apiBase ?? location.origin) + '/' + device
const additionalData = new TextEncoder().encode(scope)
return navigator.locks.request('xhchat-chat:' + scope, async () => {
const db = await database()
try {
const stored = await record(db, scope)
if (!stored && readOnly) return await update(undefined, async () => { throw new Error('会话尚未启用') })
const wrapped = stored?.key ?? await newKey()
const key = await unsealKey(wrapped)
const state = stored?.iv && stored.sealed