Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
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
20 changes: 15 additions & 5 deletions src/components/structures/CallEventGrouper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ export default class CallEventGrouper extends EventEmitter {
return ![...this.events].some((event) => event.sender?.userId === MatrixClientPeg.get().getUserId());
}

private get callId(): string {
return [...this.events][0].getContent().call_id;
private get callId(): string | undefined {
return [...this.events][0]?.getContent()?.call_id;
}

private get roomId(): string | undefined {
return [...this.events][0]?.getRoomId();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we always 100% certain we have at least one element in this.events? Seems from my short code analysis that this case should never happen, but could we add an additional check for it, just to be sure? Same would go for callId. Otherwise LGTM.

Copy link
Copy Markdown
Contributor Author

@SimonBrandner SimonBrandner Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should always have at least one event, but I've added some ? and made the return type into string | undefined, hopefully, it's better this way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also probably have some null-checks though those should be in the CallHandler. I am going to do some more refactoring in that area, so this is one of the things I will look into

}

private onSilencedCallsChanged = () => {
Expand All @@ -114,18 +118,24 @@ export default class CallEventGrouper extends EventEmitter {
};

public answerCall = () => {
this.call?.answer();
defaultDispatcher.dispatch({
action: 'answer',
room_id: this.roomId,
});
};

public rejectCall = () => {
this.call?.reject();
defaultDispatcher.dispatch({
action: 'reject',
room_id: this.roomId,
});
};

public callBack = () => {
defaultDispatcher.dispatch({
action: 'place_call',
type: this.isVoice ? CallType.Voice : CallType.Video,
room_id: [...this.events][0]?.getRoomId(),
room_id: this.roomId,
});
};

Expand Down