feat: add message management and delivery states
This commit is contained in:
+18
-2
@@ -80,8 +80,11 @@ export function upsertDevice(d: DeviceRow) {
|
||||
upsertDeviceStmt.run(d)
|
||||
}
|
||||
|
||||
export function listDevices(): DeviceRow[] {
|
||||
return db.prepare(`SELECT * FROM devices ORDER BY last_seen DESC`).all() as DeviceRow[]
|
||||
export function listDevices(includeIgnored = false): DeviceRow[] {
|
||||
const sql = includeIgnored
|
||||
? `SELECT * FROM devices ORDER BY last_seen DESC`
|
||||
: `SELECT * FROM devices WHERE ignored = 0 ORDER BY last_seen DESC`
|
||||
return db.prepare(sql).all() as DeviceRow[]
|
||||
}
|
||||
|
||||
export function getDevice(id: string): DeviceRow | undefined {
|
||||
@@ -178,6 +181,19 @@ export function listPendingMessages(peerId: string, selfId: string): MessageRow[
|
||||
).all(key) as MessageRow[]
|
||||
}
|
||||
|
||||
// 已上传完但 WS update 帧 (带 savedPath) 没送达: metadata 帧 status='sent',
|
||||
// body.savedPath 已填, 重发完整 envelope 让收件方出 "打开/位置"
|
||||
export function listSentFileUpdates(selfId: string, peerId: string): MessageRow[] {
|
||||
return db.prepare(
|
||||
`SELECT * FROM messages
|
||||
WHERE from_id = ? AND to_id = ?
|
||||
AND status = 'sent'
|
||||
AND type IN ('file', 'image')
|
||||
AND json_extract(body_json, '$.savedPath') IS NOT NULL
|
||||
ORDER BY ts ASC`
|
||||
).all(selfId, peerId) as MessageRow[]
|
||||
}
|
||||
|
||||
export function listAllPending(selfId: string): MessageRow[] {
|
||||
return db.prepare(
|
||||
`SELECT * FROM messages WHERE status = 'pending' AND from_id = ? ORDER BY ts ASC`
|
||||
|
||||
Reference in New Issue
Block a user