mirror of https://github.com/vector-im/riot-web
Reuse direct chats when starting new ones
Part of https://github.com/vector-im/riot-web/issues/10416 This section of code applies to the + button next to PEOPLE in the room list.pull/21833/head
parent
66ef08120e
commit
2ecabd2195
|
@ -48,7 +48,7 @@ export function showStartChatInviteDialog() {
|
|||
placeholder: _t("Email, name or Matrix ID"),
|
||||
validAddressTypes: ['mx-user-id', 'email'],
|
||||
button: _t("Start Chat"),
|
||||
onFinished: _onStartChatFinished,
|
||||
onFinished: _onStartDmFinished,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,8 @@ export function isValid3pidInvite(event) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function _onStartChatFinished(shouldInvite, addrs) {
|
||||
// TODO: Immutable DMs replaces this
|
||||
function _onStartDmFinished(shouldInvite, addrs) {
|
||||
if (!shouldInvite) return;
|
||||
|
||||
const addrTexts = addrs.map((addr) => addr.address);
|
||||
|
@ -91,32 +92,19 @@ function _onStartChatFinished(shouldInvite, addrs) {
|
|||
if (_isDmChat(addrTexts)) {
|
||||
const rooms = _getDirectMessageRooms(addrTexts[0]);
|
||||
if (rooms.length > 0) {
|
||||
// A Direct Message room already exists for this user, so select a
|
||||
// room from a list that is similar to the one in MemberInfo panel
|
||||
const ChatCreateOrReuseDialog = sdk.getComponent("views.dialogs.ChatCreateOrReuseDialog");
|
||||
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;
|
||||
// A Direct Message room already exists for this user, so reuse it
|
||||
dis.dispatch({
|
||||
action: 'view_room',
|
||||
room_id: rooms[0],
|
||||
should_peek: false,
|
||||
joining: false,
|
||||
});
|
||||
} 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"),
|
||||
Modal.createTrackedDialog('Failed to start chat', '', ErrorDialog, {
|
||||
title: _t("Failed to start chat"),
|
||||
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
||||
});
|
||||
});
|
||||
|
@ -125,8 +113,8 @@ function _onStartChatFinished(shouldInvite, addrs) {
|
|||
// 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"),
|
||||
Modal.createTrackedDialog('Failed to start chat', '', ErrorDialog, {
|
||||
title: _t("Failed to start chat"),
|
||||
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
||||
});
|
||||
});
|
||||
|
@ -168,6 +156,7 @@ function _onRoomInviteFinished(roomId, shouldInvite, addrs) {
|
|||
});
|
||||
}
|
||||
|
||||
// TODO: Immutable DMs replaces this
|
||||
function _isDmChat(addrTexts) {
|
||||
if (addrTexts.length === 1 && getAddressType(addrTexts[0]) === 'mx-user-id') {
|
||||
return true;
|
||||
|
|
|
@ -114,8 +114,9 @@
|
|||
"Invite new room members": "Invite new room members",
|
||||
"Who would you like to add to this room?": "Who would you like to add to this room?",
|
||||
"Send Invites": "Send Invites",
|
||||
"Failed to invite user": "Failed to invite user",
|
||||
"Failed to start chat": "Failed to start chat",
|
||||
"Operation failed": "Operation failed",
|
||||
"Failed to invite user": "Failed to invite user",
|
||||
"Failed to invite": "Failed to invite",
|
||||
"Failed to invite users to the room:": "Failed to invite users to the room:",
|
||||
"Failed to invite the following users to the %(roomName)s room:": "Failed to invite the following users to the %(roomName)s room:",
|
||||
|
|
Loading…
Reference in New Issue