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

Commit

Permalink
Handle group call redaction (#10465)
Browse files Browse the repository at this point in the history
Redacted group call events should be interpreted as terminated calls.
  • Loading branch information
robintown authored Mar 28, 2023
1 parent f166787 commit edef4cc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/views/messages/CallEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const CallEvent = forwardRef<any, CallEventProps>(({ mxEvent }, ref) => {
.getRoom(mxEvent.getRoomId())!
.currentState.getStateEvents(mxEvent.getType(), mxEvent.getStateKey()!)!;

if ("m.terminated" in latestEvent.getContent()) {
if ("m.terminated" in latestEvent.getContent() || latestEvent.isRedacted()) {
// The call is terminated
return (
<div className="mx_CallEvent_wrapper" ref={ref}>
Expand Down
5 changes: 4 additions & 1 deletion src/toasts/IncomingCallToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import React, { useCallback, useEffect } from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";

import { _t } from "../languageHandler";
import RoomAvatar from "../components/views/avatars/RoomAvatar";
Expand All @@ -36,6 +36,7 @@ import { ButtonEvent } from "../components/views/elements/AccessibleButton";
import { useDispatcher } from "../hooks/useDispatcher";
import { ActionPayload } from "../dispatcher/payloads";
import { Call } from "../models/Call";
import { useTypedEventEmitter } from "../hooks/useEventEmitter";

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

Expand Down Expand Up @@ -89,6 +90,8 @@ export function IncomingCallToast({ callEvent }: Props): JSX.Element {
}
}, [latestEvent, dismissToast]);

useTypedEventEmitter(latestEvent, MatrixEventEvent.BeforeRedaction, dismissToast);

useDispatcher(
defaultDispatcher,
useCallback(
Expand Down
8 changes: 8 additions & 0 deletions test/components/views/messages/CallEvent-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ describe("CallEvent", () => {
screen.getByText("1m 30s");
});

it("shows a message if the call was redacted", () => {
const event = room.currentState.getStateEvents(MockedCall.EVENT_TYPE, "1")!;
jest.spyOn(event, "isRedacted").mockReturnValue(true);
renderEvent();

screen.getByText("Video call ended");
});

it("shows placeholder info if the call isn't loaded yet", () => {
jest.spyOn(CallStore.instance, "getCall").mockReturnValue(null);
jest.advanceTimersByTime(90000);
Expand Down
12 changes: 12 additions & 0 deletions test/toasts/IncomingCallToast-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { ClientWidgetApi, Widget } from "matrix-widget-api";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";

import type { RoomMember } from "matrix-js-sdk/src/models/room-member";
import {
Expand Down Expand Up @@ -176,4 +177,15 @@ describe("IncomingCallEvent", () => {
expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)),
);
});

it("closes toast when the call event is redacted", async () => {
renderToast();

const event = room.currentState.getStateEvents(MockedCall.EVENT_TYPE, "1")!;
event.emit(MatrixEventEvent.BeforeRedaction, event, {} as unknown as MatrixEvent);

await waitFor(() =>
expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)),
);
});
});

0 comments on commit edef4cc

Please sign in to comment.