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

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

+6 -3
View File
@@ -20,7 +20,7 @@ export interface ChatIdentity {
}
export interface Package { package: string; signature: string }
interface Outgoing { messageId: string; recipientDevice: string; ciphertext: string; mutationTarget?: string }
interface Outgoing { messageId: string; recipientDevice: string; ciphertext: string; mutationTarget?: string; silent?: boolean }
interface Incoming { messageId: string; senderDevice: string; ciphertext: string; sequence: string; createdAt: string }
export interface ChatLine {
@@ -159,7 +159,10 @@ async function flush(state: ChatState, save: (state: ChatState) => Promise<void>
for (const item of [...state.outbox]) {
if (unavailable.has(item.recipientDevice)) continue
try {
await call('/inbox', 'POST', { messageId: item.messageId, recipientDevice: item.recipientDevice, ciphertext: item.ciphertext })
await call('/inbox', 'POST', {
messageId: item.messageId, recipientDevice: item.recipientDevice, ciphertext: item.ciphertext,
...(item.silent || item.mutationTarget ? { silent: true } : {}),
})
state.outbox = state.outbox.filter((pending) => pending.messageId !== item.messageId)
await save(state)
} catch (error) {
@@ -308,7 +311,7 @@ export function markRead(identity: ChatIdentity, user: string, peer: Peer, visib
try {
const id = crypto.randomUUID()
const bytes = engine.encrypt(decode(group), aad(id, identity.device.id, peer.id), encodeRead(lines.map((line) => line.id)))
state.outbox.push({ messageId: id, recipientDevice: peer.id, ciphertext: base64(bytes) })
state.outbox.push({ messageId: id, recipientDevice: peer.id, ciphertext: base64(bytes), silent: true })
for (const line of lines) line.read = true
state.engine = base64(engine.snapshot())
await save(state)