Check if a room looks like a DM rooms on joining

and mark it as one if so.

Also change the heuristic to only count rooms with 2 total members rather than 2 joined members, otherwise this is going to mark any room as a DM if someone creates a room, invites a bunch of people and you happen to be first to join.
pull/21833/head
David Baker 2016-09-20 17:59:46 +01:00
parent b66c449bd7
commit d1a5e54a69
2 changed files with 13 additions and 1 deletions

View File

@ -68,7 +68,7 @@ export function looksLikeDirectMessageRoom(room, me) {
// Used to split rooms via tags // Used to split rooms via tags
const tagNames = Object.keys(room.tags); const tagNames = Object.keys(room.tags);
// Used for 1:1 direct chats // Used for 1:1 direct chats
const joinedMembers = room.getJoinedMembers(); const joinedMembers = room.currentState.getMembers();
// Show 1:1 chats in seperate "Direct Messages" section as long as they haven't // Show 1:1 chats in seperate "Direct Messages" section as long as they haven't
// been moved to a different tag section // been moved to a different tag section

View File

@ -451,6 +451,7 @@ module.exports = React.createClass({
room: room, room: room,
joining: false, joining: false,
}); });
this._onRoomLoaded(room); this._onRoomLoaded(room);
} }
}, },
@ -520,6 +521,17 @@ module.exports = React.createClass({
// into. // into.
var me = MatrixClientPeg.get().credentials.userId; var me = MatrixClientPeg.get().credentials.userId;
if (this.state.joining && this.state.room.hasMembershipState(me, "join")) { if (this.state.joining && this.state.room.hasMembershipState(me, "join")) {
// Having just joined a room, check to see if it looks like a DM room, and if so,
// mark it as one. This is to work around the fact that some clients don't support
// is_direct. We should remove this once they do.
const me = this.state.room.getMember(MatrixClientPeg.get().credentials.userId);
if (Rooms.looksLikeDirectMessageRoom(this.state.room, me)) {
// XXX: There's not a whole lot we can really do if this fails: at best
// perhaps we could try a couple more times, but since it's a temporary
// compatability workaround, let's not bother.
Rooms.setDMRoom(this.state.room.roomId, me.events.member.getSender()).done();
}
this.setState({ this.setState({
joining: false joining: false
}); });