From d0523cae70dd15bfaf3330ae3586b2ab8975cdb3 Mon Sep 17 00:00:00 2001 From: wmwragg Date: Thu, 8 Sep 2016 11:45:09 +0100 Subject: [PATCH] If a Direct Message room already exists for the users specified, then just go to that room, rather than creating another one --- .../views/dialogs/ChatInviteDialog.js | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/views/dialogs/ChatInviteDialog.js b/src/components/views/dialogs/ChatInviteDialog.js index 592a600a63..12452fb479 100644 --- a/src/components/views/dialogs/ChatInviteDialog.js +++ b/src/components/views/dialogs/ChatInviteDialog.js @@ -20,7 +20,9 @@ var sdk = require("../../../index"); var Invite = require("../../../Invite"); var createRoom = require("../../../createRoom"); var MatrixClientPeg = require("../../../MatrixClientPeg"); +var DMRoomMap = require('../../../utils/DMRoomMap'); var rate_limited_func = require("../../../ratelimitedfunc"); +var dis = require("../../../dispatcher"); var Modal = require('../../../Modal'); const TRUNCATE_QUERY_LIST = 40; @@ -79,7 +81,9 @@ module.exports = React.createClass({ }, onStartChat: function() { + const dmRoomMap = new DMRoomMap(MatrixClientPeg.get()); var addr; + // Either an address tile was created, or text input is being used if (this.state.user) { addr = this.state.user.userId; @@ -88,7 +92,20 @@ module.exports = React.createClass({ } // Check if the addr is a valid type - if (Invite.getAddressType(addr) !== null) { + if (Invite.getAddressType(addr) === "mx") { + var dmRooms = dmRoomMap.getDMRoomsForUserId(addr); + if (dmRooms) { + // A Direct Message room already exists for this user and you + // so go straight to that room + dis.dispatch({ + action: 'view_room', + room_id: dmRooms[0], + }); + this.props.onFinished(true, addr); + } else { + this._startChat(addr); + } + } else if (Invite.getAddressType(addr) === "email") { this._startChat(addr); } else { // Nothing to do, so focus back on the textinput @@ -211,7 +228,7 @@ module.exports = React.createClass({ "mx_ChatInviteDialog_selected": this.state.selected === i, }); - // NOTE: Defaulting to "vector" as the network, until the network backend stuff is done + // NOTE: Defaulting to "vector" as the network, until the network backend stuff is done. // Saving the queryListElement so we can use it to work out, in the componentDidUpdate // method, how far to scroll when using the arrow keys queryList.push(