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.
This commit is contained in:
Valere
2026-09-02 11:00:42 +02:00
parent 6e44332fd1
commit d8d70812b8
+23 -6
View File
@@ -12,7 +12,7 @@ import {
setLocalStorageItemReactive, setLocalStorageItemReactive,
useLocalStorage, useLocalStorage,
} from "../useLocalStorage"; } from "../useLocalStorage";
import { getUrlParams } from "../UrlParams"; import { getUrlParams, useUrlParams } from "../UrlParams";
import { E2eeType } from "./e2eeType"; import { E2eeType } from "./e2eeType";
import { useClient } from "../ClientContext"; import { useClient } from "../ClientContext";
@@ -57,19 +57,31 @@ const useRoomSharedKey = (
return [setInitialValue ?? roomSharedKey, setRoomSharedKey]; return [setInitialValue ?? roomSharedKey, setRoomSharedKey];
}; };
export function getKeyForRoom(roomId: string): string | null { /**
const { roomId: urlRoomId, password } = getUrlParams(); * The shared key for a room, preferring one supplied in the parameters Element
if (roomId !== urlRoomId) * 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( logger.warn(
"requested key for a roomId which is not the current call room id (from the URL)", "requested key for a roomId which is not the current call room id (from the URL)",
roomId, roomId,
urlRoomId, paramsRoomId,
); );
return ( return (
password ?? localStorage.getItem(getRoomSharedKeyLocalStorageKey(roomId)) 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 Unencrypted = { kind: E2eeType.NONE };
export type SharedSecret = { kind: E2eeType.SHARED_KEY; secret: string }; export type SharedSecret = { kind: E2eeType.SHARED_KEY; secret: string };
export type PerParticipantE2EE = { kind: E2eeType.PER_PARTICIPANT }; export type PerParticipantE2EE = { kind: E2eeType.PER_PARTICIPANT };
@@ -77,10 +89,15 @@ export type EncryptionSystem = Unencrypted | SharedSecret | PerParticipantE2EE;
export function useRoomEncryptionSystem(roomId: string): EncryptionSystem { export function useRoomEncryptionSystem(roomId: string): EncryptionSystem {
const { client } = useClient(); const { client } = useClient();
const { roomId: paramsRoomId, password } = useUrlParams();
const [storedPassword] = useRoomSharedKey( 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), getRoomSharedKeyLocalStorageKey(roomId),
getKeyForRoom(roomId) ?? undefined, keyForRoom(roomId, paramsRoomId, password) ?? undefined,
); );
const room = client?.getRoom(roomId); const room = client?.getRoom(roomId);