[Chat] Fix duplicate messages when history fetch races firehose (#10839)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -917,17 +917,27 @@ export class Convo {
|
|||||||
ChatBskyConvoDefs.isLogCreateMessage(ev) &&
|
ChatBskyConvoDefs.isLogCreateMessage(ev) &&
|
||||||
ChatBskyConvoDefs.isMessageView(ev.message)
|
ChatBskyConvoDefs.isMessageView(ev.message)
|
||||||
) {
|
) {
|
||||||
/**
|
/*
|
||||||
* If this message is already in new messages, it was added by our
|
* If this message is already in past messages, the initial
|
||||||
* sending logic, and is based on client-ordering. When we receive
|
* history fetch raced this log event and already returned it.
|
||||||
* the "committed" event from the log, we should replace this
|
* Update in place rather than inserting a duplicate into new
|
||||||
* reference and re-insert in order to respect the order we received
|
* messages.
|
||||||
* from the log.
|
|
||||||
*/
|
*/
|
||||||
if (this.newMessages.has(ev.message.id)) {
|
if (this.pastMessages.has(ev.message.id)) {
|
||||||
this.newMessages.delete(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
|
needsCommit = true
|
||||||
} else if (
|
} else if (
|
||||||
ChatBskyConvoDefs.isLogDeleteMessage(ev) &&
|
ChatBskyConvoDefs.isLogDeleteMessage(ev) &&
|
||||||
@@ -964,7 +974,12 @@ export class Convo {
|
|||||||
} else {
|
} else {
|
||||||
const systemView = toSystemMessageView(ev)
|
const systemView = toSystemMessageView(ev)
|
||||||
if (systemView) {
|
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
|
needsCommit = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user