Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where original event was inserted into timeline instead of the edit event #3398

Merged
merged 13 commits into from
May 25, 2023
Merged
19 changes: 6 additions & 13 deletions spec/unit/models/thread.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,21 +660,14 @@ describe("Thread", () => {
});
await thread.addEvent(messageToEdit, false);

// THIS IS THE CORRECT BEHAVIOUR
// Then both events end up in the timeline
//const lastEvent = thread.timeline.at(-1)!;
//const secondLastEvent = thread.timeline.at(-2)!;
//expect(lastEvent).toBe(editEvent);
//expect(secondLastEvent).toBe(messageToEdit);

//// And the first message has been edited
//expect(secondLastEvent.getContent().body).toEqual("edit");

// TODO: For now, we incorrecly DON'T add the event to the timeline
const lastEvent = thread.timeline.at(-1)!;
expect(lastEvent).toBe(messageToEdit);
// But the original is edited, as expected
expect(lastEvent.getContent().body).toEqual("edit");
const secondLastEvent = thread.timeline.at(-2)!;
expect(lastEvent).toBe(editEvent);
expect(secondLastEvent).toBe(messageToEdit);

// And the first message has been edited
expect(secondLastEvent.getContent().body).toEqual("edit");
});
});
});
Expand Down
5 changes: 3 additions & 2 deletions src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,9 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
})
.then((relations) => {
if (relations.events.length) {
event.makeReplaced(relations.events[0]);
this.insertEventIntoTimeline(event);
const editEvent = relations.events[0];
event.makeReplaced(editEvent);
this.insertEventIntoTimeline(editEvent);
}
})
.catch((e) => {
Expand Down