From 4ff96814083e712f6dede368975bd13921bab620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 7 Oct 2022 19:31:22 +0200 Subject: [PATCH] Close incoming Element call toast when viewing the call lobby (#9375) --- src/toasts/IncomingCallToast.tsx | 12 ++++++++++++ test/toasts/IncomingCallToast-test.tsx | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/toasts/IncomingCallToast.tsx b/src/toasts/IncomingCallToast.tsx index faff195226..5f7bb4d2a7 100644 --- a/src/toasts/IncomingCallToast.tsx +++ b/src/toasts/IncomingCallToast.tsx @@ -34,6 +34,8 @@ import { import { useCall } from "../hooks/useCall"; import { useRoomState } from "../hooks/useRoomState"; import { ButtonEvent } from "../components/views/elements/AccessibleButton"; +import { useDispatcher } from "../hooks/useDispatcher"; +import { ActionPayload } from "../dispatcher/payloads"; export const getIncomingCallToastKey = (stateKey: string) => `call_${stateKey}`; @@ -60,6 +62,16 @@ export function IncomingCallToast({ callEvent }: Props) { } }, [latestEvent, dismissToast]); + useDispatcher(defaultDispatcher, useCallback((payload: ActionPayload) => { + if ( + payload.action === Action.ViewRoom + && payload.room_id === roomId + && payload.view_call + ) { + dismissToast(); + } + }, [roomId, dismissToast])); + const onJoinClick = useCallback((e: ButtonEvent): void => { e.stopPropagation(); diff --git a/test/toasts/IncomingCallToast-test.tsx b/test/toasts/IncomingCallToast-test.tsx index 763cffeadd..ad19848faa 100644 --- a/test/toasts/IncomingCallToast-test.tsx +++ b/test/toasts/IncomingCallToast-test.tsx @@ -155,4 +155,18 @@ describe("IncomingCallEvent", () => { defaultDispatcher.unregister(dispatcherRef); }); + + it("closes toast when the call lobby is viewed", async () => { + renderToast(); + + defaultDispatcher.dispatch({ + action: Action.ViewRoom, + room_id: room.roomId, + view_call: true, + }); + + await waitFor(() => expect(toastStore.dismissToast).toHaveBeenCalledWith( + getIncomingCallToastKey(call.event.getStateKey()!), + )); + }); });