feat(guild): LWW reaction toggle on mesh gossip (v0.8.605)

REACTION_TOGGLE ingest respects createdAt and tombstone flags for CRDT merge.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-06-01 18:45:27 -04:00
co-authored by Cursor
parent 232012b8a3
commit 527df63c67
+23 -10
View File
@@ -297,18 +297,31 @@ class PearcordGuild extends EventEmitter {
const key = {
channelId: payload.channelId,
messageId: payload.messageId,
emoji: payload.emoji,
emoji: String(payload.emoji || '').slice(0, 16),
userId: payload.userId
}
if (payload.removed) {
this.db.delete(COLLECTIONS.REACTIONS, key).then(() => {
this.emit('reaction', payload)
}).catch(() => {})
} else {
this.db.insert(COLLECTIONS.REACTIONS, payload).then(() => {
this.emit('reaction', payload)
}).catch(() => {})
}
const inTs = Number(payload.createdAt) || Number(payload.at) || 0
const removed = payload.removed === true || payload.tombstone === true
this.db
.get(COLLECTIONS.REACTIONS, key)
.then(async (existing) => {
const exTs = Number(existing?.createdAt) || 0
if (existing && inTs > 0 && exTs > 0 && inTs < exTs) return
if (removed) {
await this.db.delete(COLLECTIONS.REACTIONS, key).catch(() => {})
this.emit('reaction', { ...key, ...payload, removed: true, tombstone: true })
return
}
if (existing && inTs > 0 && exTs > 0 && inTs <= exTs && !removed) return
await this.db.insert(COLLECTIONS.REACTIONS, {
...existing,
...key,
guildId: payload.guildId,
createdAt: Math.max(inTs, exTs, Date.now())
})
this.emit('reaction', { ...key, ...payload, removed: false })
})
.catch(() => {})
}
if (method === RPC.CHANNEL_CREATE) {
this.ingestChannel(payload).then((ch) => {