Merge pull request #1571 from vector-im/revert-1570-dbkr/isroome2ee_refactor
Revert "Refactor useIsRoomE2EE"
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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 }) => {
|
||||
@@ -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!"
|
||||
@@ -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)
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
]);
|
||||
|
||||
|
||||
@@ -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} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user