增加会话导航与可选加密已读回执
This commit is contained in:
1 parent
6786158a3e
commit
149028267e
8 files changed
+218
-17
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user