fix duplicate messages when history fetch races firehose
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -881,6 +881,15 @@ export class Convo {
|
|||||||
ChatBskyConvoDefs.isLogCreateMessage(ev) &&
|
ChatBskyConvoDefs.isLogCreateMessage(ev) &&
|
||||||
ChatBskyConvoDefs.isMessageView(ev.message)
|
ChatBskyConvoDefs.isMessageView(ev.message)
|
||||||
) {
|
) {
|
||||||
|
/*
|
||||||
|
* 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.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
|
* If this message is already in new messages, it was added by our
|
||||||
* sending logic, and is based on client-ordering. When we receive
|
* sending logic, and is based on client-ordering. When we receive
|
||||||
@@ -892,6 +901,7 @@ export class Convo {
|
|||||||
this.newMessages.delete(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) &&
|
||||||
@@ -928,7 +938,12 @@ export class Convo {
|
|||||||
} else {
|
} else {
|
||||||
const systemView = toSystemMessageView(ev)
|
const systemView = toSystemMessageView(ev)
|
||||||
if (systemView) {
|
if (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)
|
this.newMessages.set(systemView.id, systemView)
|
||||||
|
}
|
||||||
needsCommit = true
|
needsCommit = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user