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

Null-guard for undefined rootEvent when creating a thread #2187

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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