Skip to content

Commit

Permalink
Fix #23916
Browse files Browse the repository at this point in the history
Prevent confusion between synthesized lastEvent and the same event in the actual timeline
  • Loading branch information
justjanne committed Dec 7, 2022
1 parent a9e7a46 commit 2d77265
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/models/thread.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Copyright 2021-2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -216,7 +216,9 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
if (!event.isRelation(THREAD_RELATION_TYPE.name)) return;

await this.updateThreadMetadata();
this.emit(ThreadEvent.NewReply, this, event);
if (this.lastEvent?.getId() !== event.getId()) {
this.emit(ThreadEvent.NewReply, this, event);
}
};

public get roomState(): RoomState {
Expand Down Expand Up @@ -307,9 +309,8 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
this.replyCount = bundledRelationship.count;
this._currentUserParticipated = !!bundledRelationship.current_user_participated;

const mapper = this.client.getEventMapper();
// re-insert roomId
this.lastEvent = mapper({
this.lastEvent = new MatrixEvent({
...bundledRelationship.latest_event,
room_id: this.roomId,
});
Expand Down Expand Up @@ -394,11 +395,6 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
* Finds an event by ID in the current thread
*/
public findEventById(eventId: string): MatrixEvent | undefined {
// Check the lastEvent as it may have been created based on a bundled relationship and not in a timeline
if (this.lastEvent?.getId() === eventId) {
return this.lastEvent;
}

return this.timelineSet.findEventById(eventId);
}

Expand Down Expand Up @@ -429,7 +425,8 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
}

/**
* A getter for the last event added to the thread, if known.
* A getter for the last event of the thread.
* This might be a synthesized event, if so, it will not emit any events to listeners.
*/
public get replyToEvent(): Optional<MatrixEvent> {
return this.lastPendingEvent ?? this.lastEvent ?? this.lastReply();
Expand Down

0 comments on commit 2d77265

Please sign in to comment.