1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-06 12:02:40 +03:00

Handle group call redaction (#3231)

Redacted group call events should be interpreted as terminated calls.
This commit is contained in:
Robin
2023-03-28 09:07:44 -04:00
committed by GitHub
parent 6861c67f56
commit d48b19e052
3 changed files with 43 additions and 5 deletions

View File

@@ -582,6 +582,7 @@ export function makeMockGroupCallStateEvent(
"m.type": GroupCallType.Video, "m.type": GroupCallType.Video,
"m.intent": GroupCallIntent.Prompt, "m.intent": GroupCallIntent.Prompt,
}, },
redacted?: boolean,
): MatrixEvent { ): MatrixEvent {
return { return {
getType: jest.fn().mockReturnValue(EventType.GroupCallPrefix), getType: jest.fn().mockReturnValue(EventType.GroupCallPrefix),
@@ -589,6 +590,7 @@ export function makeMockGroupCallStateEvent(
getTs: jest.fn().mockReturnValue(0), getTs: jest.fn().mockReturnValue(0),
getContent: jest.fn().mockReturnValue(content), getContent: jest.fn().mockReturnValue(content),
getStateKey: jest.fn().mockReturnValue(groupCallId), getStateKey: jest.fn().mockReturnValue(groupCallId),
isRedacted: jest.fn().mockReturnValue(redacted ?? false),
} as unknown as MatrixEvent; } as unknown as MatrixEvent;
} }

View File

@@ -98,6 +98,23 @@ describe("Group Call Event Handler", function () {
expect(groupCall.state).toBe(GroupCallState.Ended); expect(groupCall.state).toBe(GroupCallState.Ended);
}); });
it("terminates call when redacted", async () => {
await groupCallEventHandler.start();
mockClient.emitRoomState(makeMockGroupCallStateEvent(FAKE_ROOM_ID, FAKE_GROUP_CALL_ID), {
roomId: FAKE_ROOM_ID,
} as unknown as RoomState);
const groupCall = groupCallEventHandler.groupCalls.get(FAKE_ROOM_ID)!;
expect(groupCall.state).toBe(GroupCallState.LocalCallFeedUninitialized);
mockClient.emitRoomState(makeMockGroupCallStateEvent(FAKE_ROOM_ID, FAKE_GROUP_CALL_ID, undefined, true), {
roomId: FAKE_ROOM_ID,
} as unknown as RoomState);
expect(groupCall.state).toBe(GroupCallState.Ended);
});
}); });
it("waits until client starts syncing", async () => { it("waits until client starts syncing", async () => {
@@ -222,9 +239,9 @@ describe("Group Call Event Handler", function () {
jest.clearAllMocks(); jest.clearAllMocks();
}); });
const setupCallAndStart = async (content?: IContent) => { const setupCallAndStart = async (content?: IContent, redacted?: boolean) => {
mocked(mockRoom.currentState.getStateEvents).mockReturnValue([ mocked(mockRoom.currentState.getStateEvents).mockReturnValue([
makeMockGroupCallStateEvent(FAKE_ROOM_ID, FAKE_GROUP_CALL_ID, content), makeMockGroupCallStateEvent(FAKE_ROOM_ID, FAKE_GROUP_CALL_ID, content, redacted),
] as unknown as MatrixEvent); ] as unknown as MatrixEvent);
mockClient.getRooms.mockReturnValue([mockRoom]); mockClient.getRooms.mockReturnValue([mockRoom]);
await groupCallEventHandler.start(); await groupCallEventHandler.start();
@@ -285,5 +302,24 @@ describe("Group Call Event Handler", function () {
}), }),
); );
}); });
it("ignores redacted calls", async () => {
await setupCallAndStart(
{
// Real event contents to make sure that it's specifically the
// event being redacted that causes it to be ignored
"m.type": GroupCallType.Video,
"m.intent": GroupCallIntent.Prompt,
},
true,
);
expect(mockClientEmit).not.toHaveBeenCalledWith(
GroupCallEventHandlerEvent.Incoming,
expect.objectContaining({
groupCallId: FAKE_GROUP_CALL_ID,
}),
);
});
}); });
}); });

View File

@@ -118,7 +118,7 @@ export class GroupCallEventHandler {
for (const callEvent of sortedCallEvents) { for (const callEvent of sortedCallEvents) {
const content = callEvent.getContent(); const content = callEvent.getContent();
if (content["m.terminated"]) { if (content["m.terminated"] || callEvent.isRedacted()) {
continue; continue;
} }
@@ -210,10 +210,10 @@ export class GroupCallEventHandler {
const currentGroupCall = this.groupCalls.get(state.roomId); const currentGroupCall = this.groupCalls.get(state.roomId);
if (!currentGroupCall && !content["m.terminated"]) { if (!currentGroupCall && !content["m.terminated"] && !event.isRedacted()) {
this.createGroupCallFromRoomStateEvent(event); this.createGroupCallFromRoomStateEvent(event);
} else if (currentGroupCall && currentGroupCall.groupCallId === groupCallId) { } else if (currentGroupCall && currentGroupCall.groupCallId === groupCallId) {
if (content["m.terminated"]) { if (content["m.terminated"] || event.isRedacted()) {
currentGroupCall.terminate(false); currentGroupCall.terminate(false);
} else if (content["m.type"] !== currentGroupCall.type) { } else if (content["m.type"] !== currentGroupCall.type) {
// TODO: Handle the callType changing when the room state changes // TODO: Handle the callType changing when the room state changes