Merge pull request #487 from matrix-org/dbkr/incoming_dm_heuristic

Apply heuristic on incoming DMs
pull/21833/head
David Baker 2016-09-21 10:29:30 +01:00 committed by GitHub
commit 2fd3c7c5ac
2 changed files with 16 additions and 4 deletions

View File

@ -68,11 +68,11 @@ 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 members = 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
if (joinedMembers.length === 2 && !tagNames.length) { if (members.length === 2 && !tagNames.length) {
return true; return true;
} }
} }

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
}); });
@ -679,9 +691,9 @@ module.exports = React.createClass({
if (this.state.room) { if (this.state.room) {
const me = this.state.room.getMember(MatrixClientPeg.get().credentials.userId); const me = this.state.room.getMember(MatrixClientPeg.get().credentials.userId);
if (me && me.membership == 'invite') { if (me && me.membership == 'invite') {
// The 'direct' hihnt is there, so declare that this is a DM room for
// whoever invited us.
if (me.events.member.getContent().is_direct) { if (me.events.member.getContent().is_direct) {
// The 'direct' hint is there, so declare that this is a DM room for
// whoever invited us.
return Rooms.setDMRoom(this.state.room.roomId, me.events.member.getSender()); return Rooms.setDMRoom(this.state.room.roomId, me.events.member.getSender());
} }
} }