Flag incoming DMs as such

* Add the 'is_direct' flag to rooms created for DMs
 * For invites, look for the DM flag when getting the DM user ID for a room
 * When accepting an invite, look for the flag and mark the room as a DM room if appropriate.
This commit is contained in:
David Baker 2016-09-12 18:32:44 +01:00
parent f6478f111a
commit 2943db1072
3 changed files with 33 additions and 0 deletions

View file

@ -21,6 +21,7 @@ limitations under the License.
*/
export default class DMRoomMap {
constructor(matrixClient) {
this.matrixClient = matrixClient;
this.roomToUser = null;
const mDirectEvent = matrixClient.getAccountData('m.direct');
@ -49,6 +50,20 @@ export default class DMRoomMap {
}
// Here, we return undefined if the room is not in the map:
// the room ID you gave is not a DM room for any user.
if (this.roomToUser[roomId] === undefined) {
// no entry? if the room is an invite, look for the is_direct hint.
const room = this.matrixClient.getRoom(roomId);
if (room) {
const me = room.getMember(this.matrixClient.credentials.userId);
if (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) {
return me.events.member.getSender();
}
}
}
}
return this.roomToUser[roomId];
}