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.
This commit is contained in:
parent
66ef08120e
commit
2ecabd2195
2 changed files with 17 additions and 27 deletions
|
@ -48,7 +48,7 @@ export function showStartChatInviteDialog() {
|
||||||
placeholder: _t("Email, name or Matrix ID"),
|
placeholder: _t("Email, name or Matrix ID"),
|
||||||
validAddressTypes: ['mx-user-id', 'email'],
|
validAddressTypes: ['mx-user-id', 'email'],
|
||||||
button: _t("Start Chat"),
|
button: _t("Start Chat"),
|
||||||
onFinished: _onStartChatFinished,
|
onFinished: _onStartDmFinished,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,8 @@ export function isValid3pidInvite(event) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _onStartChatFinished(shouldInvite, addrs) {
|
// TODO: Immutable DMs replaces this
|
||||||
|
function _onStartDmFinished(shouldInvite, addrs) {
|
||||||
if (!shouldInvite) return;
|
if (!shouldInvite) return;
|
||||||
|
|
||||||
const addrTexts = addrs.map((addr) => addr.address);
|
const addrTexts = addrs.map((addr) => addr.address);
|
||||||
|
@ -91,32 +92,19 @@ function _onStartChatFinished(shouldInvite, addrs) {
|
||||||
if (_isDmChat(addrTexts)) {
|
if (_isDmChat(addrTexts)) {
|
||||||
const rooms = _getDirectMessageRooms(addrTexts[0]);
|
const rooms = _getDirectMessageRooms(addrTexts[0]);
|
||||||
if (rooms.length > 0) {
|
if (rooms.length > 0) {
|
||||||
// A Direct Message room already exists for this user, so select a
|
// A Direct Message room already exists for this user, so reuse it
|
||||||
// room from a list that is similar to the one in MemberInfo panel
|
dis.dispatch({
|
||||||
const ChatCreateOrReuseDialog = sdk.getComponent("views.dialogs.ChatCreateOrReuseDialog");
|
action: 'view_room',
|
||||||
const close = Modal.createTrackedDialog('Create or Reuse', '', ChatCreateOrReuseDialog, {
|
room_id: rooms[0],
|
||||||
userId: addrTexts[0],
|
should_peek: false,
|
||||||
onNewDMClick: () => {
|
joining: false,
|
||||||
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 {
|
} else {
|
||||||
// Start a new DM chat
|
// Start a new DM chat
|
||||||
createRoom({dmUserId: addrTexts[0]}).catch((err) => {
|
createRoom({dmUserId: addrTexts[0]}).catch((err) => {
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
Modal.createTrackedDialog('Failed to invite user', '', ErrorDialog, {
|
Modal.createTrackedDialog('Failed to start chat', '', ErrorDialog, {
|
||||||
title: _t("Failed to invite user"),
|
title: _t("Failed to start chat"),
|
||||||
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -125,8 +113,8 @@ function _onStartChatFinished(shouldInvite, addrs) {
|
||||||
// Start a new DM chat
|
// Start a new DM chat
|
||||||
createRoom({dmUserId: addrTexts[0]}).catch((err) => {
|
createRoom({dmUserId: addrTexts[0]}).catch((err) => {
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
Modal.createTrackedDialog('Failed to invite user', '', ErrorDialog, {
|
Modal.createTrackedDialog('Failed to start chat', '', ErrorDialog, {
|
||||||
title: _t("Failed to invite user"),
|
title: _t("Failed to start chat"),
|
||||||
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
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) {
|
function _isDmChat(addrTexts) {
|
||||||
if (addrTexts.length === 1 && getAddressType(addrTexts[0]) === 'mx-user-id') {
|
if (addrTexts.length === 1 && getAddressType(addrTexts[0]) === 'mx-user-id') {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -114,8 +114,9 @@
|
||||||
"Invite new room members": "Invite new room members",
|
"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?",
|
"Who would you like to add to this room?": "Who would you like to add to this room?",
|
||||||
"Send Invites": "Send Invites",
|
"Send Invites": "Send Invites",
|
||||||
"Failed to invite user": "Failed to invite user",
|
"Failed to start chat": "Failed to start chat",
|
||||||
"Operation failed": "Operation failed",
|
"Operation failed": "Operation failed",
|
||||||
|
"Failed to invite user": "Failed to invite user",
|
||||||
"Failed to invite": "Failed to invite",
|
"Failed to invite": "Failed to invite",
|
||||||
"Failed to invite users to the room:": "Failed to invite users to the room:",
|
"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:",
|
"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 a new issue