From 48b038914fb7f78b5a92eec2e32f2c3a8714c5e0 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 22 Sep 2023 18:20:29 +0100 Subject: [PATCH] Revert "Refactor useIsRoomE2EE" --- src/e2ee/sharedKeyManagement.ts | 18 ++++++------------ src/room/AppSelectionModal.tsx | 10 +++------- src/room/GroupCallView.tsx | 7 ++++--- src/room/RoomPage.tsx | 2 +- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/e2ee/sharedKeyManagement.ts b/src/e2ee/sharedKeyManagement.ts index 4ce96c74c..b83212c1f 100644 --- a/src/e2ee/sharedKeyManagement.ts +++ b/src/e2ee/sharedKeyManagement.ts @@ -15,11 +15,10 @@ limitations under the License. */ import { useEffect, useMemo } from "react"; -import { Room } from "matrix-js-sdk/src/models/room"; -import { logger } from "matrix-js-sdk/src/logger"; import { useEnableE2EE } from "../settings/useSetting"; import { useLocalStorage } from "../useLocalStorage"; +import { useClient } from "../ClientContext"; import { PASSWORD_STRING, useUrlParams } from "../UrlParams"; import { widget } from "../widget"; @@ -84,19 +83,14 @@ export const useManageRoomSharedKey = (roomId: string): string | null => { return e2eeSharedKey ?? urlPassword; }; -export const useIsRoomE2EE = (room?: Room): boolean | null => { +export const useIsRoomE2EE = (roomId: string): boolean | null => { + const { client } = useClient(); + const room = useMemo(() => client?.getRoom(roomId) ?? null, [roomId, client]); // For now, rooms in widget mode are never considered encrypted. // In the future, when widget mode gains encryption support, then perhaps we // should inspect the e2eEnabled URL parameter here? - const canonAlias = useMemo( - () => (room ? room.getCanonicalAlias() : null), + return useMemo( + () => widget === null && (room === null || !room.getCanonicalAlias()), [room] ); - - const result = room ? !canonAlias && !widget : null; - logger.debug( - `Room ${room?.roomId} has canon alias ${canonAlias}. Is E2EE: ${result}` - ); - - return result; }; diff --git a/src/room/AppSelectionModal.tsx b/src/room/AppSelectionModal.tsx index 49b5e72fa..a6216ee15 100644 --- a/src/room/AppSelectionModal.tsx +++ b/src/room/AppSelectionModal.tsx @@ -25,10 +25,9 @@ import { useIsRoomE2EE, useRoomSharedKey } from "../e2ee/sharedKeyManagement"; import { getAbsoluteRoomUrl } from "../matrix-utils"; import styles from "./AppSelectionModal.module.css"; import { editFragmentQuery } from "../UrlParams"; -import { useClient } from "../ClientContext"; interface Props { - roomId: string | undefined; + roomId: string | null; } export const AppSelectionModal: FC = ({ roomId }) => { @@ -44,11 +43,8 @@ export const AppSelectionModal: FC = ({ roomId }) => { [setOpen] ); - const { client } = useClient(); - const room = useMemo(() => client?.getRoom(roomId) ?? null, [roomId, client]); - const roomSharedKey = useRoomSharedKey(roomId ?? ""); - const roomIsEncrypted = useIsRoomE2EE(room ?? undefined); + const roomIsEncrypted = useIsRoomE2EE(roomId ?? ""); if (roomIsEncrypted && roomSharedKey === undefined) { logger.error( "Generating app redirect URL for encrypted room but don't have key available!" @@ -62,7 +58,7 @@ export const AppSelectionModal: FC = ({ roomId }) => { // we got in our own URL and use that, but it's not a string that a human // ever sees so it's somewhat redundant. We just don't pass a name. const url = new URL( - !roomId + roomId === null ? window.location.href : getAbsoluteRoomUrl(roomId, undefined, roomSharedKey ?? undefined) ); diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index dfee43231..ab96926a4 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -76,7 +76,7 @@ export function GroupCallView({ const isJoined = useMatrixRTCSessionJoinState(rtcSession); const e2eeSharedKey = useManageRoomSharedKey(rtcSession.room.roomId); - const isRoomE2EE = useIsRoomE2EE(rtcSession.room); + const isRoomE2EE = useIsRoomE2EE(rtcSession.room.roomId); useEffect(() => { window.rtcSession = rtcSession; @@ -88,6 +88,7 @@ export function GroupCallView({ const { displayName, avatarUrl } = useProfile(client); const roomName = useRoomName(rtcSession.room); const roomAvatar = useRoomAvatar(rtcSession.room); + const roomEncrypted = useIsRoomE2EE(rtcSession.room.roomId)!; const matrixInfo = useMemo((): MatrixInfo => { return { @@ -98,7 +99,7 @@ export function GroupCallView({ roomName, roomAlias: rtcSession.room.getCanonicalAlias(), roomAvatar, - roomEncrypted: isRoomE2EE!, + roomEncrypted, }; }, [ displayName, @@ -106,7 +107,7 @@ export function GroupCallView({ rtcSession, roomName, roomAvatar, - isRoomE2EE, + roomEncrypted, client, ]); diff --git a/src/room/RoomPage.tsx b/src/room/RoomPage.tsx index 617005377..1a53dc49b 100644 --- a/src/room/RoomPage.tsx +++ b/src/room/RoomPage.tsx @@ -110,7 +110,7 @@ export const RoomPage: FC = () => { {content} {/* On Android and iOS, show a prompt to launch the mobile app. */} {appPrompt && (platform === "android" || platform === "ios") && ( - + )} );