feat(sync): seamless conversation sync, git-like version control, and offline remote notification
This commit is contained in:
1 parent
8e150dcacd
commit
0f866b1bbd
6 files changed
+471
-17
No files matched your search
@@ -157,4 +157,35 @@ export class Store {
|
||||
this.data.master = m
|
||||
this.save()
|
||||
}
|
||||
|
||||
// ---- session version control & offline notification queue ----------------
|
||||
sessionLineage() { return (this.data.sessionLineage ||= {}) }
|
||||
|
||||
recordLineage(sessionId, info) {
|
||||
const table = this.sessionLineage()
|
||||
table[sessionId] = { ...(table[sessionId] || {}), ...info, updatedAt: Date.now() }
|
||||
this.save()
|
||||
return table[sessionId]
|
||||
}
|
||||
|
||||
pendingMoves() { return (this.data.pendingMoves ||= {}) }
|
||||
|
||||
queueMoveNotice(notice) {
|
||||
const key = `${notice.fromDevice}:${notice.sessionId}`
|
||||
this.pendingMoves()[key] = { ...notice, queuedAt: Date.now() }
|
||||
this.save()
|
||||
}
|
||||
|
||||
popPendingMovesForDevice(deviceId) {
|
||||
const moves = this.pendingMoves()
|
||||
const matching = []
|
||||
for (const [k, v] of Object.entries(moves)) {
|
||||
if (v.fromDevice === deviceId) {
|
||||
matching.push(v)
|
||||
delete moves[k]
|
||||
}
|
||||
}
|
||||
if (matching.length > 0) this.save()
|
||||
return matching
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user