Skip to content

Commit

Permalink
Merge pull request #1571 from vector-im/revert-1570-dbkr/isroome2ee_r…
Browse files Browse the repository at this point in the history
…efactor

Revert "Refactor useIsRoomE2EE"
  • Loading branch information
dbkr authored Sep 22, 2023
2 parents ef32b87 + 48b0389 commit 6bc8ccf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
18 changes: 6 additions & 12 deletions src/e2ee/sharedKeyManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
};
10 changes: 3 additions & 7 deletions src/room/AppSelectionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Props> = ({ roomId }) => {
Expand All @@ -44,11 +43,8 @@ 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(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!"
Expand All @@ -62,7 +58,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
roomId === null
? window.location.href
: getAbsoluteRoomUrl(roomId, undefined, roomSharedKey ?? undefined)
);
Expand Down
7 changes: 4 additions & 3 deletions src/room/GroupCallView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -98,15 +99,15 @@ export function GroupCallView({
roomName,
roomAlias: rtcSession.room.getCanonicalAlias(),
roomAvatar,
roomEncrypted: isRoomE2EE!,
roomEncrypted,
};
}, [
displayName,
avatarUrl,
rtcSession,
roomName,
roomAvatar,
isRoomE2EE,
roomEncrypted,
client,
]);

Expand Down
2 changes: 1 addition & 1 deletion src/room/RoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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") && (
<AppSelectionModal roomId={roomId ?? undefined} />
<AppSelectionModal roomId={roomId} />
)}
</>
);
Expand Down

0 comments on commit 6bc8ccf

Please sign in to comment.