[Chat] Fix duplicate messages when history fetch races firehose (#10839)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-06-10 19:44:44 +03:00
committed by GitHub
parent 9e9a4024c3
commit e5335fa52b
+25 -10
View File
@@ -917,17 +917,27 @@ export class Convo {
ChatBskyConvoDefs.isLogCreateMessage(ev) &&
ChatBskyConvoDefs.isMessageView(ev.message)
) {
/**
* If this message is already in new messages, it was added by our
* sending logic, and is based on client-ordering. When we receive
* the "committed" event from the log, we should replace this
* reference and re-insert in order to respect the order we received
* from the log.
/*
* If this message is already in past messages, the initial
* history fetch raced this log event and already returned it.
* Update in place rather than inserting a duplicate into new
* messages.
*/
if (this.newMessages.has(ev.message.id)) {
this.newMessages.delete(ev.message.id)
if (this.pastMessages.has(ev.message.id)) {
this.pastMessages.set(ev.message.id, ev.message)
} else {
/**
* If this message is already in new messages, it was added by our
* sending logic, and is based on client-ordering. When we receive
* the "committed" event from the log, we should replace this
* reference and re-insert in order to respect the order we received
* from the log.
*/
if (this.newMessages.has(ev.message.id)) {
this.newMessages.delete(ev.message.id)
}
this.newMessages.set(ev.message.id, ev.message)
}
this.newMessages.set(ev.message.id, ev.message)
needsCommit = true
} else if (
ChatBskyConvoDefs.isLogDeleteMessage(ev) &&
@@ -964,7 +974,12 @@ export class Convo {
} else {
const systemView = toSystemMessageView(ev)
if (systemView) {
this.newMessages.set(systemView.id, systemView)
// same as above: avoid duplicating if history fetch won the race
if (this.pastMessages.has(systemView.id)) {
this.pastMessages.set(systemView.id, systemView)
} else {
this.newMessages.set(systemView.id, systemView)
}
needsCommit = true
}
}