From d8d70812b847fa54c3b1adc9e3d787d5a3270443 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 2 Sep 2026 11:00:42 +0200 Subject: [PATCH] Read the shared room key from the parameters context useRoomEncryptionSystem is used from GroupCallView, inside the part of Element Call that will become the embeddable component, but it reached for getUrlParams() via getKeyForRoom(). Extract the lookup into a helper taking the room ID and password explicitly: the hook supplies them from the parameters context, while getKeyForRoom keeps reading the URL for its one remaining caller in the app shell. No functional change. --- src/e2ee/sharedKeyManagement.ts | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/e2ee/sharedKeyManagement.ts b/src/e2ee/sharedKeyManagement.ts index 18d007e2b..b29ede319 100644 --- a/src/e2ee/sharedKeyManagement.ts +++ b/src/e2ee/sharedKeyManagement.ts @@ -12,7 +12,7 @@ import { setLocalStorageItemReactive, useLocalStorage, } from "../useLocalStorage"; -import { getUrlParams } from "../UrlParams"; +import { getUrlParams, useUrlParams } from "../UrlParams"; import { E2eeType } from "./e2eeType"; import { useClient } from "../ClientContext"; @@ -57,19 +57,31 @@ const useRoomSharedKey = ( return [setInitialValue ?? roomSharedKey, setRoomSharedKey]; }; -export function getKeyForRoom(roomId: string): string | null { - const { roomId: urlRoomId, password } = getUrlParams(); - if (roomId !== urlRoomId) +/** + * The shared key for a room, preferring one supplied in the parameters Element + * Call was started with over whatever is in local storage. + */ +function keyForRoom( + roomId: string, + paramsRoomId: string | null, + password: string | null, +): string | null { + if (roomId !== paramsRoomId) logger.warn( "requested key for a roomId which is not the current call room id (from the URL)", roomId, - urlRoomId, + paramsRoomId, ); return ( password ?? localStorage.getItem(getRoomSharedKeyLocalStorageKey(roomId)) ); } +export function getKeyForRoom(roomId: string): string | null { + const { roomId: paramsRoomId, password } = getUrlParams(); + return keyForRoom(roomId, paramsRoomId, password); +} + export type Unencrypted = { kind: E2eeType.NONE }; export type SharedSecret = { kind: E2eeType.SHARED_KEY; secret: string }; export type PerParticipantE2EE = { kind: E2eeType.PER_PARTICIPANT }; @@ -77,10 +89,15 @@ export type EncryptionSystem = Unencrypted | SharedSecret | PerParticipantE2EE; export function useRoomEncryptionSystem(roomId: string): EncryptionSystem { const { client } = useClient(); + const { roomId: paramsRoomId, password } = useUrlParams(); const [storedPassword] = useRoomSharedKey( + // TODO: this passes an already-prefixed key where a room ID is expected, so + // the local storage key ends up prefixed twice and never matches what + // saveKeyForRoom writes. Preserved as-is here to keep this commit a pure + // refactor; the reactive read is effectively dead until it is fixed. getRoomSharedKeyLocalStorageKey(roomId), - getKeyForRoom(roomId) ?? undefined, + keyForRoom(roomId, paramsRoomId, password) ?? undefined, ); const room = client?.getRoom(roomId);