Fix optimistic user message reconciliation
This commit is contained in:
@@ -326,7 +326,7 @@ describe("processTimelineResponse", () => {
|
||||
...makeTimelineEntry(1, "Analyze this", "user_message"),
|
||||
item: {
|
||||
type: "user_message",
|
||||
text: "Analyze this",
|
||||
text: "server-rendered attachment text",
|
||||
messageId: "canonical-create-user",
|
||||
},
|
||||
},
|
||||
@@ -339,6 +339,7 @@ describe("processTimelineResponse", () => {
|
||||
expect(userMessages[0]).toMatchObject({
|
||||
id: "canonical-create-user",
|
||||
text: "Analyze this",
|
||||
timestamp: new Date(1000),
|
||||
images: [image],
|
||||
attachments: [attachment],
|
||||
});
|
||||
|
||||
@@ -295,16 +295,15 @@ function mergeCanonicalUserWithOptimistic(
|
||||
canonical: UserMessageItem,
|
||||
optimistic: UserMessageItem,
|
||||
): UserMessageItem {
|
||||
const shouldPreserveImages =
|
||||
(!canonical.images || canonical.images.length === 0) &&
|
||||
Boolean(optimistic.images && optimistic.images.length > 0);
|
||||
const shouldPreserveAttachments =
|
||||
(!canonical.attachments || canonical.attachments.length === 0) &&
|
||||
Boolean(optimistic.attachments && optimistic.attachments.length > 0);
|
||||
return {
|
||||
...canonical,
|
||||
...(shouldPreserveImages ? { images: optimistic.images } : {}),
|
||||
...(shouldPreserveAttachments ? { attachments: optimistic.attachments } : {}),
|
||||
kind: "user_message",
|
||||
id: canonical.id,
|
||||
text: optimistic.text,
|
||||
timestamp: optimistic.timestamp,
|
||||
...(optimistic.images && optimistic.images.length > 0 ? { images: optimistic.images } : {}),
|
||||
...(optimistic.attachments && optimistic.attachments.length > 0
|
||||
? { attachments: optimistic.attachments }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user