Skip to content

Commit

Permalink
Null-guard for undefined rootEvent when creating a thread (#2187)
Browse files Browse the repository at this point in the history
  • Loading branch information
Germain authored Feb 21, 2022
1 parent 7a7318b commit 4e72290
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1398,12 +1398,17 @@ export class Room extends EventEmitter {
this.emit(ThreadEvent.Update, thread);
}

public createThread(rootEvent: MatrixEvent, events: MatrixEvent[] = []): Thread | undefined {
const tl = this.getTimelineForEvent(rootEvent.getId());
const relatedEvents = tl?.getTimelineSet().getAllRelationsEventForEvent(rootEvent.getId()) ?? [];
public createThread(rootEvent: MatrixEvent | undefined, events: MatrixEvent[] = []): Thread | undefined {
if (rootEvent) {
const tl = this.getTimelineForEvent(rootEvent.getId());
const relatedEvents = tl?.getTimelineSet().getAllRelationsEventForEvent(rootEvent.getId());
if (relatedEvents) {
events = events.concat(relatedEvents);
}
}

const thread = new Thread(rootEvent, {
initialEvents: events.concat(relatedEvents),
initialEvents: events,
room: this,
client: this.client,
});
Expand Down

0 comments on commit 4e72290

Please sign in to comment.