From 47e6527b0e3a280cb5529d8a1921d184c4ef284e Mon Sep 17 00:00:00 2001 From: Krishan <33421343+kfiven@users.noreply.github.com> Date: Fri, 8 Jul 2022 20:24:35 +0530 Subject: [PATCH] Don't enable e2ee from profileViewer for bridge users (#666) --- src/app/organisms/invite-user/InviteUser.jsx | 14 +------------- src/app/organisms/profile-viewer/ProfileViewer.jsx | 4 ++-- src/util/matrixUtil.js | 13 +++++++++++++ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/app/organisms/invite-user/InviteUser.jsx b/src/app/organisms/invite-user/InviteUser.jsx index d0a8d9e1..75195102 100644 --- a/src/app/organisms/invite-user/InviteUser.jsx +++ b/src/app/organisms/invite-user/InviteUser.jsx @@ -6,7 +6,7 @@ import initMatrix from '../../../client/initMatrix'; import cons from '../../../client/state/cons'; import * as roomActions from '../../../client/action/room'; import { selectRoom } from '../../../client/action/navigation'; -import { hasDMWith } from '../../../util/matrixUtil'; +import { hasDMWith, hasDevices } from '../../../util/matrixUtil'; import Text from '../../atoms/text/Text'; import Button from '../../atoms/button/Button'; @@ -103,18 +103,6 @@ function InviteUser({ updateIsSearching(false); } - async function hasDevices(userId) { - try { - const usersDeviceMap = await mx.downloadKeys([userId, mx.getUserId()]); - return Object.values(usersDeviceMap).every((userDevices) => - Object.keys(userDevices).length > 0, - ); - } catch (e) { - console.error("Error determining if it's possible to encrypt to all users: ", e); - return false; - } - } - async function createDM(userId) { if (mx.getUserId() === userId) return; const dmRoomId = hasDMWith(userId); diff --git a/src/app/organisms/profile-viewer/ProfileViewer.jsx b/src/app/organisms/profile-viewer/ProfileViewer.jsx index d74629f2..26e39682 100644 --- a/src/app/organisms/profile-viewer/ProfileViewer.jsx +++ b/src/app/organisms/profile-viewer/ProfileViewer.jsx @@ -11,7 +11,7 @@ import { selectRoom, openReusableContextMenu } from '../../../client/action/navi import * as roomActions from '../../../client/action/room'; import { - getUsername, getUsernameOfRoomMember, getPowerLabel, hasDMWith + getUsername, getUsernameOfRoomMember, getPowerLabel, hasDMWith, hasDevices } from '../../../util/matrixUtil'; import { getEventCords } from '../../../util/common'; import colorMXID from '../../../util/colorMXID'; @@ -201,7 +201,7 @@ function ProfileFooter({ roomId, userId, onRequestClose }) { // Create new DM try { setIsCreatingDM(true); - await roomActions.createDM(userId); + await roomActions.createDM(userId, await hasDevices(userId)); } catch { if (isMountedRef.current === false) return; setIsCreatingDM(false); diff --git a/src/util/matrixUtil.js b/src/util/matrixUtil.js index 16be1175..fb97d850 100644 --- a/src/util/matrixUtil.js +++ b/src/util/matrixUtil.js @@ -199,3 +199,16 @@ export function getSSKeyInfo(key) { return undefined; } } + +export async function hasDevices(userId) { + const mx = initMatrix.matrixClient; + try { + const usersDeviceMap = await mx.downloadKeys([userId, mx.getUserId()]); + return Object.values(usersDeviceMap).every((userDevices) => + Object.keys(userDevices).length > 0, + ); + } catch (e) { + console.error("Error determining if it's possible to encrypt to all users: ", e); + return false; + } +} \ No newline at end of file