From 471712cbf06a067e5499bd5d2d7a75f693d9a12d Mon Sep 17 00:00:00 2001 From: Timo Date: Tue, 11 Feb 2025 14:22:26 +0100 Subject: [PATCH] fix destroy condition --- src/stores/RoomViewStore.tsx | 16 +++++++++++----- test/unit-tests/stores/RoomViewStore-test.ts | 1 - 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/stores/RoomViewStore.tsx b/src/stores/RoomViewStore.tsx index 28ee2e47df..ef499b161a 100644 --- a/src/stores/RoomViewStore.tsx +++ b/src/stores/RoomViewStore.tsx @@ -354,15 +354,21 @@ export class RoomViewStore extends EventEmitter { }); } - // Start a call if requested - const currentRoomCall = this.state.roomId ? CallStore.instance.getCall(this.state.roomId) : null; + // Start a call if requested and not already there + const currentRoomCall = payload.room_id ? CallStore.instance.getCall(payload.room_id) : null; if (payload.view_call && room && !currentRoomCall) { ElementCall.create(room, false); } - // Destroy the call when leaving call view + // Destroy all calls that are not connected when dispatching to a new room id. const prevRoomCall = this.state.roomId ? CallStore.instance.getCall(this.state.roomId) : null; - if (prevRoomCall && !prevRoomCall.connected) { - currentRoomCall?.destroy(); + if ( + // not looking at prevRoomCall anymore + (!payload.view_call || payload.room_id !== this.state.roomId) && + // not connected to the previous call anymore + prevRoomCall && + !prevRoomCall.connected + ) { + prevRoomCall?.destroy(); } if (SettingsStore.getValue("feature_sliding_sync") && this.state.roomId !== payload.room_id) { diff --git a/test/unit-tests/stores/RoomViewStore-test.ts b/test/unit-tests/stores/RoomViewStore-test.ts index 5116f8452d..2bb5cd6ee1 100644 --- a/test/unit-tests/stores/RoomViewStore-test.ts +++ b/test/unit-tests/stores/RoomViewStore-test.ts @@ -316,7 +316,6 @@ describe("RoomViewStore", function () { it("should display an error message when the room is unreachable via the roomId", async () => { // When // View and wait for the room - // jest.spyOn(WidgetStore).mockReturnValue({ getApps: () => [] } as unknown as void & WidgetStore); dis.dispatch({ action: Action.ViewRoom, room_id: roomId }); await untilDispatch(Action.ActiveRoomChanged, dis); // Generate error to display the expected error message