Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle group call redaction #3231

Merged
merged 1 commit into from
Mar 28, 2023
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
2 changes: 2 additions & 0 deletions spec/test-utils/webrtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,15 @@ export function makeMockGroupCallStateEvent(
"m.type": GroupCallType.Video,
"m.intent": GroupCallIntent.Prompt,
},
redacted?: boolean,
): MatrixEvent {
return {
getType: jest.fn().mockReturnValue(EventType.GroupCallPrefix),
getRoomId: jest.fn().mockReturnValue(roomId),
getTs: jest.fn().mockReturnValue(0),
getContent: jest.fn().mockReturnValue(content),
getStateKey: jest.fn().mockReturnValue(groupCallId),
isRedacted: jest.fn().mockReturnValue(redacted ?? false),
} as unknown as MatrixEvent;
}

Expand Down
40 changes: 38 additions & 2 deletions spec/unit/webrtc/groupCallEventHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ describe("Group Call Event Handler", function () {

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 () => {
Expand Down Expand Up @@ -222,9 +239,9 @@ describe("Group Call Event Handler", function () {
jest.clearAllMocks();
});

const setupCallAndStart = async (content?: IContent) => {
const setupCallAndStart = async (content?: IContent, redacted?: boolean) => {
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);
mockClient.getRooms.mockReturnValue([mockRoom]);
await groupCallEventHandler.start();
Expand Down Expand Up @@ -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,
}),
);
});
});
});
6 changes: 3 additions & 3 deletions src/webrtc/groupCallEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class GroupCallEventHandler {
for (const callEvent of sortedCallEvents) {
const content = callEvent.getContent();

if (content["m.terminated"]) {
if (content["m.terminated"] || callEvent.isRedacted()) {
continue;
}

Expand Down Expand Up @@ -210,10 +210,10 @@ export class GroupCallEventHandler {

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

if (!currentGroupCall && !content["m.terminated"]) {
if (!currentGroupCall && !content["m.terminated"] && !event.isRedacted()) {
this.createGroupCallFromRoomStateEvent(event);
} else if (currentGroupCall && currentGroupCall.groupCallId === groupCallId) {
if (content["m.terminated"]) {
if (content["m.terminated"] || event.isRedacted()) {
currentGroupCall.terminate(false);
} else if (content["m.type"] !== currentGroupCall.type) {
// TODO: Handle the callType changing when the room state changes
Expand Down