From b202f997e33acd017511477ea98cc504b9589ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 2 Jun 2021 10:30:17 +0200 Subject: [PATCH] Refactor setState() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/structures/CallEventGrouper.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/structures/CallEventGrouper.ts b/src/components/structures/CallEventGrouper.ts index 8455eae0cd..ab1444d4fa 100644 --- a/src/components/structures/CallEventGrouper.ts +++ b/src/components/structures/CallEventGrouper.ts @@ -55,6 +55,10 @@ export default class CallEventGrouper extends EventEmitter { return [...this.events].find((event) => event.getType() === EventType.CallHangup); } + private get reject(): MatrixEvent { + return [...this.events].find((event) => event.getType() === EventType.CallReject); + } + public get isVoice(): boolean { const invite = this.invite; if (!invite) return; @@ -101,13 +105,10 @@ export default class CallEventGrouper extends EventEmitter { if (SUPPORTED_STATES.includes(this.call?.state)) { this.state = this.call.state; } else { - const lastEvent = [...this.events][this.events.size - 1]; - const lastEventType = lastEvent.getType(); - if (this.callWasMissed) this.state = CustomCallState.Missed; - else if (lastEventType === EventType.CallHangup) this.state = CallState.Ended; - else if (lastEventType === EventType.CallReject) this.state = CallState.Ended; - else if (lastEventType === EventType.CallInvite && this.call) this.state = CallState.Connecting; + else if (this.reject) this.state = CallState.Ended; + else if (this.hangup) this.state = CallState.Ended; + else if (this.invite && this.call) this.state = CallState.Connecting; } this.emit(CallEventGrouperEvent.StateChanged, this.state); }