Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 4ff9681

Browse files
Close incoming Element call toast when viewing the call lobby (#9375)
1 parent 6b1ee13 commit 4ff9681

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/toasts/IncomingCallToast.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
import { useCall } from "../hooks/useCall";
3535
import { useRoomState } from "../hooks/useRoomState";
3636
import { ButtonEvent } from "../components/views/elements/AccessibleButton";
37+
import { useDispatcher } from "../hooks/useDispatcher";
38+
import { ActionPayload } from "../dispatcher/payloads";
3739

3840
export const getIncomingCallToastKey = (stateKey: string) => `call_${stateKey}`;
3941

@@ -60,6 +62,16 @@ export function IncomingCallToast({ callEvent }: Props) {
6062
}
6163
}, [latestEvent, dismissToast]);
6264

65+
useDispatcher(defaultDispatcher, useCallback((payload: ActionPayload) => {
66+
if (
67+
payload.action === Action.ViewRoom
68+
&& payload.room_id === roomId
69+
&& payload.view_call
70+
) {
71+
dismissToast();
72+
}
73+
}, [roomId, dismissToast]));
74+
6375
const onJoinClick = useCallback((e: ButtonEvent): void => {
6476
e.stopPropagation();
6577

test/toasts/IncomingCallToast-test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,18 @@ describe("IncomingCallEvent", () => {
155155

156156
defaultDispatcher.unregister(dispatcherRef);
157157
});
158+
159+
it("closes toast when the call lobby is viewed", async () => {
160+
renderToast();
161+
162+
defaultDispatcher.dispatch({
163+
action: Action.ViewRoom,
164+
room_id: room.roomId,
165+
view_call: true,
166+
});
167+
168+
await waitFor(() => expect(toastStore.dismissToast).toHaveBeenCalledWith(
169+
getIncomingCallToastKey(call.event.getStateKey()!),
170+
));
171+
});
158172
});

0 commit comments

Comments
 (0)