Compare commits
1 commit
dev
...
dm-profile
Author | SHA1 | Date | |
---|---|---|---|
|
cc423fcc96 |
3 changed files with 16 additions and 15 deletions
|
@ -6,7 +6,7 @@ import initMatrix from '../../../client/initMatrix';
|
||||||
import cons from '../../../client/state/cons';
|
import cons from '../../../client/state/cons';
|
||||||
import * as roomActions from '../../../client/action/room';
|
import * as roomActions from '../../../client/action/room';
|
||||||
import { selectRoom } from '../../../client/action/navigation';
|
import { selectRoom } from '../../../client/action/navigation';
|
||||||
import { hasDMWith } from '../../../util/matrixUtil';
|
import { hasDMWith, hasDevices } from '../../../util/matrixUtil';
|
||||||
|
|
||||||
import Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
import Button from '../../atoms/button/Button';
|
import Button from '../../atoms/button/Button';
|
||||||
|
@ -103,18 +103,6 @@ function InviteUser({
|
||||||
updateIsSearching(false);
|
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) {
|
async function createDM(userId) {
|
||||||
if (mx.getUserId() === userId) return;
|
if (mx.getUserId() === userId) return;
|
||||||
const dmRoomId = hasDMWith(userId);
|
const dmRoomId = hasDMWith(userId);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { selectRoom, openReusableContextMenu } from '../../../client/action/navi
|
||||||
import * as roomActions from '../../../client/action/room';
|
import * as roomActions from '../../../client/action/room';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getUsername, getUsernameOfRoomMember, getPowerLabel, hasDMWith
|
getUsername, getUsernameOfRoomMember, getPowerLabel, hasDMWith, hasDevices
|
||||||
} from '../../../util/matrixUtil';
|
} from '../../../util/matrixUtil';
|
||||||
import { getEventCords } from '../../../util/common';
|
import { getEventCords } from '../../../util/common';
|
||||||
import colorMXID from '../../../util/colorMXID';
|
import colorMXID from '../../../util/colorMXID';
|
||||||
|
@ -201,7 +201,7 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
|
||||||
// Create new DM
|
// Create new DM
|
||||||
try {
|
try {
|
||||||
setIsCreatingDM(true);
|
setIsCreatingDM(true);
|
||||||
await roomActions.createDM(userId);
|
await roomActions.createDM(userId, await hasDevices(userId));
|
||||||
} catch {
|
} catch {
|
||||||
if (isMountedRef.current === false) return;
|
if (isMountedRef.current === false) return;
|
||||||
setIsCreatingDM(false);
|
setIsCreatingDM(false);
|
||||||
|
|
|
@ -199,3 +199,16 @@ export function getSSKeyInfo(key) {
|
||||||
return undefined;
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue