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 { 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 { useEnableE2EE } from "../settings/useSetting";
|
||||||
import { useLocalStorage } from "../useLocalStorage";
|
import { useLocalStorage } from "../useLocalStorage";
|
||||||
|
import { useClient } from "../ClientContext";
|
||||||
import { PASSWORD_STRING, useUrlParams } from "../UrlParams";
|
import { PASSWORD_STRING, useUrlParams } from "../UrlParams";
|
||||||
import { widget } from "../widget";
|
import { widget } from "../widget";
|
||||||
|
|
||||||
@@ -84,19 +83,14 @@ export const useManageRoomSharedKey = (roomId: string): string | null => {
|
|||||||
return e2eeSharedKey ?? urlPassword;
|
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.
|
// For now, rooms in widget mode are never considered encrypted.
|
||||||
// In the future, when widget mode gains encryption support, then perhaps we
|
// In the future, when widget mode gains encryption support, then perhaps we
|
||||||
// should inspect the e2eEnabled URL parameter here?
|
// should inspect the e2eEnabled URL parameter here?
|
||||||
const canonAlias = useMemo(
|
return useMemo(
|
||||||
() => (room ? room.getCanonicalAlias() : null),
|
() => widget === null && (room === null || !room.getCanonicalAlias()),
|
||||||
[room]
|
[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 { getAbsoluteRoomUrl } from "../matrix-utils";
|
||||||
import styles from "./AppSelectionModal.module.css";
|
import styles from "./AppSelectionModal.module.css";
|
||||||
import { editFragmentQuery } from "../UrlParams";
|
import { editFragmentQuery } from "../UrlParams";
|
||||||
import { useClient } from "../ClientContext";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
roomId: string | undefined;
|
roomId: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AppSelectionModal: FC<Props> = ({ roomId }) => {
|
export const AppSelectionModal: FC<Props> = ({ roomId }) => {
|
||||||
@@ -44,11 +43,8 @@ export const AppSelectionModal: FC<Props> = ({ roomId }) => {
|
|||||||
[setOpen]
|
[setOpen]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { client } = useClient();
|
|
||||||
const room = useMemo(() => client?.getRoom(roomId) ?? null, [roomId, client]);
|
|
||||||
|
|
||||||
const roomSharedKey = useRoomSharedKey(roomId ?? "");
|
const roomSharedKey = useRoomSharedKey(roomId ?? "");
|
||||||
const roomIsEncrypted = useIsRoomE2EE(room ?? undefined);
|
const roomIsEncrypted = useIsRoomE2EE(roomId ?? "");
|
||||||
if (roomIsEncrypted && roomSharedKey === undefined) {
|
if (roomIsEncrypted && roomSharedKey === undefined) {
|
||||||
logger.error(
|
logger.error(
|
||||||
"Generating app redirect URL for encrypted room but don't have key available!"
|
"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
|
// 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.
|
// ever sees so it's somewhat redundant. We just don't pass a name.
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
!roomId
|
roomId === null
|
||||||
? window.location.href
|
? window.location.href
|
||||||
: getAbsoluteRoomUrl(roomId, undefined, roomSharedKey ?? undefined)
|
: getAbsoluteRoomUrl(roomId, undefined, roomSharedKey ?? undefined)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ export function GroupCallView({
|
|||||||
const isJoined = useMatrixRTCSessionJoinState(rtcSession);
|
const isJoined = useMatrixRTCSessionJoinState(rtcSession);
|
||||||
|
|
||||||
const e2eeSharedKey = useManageRoomSharedKey(rtcSession.room.roomId);
|
const e2eeSharedKey = useManageRoomSharedKey(rtcSession.room.roomId);
|
||||||
const isRoomE2EE = useIsRoomE2EE(rtcSession.room);
|
const isRoomE2EE = useIsRoomE2EE(rtcSession.room.roomId);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.rtcSession = rtcSession;
|
window.rtcSession = rtcSession;
|
||||||
@@ -88,6 +88,7 @@ export function GroupCallView({
|
|||||||
const { displayName, avatarUrl } = useProfile(client);
|
const { displayName, avatarUrl } = useProfile(client);
|
||||||
const roomName = useRoomName(rtcSession.room);
|
const roomName = useRoomName(rtcSession.room);
|
||||||
const roomAvatar = useRoomAvatar(rtcSession.room);
|
const roomAvatar = useRoomAvatar(rtcSession.room);
|
||||||
|
const roomEncrypted = useIsRoomE2EE(rtcSession.room.roomId)!;
|
||||||
|
|
||||||
const matrixInfo = useMemo((): MatrixInfo => {
|
const matrixInfo = useMemo((): MatrixInfo => {
|
||||||
return {
|
return {
|
||||||
@@ -98,7 +99,7 @@ export function GroupCallView({
|
|||||||
roomName,
|
roomName,
|
||||||
roomAlias: rtcSession.room.getCanonicalAlias(),
|
roomAlias: rtcSession.room.getCanonicalAlias(),
|
||||||
roomAvatar,
|
roomAvatar,
|
||||||
roomEncrypted: isRoomE2EE!,
|
roomEncrypted,
|
||||||
};
|
};
|
||||||
}, [
|
}, [
|
||||||
displayName,
|
displayName,
|
||||||
@@ -106,7 +107,7 @@ export function GroupCallView({
|
|||||||
rtcSession,
|
rtcSession,
|
||||||
roomName,
|
roomName,
|
||||||
roomAvatar,
|
roomAvatar,
|
||||||
isRoomE2EE,
|
roomEncrypted,
|
||||||
client,
|
client,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export const RoomPage: FC = () => {
|
|||||||
{content}
|
{content}
|
||||||
{/* On Android and iOS, show a prompt to launch the mobile app. */}
|
{/* On Android and iOS, show a prompt to launch the mobile app. */}
|
||||||
{appPrompt && (platform === "android" || platform === "ios") && (
|
{appPrompt && (platform === "android" || platform === "ios") && (
|
||||||
<AppSelectionModal roomId={roomId ?? undefined} />
|
<AppSelectionModal roomId={roomId} />
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user