Fix the state shown for call in rooms (#10833)

* Fix the state shown for call in rooms

We split out a separate state for 'missed' separate to 'ended' which
caused confusion as the state got set to this when it shouldn't have,
so calls that wouldn't have been shown as missed were.

Remove the csutom call state and just have the missed state as a
variant of the ended state. Re-order the if clauses so they hit the
right ones. Also don't pass the callState variable into renderContent()
which is a class method and so has access to the same info anyway.

* Fix test

* i18n (reorder only)

* Fix test

* Fix types

* Add test for legacy call event tile
This commit is contained in:
David Baker 2023-05-15 09:37:40 +01:00 committed by GitHub
parent 5988bb9a68
commit 1aa9860743
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 163 additions and 43 deletions

View file

@ -37,10 +37,6 @@ const CONNECTING_STATES = [
const SUPPORTED_STATES = [CallState.Connected, CallState.Ringing, CallState.Ended];
export enum CustomCallState {
Missed = "missed",
}
const isCallEventType = (eventType: string): boolean =>
eventType.startsWith("m.call.") || eventType.startsWith("org.matrix.call.");
@ -73,7 +69,7 @@ export function buildLegacyCallEventGroupers(
export default class LegacyCallEventGrouper extends EventEmitter {
private events: Set<MatrixEvent> = new Set<MatrixEvent>();
private call: MatrixCall | null = null;
public state?: CallState | CustomCallState;
public state?: CallState;
public constructor() {
super();
@ -130,8 +126,11 @@ export default class LegacyCallEventGrouper extends EventEmitter {
/**
* Returns true if there are only events from the other side - we missed the call
*/
private get callWasMissed(): boolean {
return ![...this.events].some((event) => event.sender?.userId === MatrixClientPeg.get().getUserId());
public get callWasMissed(): boolean {
return (
this.state === CallState.Ended &&
![...this.events].some((event) => event.sender?.userId === MatrixClientPeg.get().getUserId())
);
}
private get callId(): string | undefined {
@ -188,10 +187,13 @@ export default class LegacyCallEventGrouper extends EventEmitter {
} else if (this.call && SUPPORTED_STATES.includes(this.call.state)) {
this.state = this.call.state;
} else {
if (this.callWasMissed) this.state = CustomCallState.Missed;
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;
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(LegacyCallEventGrouperEvent.StateChanged, this.state);
};