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

Close incoming Element call toast when viewing the call lobby #9375

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/toasts/IncomingCallToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;

Expand All @@ -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();

Expand Down
14 changes: 14 additions & 0 deletions test/toasts/IncomingCallToast-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()!),
));
});
});