From a8d0d8f33dae99dc5422dc34bd458e63d54e77d6 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 2 Aug 2018 11:38:58 +0200 Subject: [PATCH] provide method on room to help with DM detection with fallback to summary heroes/counts. --- src/models/room.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/models/room.js b/src/models/room.js index 6301501af..8673ee5e9 100644 --- a/src/models/room.js +++ b/src/models/room.js @@ -240,6 +240,21 @@ Room.prototype.getMyMembership = function() { return this._syncedMembership; }; +Room.prototype.getDMInviter = function() { + if (this.myUserId) { + const me = this.getMember(this.myUserId); + if (me) { + return me.getDMInviter(); + } + } + // fall back to summary information + const memberCount = room.currentState.getJoinedMemberCount() + + room.currentState.getInvitedMemberCount(); + if (memberCount == 2 && this._summaryHeroes.length) { + return this._summaryHeroes[0]; + } +} + /** * Sets the membership this room was received as during sync * @param {string} membership join | leave | invite