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

Commit 09f0d11

Browse files
authored
Fix external guest access url for unencrypted rooms (#12345)
* use unencrypted calls in unencrypted rooms (make external call links compatible with unencrypted embedded calls) Signed-off-by: Timo K <[email protected]> * use same logic in Call.ts Signed-off-by: Timo K <[email protected]> * fix tests Signed-off-by: Timo K <[email protected]> * fix test Signed-off-by: Timo K <[email protected]> --------- Signed-off-by: Timo K <[email protected]>
1 parent 75a989e commit 09f0d11

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

src/hooks/room/useRoomCall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export const useRoomCall = (
282282
url.pathname = "/room/";
283283
// Set params for the sharable url
284284
url.searchParams.set("roomId", room.roomId);
285-
url.searchParams.set("perParticipantE2EE", "true");
285+
if (room.hasEncryptionStateEvent()) url.searchParams.set("perParticipantE2EE", "true");
286286
for (const server of calculateRoomVia(room)) {
287287
url.searchParams.set("viaServers", server);
288288
}

src/models/Call.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,10 @@ export class ElementCall extends Call {
778778
overwriteData: IWidgetData,
779779
): IWidgetData {
780780
let perParticipantE2EE = false;
781-
if (client.isRoomEncrypted(roomId) && !SettingsStore.getValue("feature_disable_call_per_sender_encryption"))
781+
if (
782+
client.getRoom(roomId)?.hasEncryptionStateEvent() &&
783+
!SettingsStore.getValue("feature_disable_call_per_sender_encryption")
784+
)
782785
perParticipantE2EE = true;
783786
return {
784787
...currentData,

test/components/views/rooms/RoomHeader-test.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,10 @@ describe("RoomHeader", () => {
563563
const { container } = render(<RoomHeader room={room} />, getWrapper());
564564
expect(getByLabelText(container, _t("voip|get_call_link"))).toBeInTheDocument();
565565
});
566-
it("opens the share dialog with the correct share link", () => {
566+
it("opens the share dialog with the correct share link in an encrypted room", () => {
567567
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
568568
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
569+
jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(true);
569570

570571
const { container } = render(<RoomHeader room={room} />, getWrapper());
571572
const modalSpy = jest.spyOn(Modal, "createDialog");
@@ -583,6 +584,20 @@ describe("RoomHeader", () => {
583584
});
584585
expect(arg1.target.toString()).toEqual(target);
585586
});
587+
588+
it("share dialog has correct link in an unencrypted room", () => {
589+
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Public);
590+
jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(false);
591+
jest.spyOn(SdkContextClass.instance.roomViewStore, "isViewingCall").mockReturnValue(true);
592+
593+
const { container } = render(<RoomHeader room={room} />, getWrapper());
594+
const modalSpy = jest.spyOn(Modal, "createDialog");
595+
fireEvent.click(getByLabelText(container, _t("voip|get_call_link")));
596+
const target =
597+
"https://guest_spa_url.com/room/#/!1:example.org?roomId=%211%3Aexample.org&viaServers=example.org";
598+
const arg1 = modalSpy.mock.calls[0][1] as any;
599+
expect(arg1.target.toString()).toEqual(target);
600+
});
586601
});
587602

588603
describe("public room", () => {

test/models/Call-test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ describe("ElementCall", () => {
10391039
call.destroy();
10401040
const addWidgetSpy = jest.spyOn(WidgetStore.instance, "addVirtualWidget");
10411041
// If a room is not encrypted we will never add the perParticipantE2EE flag.
1042-
client.isRoomEncrypted.mockReturnValue(true);
1042+
const roomSpy = jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(true);
10431043

10441044
// should create call with perParticipantE2EE flag
10451045
ElementCall.create(room);
@@ -1049,8 +1049,7 @@ describe("ElementCall", () => {
10491049
enabledSettings.add("feature_disable_call_per_sender_encryption");
10501050
expect(Call.get(room)?.widget?.data?.perParticipantE2EE).toBe(false);
10511051
enabledSettings.delete("feature_disable_call_per_sender_encryption");
1052-
1053-
client.isRoomEncrypted.mockClear();
1052+
roomSpy.mockRestore();
10541053
addWidgetSpy.mockRestore();
10551054
});
10561055

test/test-utils/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ export function mkStubRoom(
624624
isElementVideoRoom: jest.fn().mockReturnValue(false),
625625
isSpaceRoom: jest.fn().mockReturnValue(false),
626626
isCallRoom: jest.fn().mockReturnValue(false),
627+
hasEncryptionStateEvent: jest.fn().mockReturnValue(false),
627628
loadMembersIfNeeded: jest.fn(),
628629
maySendMessage: jest.fn().mockReturnValue(true),
629630
myUserId: client?.getUserId(),

0 commit comments

Comments
 (0)