Skip to content

Commit 2556a58

Browse files
committed
Handle group call redaction
Redacted group call events should be interpreted as terminated calls.
1 parent 254f043 commit 2556a58

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

spec/test-utils/webrtc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,13 +585,15 @@ export function makeMockGroupCallStateEvent(
585585
"m.type": GroupCallType.Video,
586586
"m.intent": GroupCallIntent.Prompt,
587587
},
588+
redacted?: boolean,
588589
): MatrixEvent {
589590
return {
590591
getType: jest.fn().mockReturnValue(EventType.GroupCallPrefix),
591592
getRoomId: jest.fn().mockReturnValue(roomId),
592593
getTs: jest.fn().mockReturnValue(0),
593594
getContent: jest.fn().mockReturnValue(content),
594595
getStateKey: jest.fn().mockReturnValue(groupCallId),
596+
isRedacted: jest.fn().mockReturnValue(redacted ?? false),
595597
} as unknown as MatrixEvent;
596598
}
597599

spec/unit/webrtc/groupCallEventHandler.spec.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ describe("Group Call Event Handler", function () {
9898

9999
expect(groupCall.state).toBe(GroupCallState.Ended);
100100
});
101+
102+
it('terminates call when redacted', async () => {
103+
await groupCallEventHandler.start()
104+
mockClient.emitRoomState(makeMockGroupCallStateEvent(FAKE_ROOM_ID, FAKE_GROUP_CALL_ID), {
105+
roomId: FAKE_ROOM_ID,
106+
} as unknown as RoomState);
107+
108+
const groupCall = groupCallEventHandler.groupCalls.get(FAKE_ROOM_ID)!;
109+
110+
expect(groupCall.state).toBe(GroupCallState.LocalCallFeedUninitialized);
111+
112+
mockClient.emitRoomState(
113+
makeMockGroupCallStateEvent(FAKE_ROOM_ID, FAKE_GROUP_CALL_ID, undefined, true),
114+
{
115+
roomId: FAKE_ROOM_ID,
116+
} as unknown as RoomState,
117+
);
118+
119+
expect(groupCall.state).toBe(GroupCallState.Ended);
120+
})
101121
});
102122

103123
it("waits until client starts syncing", async () => {
@@ -222,9 +242,9 @@ describe("Group Call Event Handler", function () {
222242
jest.clearAllMocks();
223243
});
224244

225-
const setupCallAndStart = async (content?: IContent) => {
245+
const setupCallAndStart = async (content?: IContent, redacted?: boolean) => {
226246
mocked(mockRoom.currentState.getStateEvents).mockReturnValue([
227-
makeMockGroupCallStateEvent(FAKE_ROOM_ID, FAKE_GROUP_CALL_ID, content),
247+
makeMockGroupCallStateEvent(FAKE_ROOM_ID, FAKE_GROUP_CALL_ID, content, redacted),
228248
] as unknown as MatrixEvent);
229249
mockClient.getRooms.mockReturnValue([mockRoom]);
230250
await groupCallEventHandler.start();
@@ -285,5 +305,21 @@ describe("Group Call Event Handler", function () {
285305
}),
286306
);
287307
});
308+
309+
it("ignores redacted calls", async () => {
310+
await setupCallAndStart({
311+
// Real event contents to make sure that it's specifically the
312+
// event being redacted that causes it to be ignored
313+
"m.type": GroupCallType.Video,
314+
"m.intent": GroupCallIntent.Prompt,
315+
}, true);
316+
317+
expect(mockClientEmit).not.toHaveBeenCalledWith(
318+
GroupCallEventHandlerEvent.Incoming,
319+
expect.objectContaining({
320+
groupCallId: FAKE_GROUP_CALL_ID,
321+
}),
322+
);
323+
})
288324
});
289325
});

src/webrtc/groupCallEventHandler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class GroupCallEventHandler {
118118
for (const callEvent of sortedCallEvents) {
119119
const content = callEvent.getContent();
120120

121-
if (content["m.terminated"]) {
121+
if (content["m.terminated"] || callEvent.isRedacted()) {
122122
continue;
123123
}
124124

@@ -210,10 +210,10 @@ export class GroupCallEventHandler {
210210

211211
const currentGroupCall = this.groupCalls.get(state.roomId);
212212

213-
if (!currentGroupCall && !content["m.terminated"]) {
213+
if (!currentGroupCall && !content["m.terminated"] && !event.isRedacted()) {
214214
this.createGroupCallFromRoomStateEvent(event);
215215
} else if (currentGroupCall && currentGroupCall.groupCallId === groupCallId) {
216-
if (content["m.terminated"]) {
216+
if (content["m.terminated"] || event.isRedacted()) {
217217
currentGroupCall.terminate(false);
218218
} else if (content["m.type"] !== currentGroupCall.type) {
219219
// TODO: Handle the callType changing when the room state changes

0 commit comments

Comments
 (0)