mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-18 06:35:35 +08:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
6618687b36
@ -21,6 +21,8 @@ import Modal from './Modal';
|
|||||||
import { getAddressType } from './UserAddress';
|
import { getAddressType } from './UserAddress';
|
||||||
import createRoom from './createRoom';
|
import createRoom from './createRoom';
|
||||||
import sdk from './';
|
import sdk from './';
|
||||||
|
import dis from './dispatcher';
|
||||||
|
import DMRoomMap from './utils/DMRoomMap';
|
||||||
import { _t } from './languageHandler';
|
import { _t } from './languageHandler';
|
||||||
|
|
||||||
export function inviteToRoom(roomId, addr) {
|
export function inviteToRoom(roomId, addr) {
|
||||||
@ -79,15 +81,40 @@ function _onStartChatFinished(shouldInvite, addrs) {
|
|||||||
const addrTexts = addrs.map((addr) => addr.address);
|
const addrTexts = addrs.map((addr) => addr.address);
|
||||||
|
|
||||||
if (_isDmChat(addrTexts)) {
|
if (_isDmChat(addrTexts)) {
|
||||||
// Start a new DM chat
|
const rooms = _getDirectMessageRooms(addrTexts[0]);
|
||||||
createRoom({dmUserId: addrTexts[0]}).catch((err) => {
|
if (rooms.length > 0) {
|
||||||
console.error(err.stack);
|
// A Direct Message room already exists for this user, so select a
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
// room from a list that is similar to the one in MemberInfo panel
|
||||||
Modal.createTrackedDialog('Failed to invite user', '', ErrorDialog, {
|
const ChatCreateOrReuseDialog = sdk.getComponent(
|
||||||
title: _t("Failed to invite user"),
|
"views.dialogs.ChatCreateOrReuseDialog",
|
||||||
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
);
|
||||||
|
const close = Modal.createTrackedDialog('Create or Reuse', '', ChatCreateOrReuseDialog, {
|
||||||
|
userId: addrTexts[0],
|
||||||
|
onNewDMClick: () => {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'start_chat',
|
||||||
|
user_id: addrTexts[0],
|
||||||
|
});
|
||||||
|
close(true);
|
||||||
|
},
|
||||||
|
onExistingRoomSelected: (roomId) => {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'view_room',
|
||||||
|
room_id: roomId,
|
||||||
|
});
|
||||||
|
close(true);
|
||||||
|
},
|
||||||
|
}).close;
|
||||||
|
} else {
|
||||||
|
// Start a new DM chat
|
||||||
|
createRoom({dmUserId: addrTexts[0]}).catch((err) => {
|
||||||
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
|
Modal.createTrackedDialog('Failed to invite user', '', ErrorDialog, {
|
||||||
|
title: _t("Failed to invite user"),
|
||||||
|
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
// Start multi user chat
|
// Start multi user chat
|
||||||
let room;
|
let room;
|
||||||
@ -153,3 +180,19 @@ function _showAnyInviteErrors(addrs, room) {
|
|||||||
return addrs;
|
return addrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _getDirectMessageRooms(addr) {
|
||||||
|
const dmRoomMap = new DMRoomMap(MatrixClientPeg.get());
|
||||||
|
const dmRooms = dmRoomMap.getDMRoomsForUserId(addr);
|
||||||
|
const rooms = [];
|
||||||
|
dmRooms.forEach((dmRoom) => {
|
||||||
|
const room = MatrixClientPeg.get().getRoom(dmRoom);
|
||||||
|
if (room) {
|
||||||
|
const me = room.getMember(MatrixClientPeg.get().credentials.userId);
|
||||||
|
if (me.membership == 'join') {
|
||||||
|
rooms.push(room);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return rooms;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user