If a Direct Message room already exists for the users specified, then just go to that room, rather than creating another one

This commit is contained in:
wmwragg 2016-09-08 11:45:09 +01:00
parent 7dfb8857d8
commit d0523cae70

View file

@ -20,7 +20,9 @@ var sdk = require("../../../index");
var Invite = require("../../../Invite"); var Invite = require("../../../Invite");
var createRoom = require("../../../createRoom"); var createRoom = require("../../../createRoom");
var MatrixClientPeg = require("../../../MatrixClientPeg"); var MatrixClientPeg = require("../../../MatrixClientPeg");
var DMRoomMap = require('../../../utils/DMRoomMap');
var rate_limited_func = require("../../../ratelimitedfunc"); var rate_limited_func = require("../../../ratelimitedfunc");
var dis = require("../../../dispatcher");
var Modal = require('../../../Modal'); var Modal = require('../../../Modal');
const TRUNCATE_QUERY_LIST = 40; const TRUNCATE_QUERY_LIST = 40;
@ -79,7 +81,9 @@ module.exports = React.createClass({
}, },
onStartChat: function() { onStartChat: function() {
const dmRoomMap = new DMRoomMap(MatrixClientPeg.get());
var addr; var addr;
// Either an address tile was created, or text input is being used // Either an address tile was created, or text input is being used
if (this.state.user) { if (this.state.user) {
addr = this.state.user.userId; addr = this.state.user.userId;
@ -88,7 +92,20 @@ module.exports = React.createClass({
} }
// Check if the addr is a valid type // 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); this._startChat(addr);
} else { } else {
// Nothing to do, so focus back on the textinput // Nothing to do, so focus back on the textinput
@ -211,7 +228,7 @@ module.exports = React.createClass({
"mx_ChatInviteDialog_selected": this.state.selected === i, "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 // Saving the queryListElement so we can use it to work out, in the componentDidUpdate
// method, how far to scroll when using the arrow keys // method, how far to scroll when using the arrow keys
queryList.push( queryList.push(