From f1e780e6428b0c9f633e7039d50549da1acf3f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 1 Jun 2021 13:40:25 +0200 Subject: [PATCH] Improved missed calls 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, 9 insertions(+), 4 deletions(-) diff --git a/src/components/structures/CallEventGrouper.ts b/src/components/structures/CallEventGrouper.ts index 5a3e5720e3..c53efadd7a 100644 --- a/src/components/structures/CallEventGrouper.ts +++ b/src/components/structures/CallEventGrouper.ts @@ -82,6 +82,13 @@ export default class CallEventGrouper extends EventEmitter { return this.state; } + /** + * Returns true if there are only events from the other side - we missed the call + */ + private wasThisCallMissed(): boolean { + return !this.events.some((event) => event.sender?.userId === MatrixClientPeg.get().getUserId()); + } + private setCallListeners() { if (!this.call) return; this.call.addListener(CallEvent.State, this.setCallState); @@ -94,12 +101,10 @@ export default class CallEventGrouper extends EventEmitter { const lastEvent = this.events[this.events.length - 1]; const lastEventType = lastEvent.getType(); - if (lastEventType === EventType.CallHangup) this.state = CallState.Ended; + if (this.wasThisCallMissed()) 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.invite?.sender?.userId !== MatrixClientPeg.get().getUserId()) { - this.state = CustomCallState.Missed; - } } this.emit(CallEventGrouperEvent.StateChanged, this.state); }