Refactor useIsRoomE2EE

Make it take a room object rather than a room ID to avoid it depending
on a side effect, ie. if the room object input changes, the hook will be
re-run but if we can't get the room from the room ID for whatever reason,
we'd be stuck.

Also add logging on why we decided a room was e2ee.
This commit is contained in:
David Baker
2023-09-22 15:35:03 +01:00
parent e9e37736b0
commit 3cd0ca205b
4 changed files with 23 additions and 14 deletions

View File

@@ -25,9 +25,10 @@ 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 | null;
roomId: string | undefined;
}
export const AppSelectionModal: FC<Props> = ({ roomId }) => {
@@ -43,8 +44,11 @@ export const AppSelectionModal: FC<Props> = ({ roomId }) => {
[setOpen]
);
const { client } = useClient();
const room = useMemo(() => client?.getRoom(roomId) ?? null, [roomId, client]);
const roomSharedKey = useRoomSharedKey(roomId ?? "");
const roomIsEncrypted = useIsRoomE2EE(roomId ?? "");
const roomIsEncrypted = useIsRoomE2EE(room ?? undefined);
if (roomIsEncrypted && roomSharedKey === undefined) {
logger.error(
"Generating app redirect URL for encrypted room but don't have key available!"
@@ -58,7 +62,7 @@ export const AppSelectionModal: FC<Props> = ({ 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 === null
!roomId
? window.location.href
: getAbsoluteRoomUrl(roomId, undefined, roomSharedKey ?? undefined)
);