Keep direct rooms orthogonal (#183)
Signed-off-by: ajbura <ajbura@gmail.com>
This commit is contained in:
parent
a9692f7db4
commit
c8ae428df8
3 changed files with 31 additions and 11 deletions
|
@ -6,6 +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 Text from '../../atoms/text/Text';
|
import Text from '../../atoms/text/Text';
|
||||||
import Button from '../../atoms/button/Button';
|
import Button from '../../atoms/button/Button';
|
||||||
|
@ -104,6 +105,13 @@ function InviteUser({
|
||||||
|
|
||||||
async function createDM(userId) {
|
async function createDM(userId) {
|
||||||
if (mx.getUserId() === userId) return;
|
if (mx.getUserId() === userId) return;
|
||||||
|
const dmRoomId = hasDMWith(userId);
|
||||||
|
if (dmRoomId) {
|
||||||
|
selectRoom(dmRoomId);
|
||||||
|
onRequestClose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addUserToProc(userId);
|
addUserToProc(userId);
|
||||||
procUserError.delete(userId);
|
procUserError.delete(userId);
|
||||||
|
|
|
@ -10,7 +10,9 @@ import navigation from '../../../client/state/navigation';
|
||||||
import { selectRoom, openReusableContextMenu } from '../../../client/action/navigation';
|
import { selectRoom, openReusableContextMenu } from '../../../client/action/navigation';
|
||||||
import * as roomActions from '../../../client/action/room';
|
import * as roomActions from '../../../client/action/room';
|
||||||
|
|
||||||
import { getUsername, getUsernameOfRoomMember, getPowerLabel } from '../../../util/matrixUtil';
|
import {
|
||||||
|
getUsername, getUsernameOfRoomMember, getPowerLabel, hasDMWith
|
||||||
|
} from '../../../util/matrixUtil';
|
||||||
import { getEventCords } from '../../../util/common';
|
import { getEventCords } from '../../../util/common';
|
||||||
import colorMXID from '../../../util/colorMXID';
|
import colorMXID from '../../../util/colorMXID';
|
||||||
|
|
||||||
|
@ -187,17 +189,12 @@ function ProfileFooter({ roomId, userId, onRequestClose }) {
|
||||||
}, [userId]);
|
}, [userId]);
|
||||||
|
|
||||||
const openDM = async () => {
|
const openDM = async () => {
|
||||||
const directIds = [...initMatrix.roomList.directs];
|
|
||||||
|
|
||||||
// Check and open if user already have a DM with userId.
|
// Check and open if user already have a DM with userId.
|
||||||
for (let i = 0; i < directIds.length; i += 1) {
|
const dmRoomId = hasDMWith(userId);
|
||||||
const dRoom = mx.getRoom(directIds[i]);
|
if (dmRoomId) {
|
||||||
const roomMembers = dRoom.getMembers();
|
selectRoom(dmRoomId);
|
||||||
if (roomMembers.length <= 2 && dRoom.getMember(userId)) {
|
onRequestClose();
|
||||||
selectRoom(directIds[i]);
|
return;
|
||||||
onRequestClose();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new DM
|
// Create new DM
|
||||||
|
|
|
@ -72,7 +72,22 @@ function parseReply(rawBody) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasDMWith(userId) {
|
||||||
|
const mx = initMatrix.matrixClient;
|
||||||
|
const directIds = [...initMatrix.roomList.directs];
|
||||||
|
|
||||||
|
return directIds.find((roomId) => {
|
||||||
|
const dRoom = mx.getRoom(roomId);
|
||||||
|
const roomMembers = dRoom.getMembers();
|
||||||
|
if (roomMembers.length <= 2 && dRoom.getMember(userId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getBaseUrl, getUsername, getUsernameOfRoomMember,
|
getBaseUrl, getUsername, getUsernameOfRoomMember,
|
||||||
isRoomAliasAvailable, getPowerLabel, parseReply,
|
isRoomAliasAvailable, getPowerLabel, parseReply,
|
||||||
|
hasDMWith,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue