Handle group call redaction (#10465)

Redacted group call events should be interpreted as terminated calls.
This commit is contained in:
Robin 2023-03-28 09:16:30 -04:00 committed by GitHub
parent f1667870a0
commit edef4cc52e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 2 deletions

View file

@ -168,7 +168,7 @@ export const CallEvent = forwardRef<any, CallEventProps>(({ mxEvent }, ref) => {
.getRoom(mxEvent.getRoomId())! .getRoom(mxEvent.getRoomId())!
.currentState.getStateEvents(mxEvent.getType(), mxEvent.getStateKey()!)!; .currentState.getStateEvents(mxEvent.getType(), mxEvent.getStateKey()!)!;
if ("m.terminated" in latestEvent.getContent()) { if ("m.terminated" in latestEvent.getContent() || latestEvent.isRedacted()) {
// The call is terminated // The call is terminated
return ( return (
<div className="mx_CallEvent_wrapper" ref={ref}> <div className="mx_CallEvent_wrapper" ref={ref}>

View file

@ -15,7 +15,7 @@ limitations under the License.
*/ */
import React, { useCallback, useEffect } from "react"; 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 { _t } from "../languageHandler";
import RoomAvatar from "../components/views/avatars/RoomAvatar"; import RoomAvatar from "../components/views/avatars/RoomAvatar";
@ -36,6 +36,7 @@ import { ButtonEvent } from "../components/views/elements/AccessibleButton";
import { useDispatcher } from "../hooks/useDispatcher"; import { useDispatcher } from "../hooks/useDispatcher";
import { ActionPayload } from "../dispatcher/payloads"; import { ActionPayload } from "../dispatcher/payloads";
import { Call } from "../models/Call"; import { Call } from "../models/Call";
import { useTypedEventEmitter } from "../hooks/useEventEmitter";
export const getIncomingCallToastKey = (stateKey: string): string => `call_${stateKey}`; export const getIncomingCallToastKey = (stateKey: string): string => `call_${stateKey}`;
@ -89,6 +90,8 @@ export function IncomingCallToast({ callEvent }: Props): JSX.Element {
} }
}, [latestEvent, dismissToast]); }, [latestEvent, dismissToast]);
useTypedEventEmitter(latestEvent, MatrixEventEvent.BeforeRedaction, dismissToast);
useDispatcher( useDispatcher(
defaultDispatcher, defaultDispatcher,
useCallback( useCallback(

View file

@ -114,6 +114,14 @@ describe("CallEvent", () => {
screen.getByText("1m 30s"); 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", () => { it("shows placeholder info if the call isn't loaded yet", () => {
jest.spyOn(CallStore.instance, "getCall").mockReturnValue(null); jest.spyOn(CallStore.instance, "getCall").mockReturnValue(null);
jest.advanceTimersByTime(90000); jest.advanceTimersByTime(90000);

View file

@ -21,6 +21,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixClient } from "matrix-js-sdk/src/client"; import { MatrixClient } from "matrix-js-sdk/src/client";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state"; import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { ClientWidgetApi, Widget } from "matrix-widget-api"; 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 type { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { import {
@ -176,4 +177,15 @@ describe("IncomingCallEvent", () => {
expect(toastStore.dismissToast).toHaveBeenCalledWith(getIncomingCallToastKey(call.event.getStateKey()!)), 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()!)),
);
});
}); });