From 7713f0d58770068906d8d9b6b4a210977d1ffda8 Mon Sep 17 00:00:00 2001 From: wmwragg Date: Thu, 11 Aug 2016 17:32:39 +0100 Subject: [PATCH] refactoring out the direct message section --- src/MatrixTools.js | 30 ++++++++++++++++++++++++++ src/components/views/rooms/RoomList.js | 25 ++++++--------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/MatrixTools.js b/src/MatrixTools.js index b003d8d2d7..3bc7f28e20 100644 --- a/src/MatrixTools.js +++ b/src/MatrixTools.js @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +var CallHandler = require('./CallHandler'); module.exports = { /** @@ -24,5 +25,34 @@ module.exports = { getDisplayAliasForRoom: function(room) { return room.getCanonicalAlias() || room.getAliases()[0]; }, + + isDirectMessageRoom: function(room, me, ConferenceHandler, hideConferenceChans) { + if (me.membership == "join" || me.membership === "ban" || + (me.membership === "leave" && me.events.member.getSender() !== me.events.member.getStateKey())) + { + // Used to split rooms via tags + var tagNames = Object.keys(room.tags); + // Used for 1:1 direct chats + var joinedMembers = room.getJoinedMembers(); + + // Show 1:1 chats in seperate "Direct Messages" section as long as they haven't + // been moved to a different tag section + if (joinedMembers.length === 2 && !tagNames.length) { + var otherMember = joinedMembers.filter(function(m) { + return m.userId !== me.userId + })[0]; + + if (ConferenceHandler && ConferenceHandler.isConferenceUser(otherMember.userId)) { + // console.log("Hiding conference 1:1 room %s", room.roomId); + if (!hideConferenceChans) { + return true; + } + } else { + return true; + } + } + } + return false; + }, } diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index ffb3b366e8..ce3e3a0cf7 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -25,6 +25,7 @@ var Unread = require('../../../Unread'); var dis = require("../../../dispatcher"); var sdk = require('../../../index'); var rate_limited_func = require('../../../ratelimitedfunc'); +var MatrixTools = require('../../../MatrixTools'); var HIDE_CONFERENCE_CHANS = true; @@ -204,31 +205,17 @@ module.exports = React.createClass({ if (me.membership == "invite") { s.lists["im.vector.fake.invite"].push(room); } + else if (MatrixTools.isDirectMessageRoom(room, me, self.props.ConferenceHandler, HIDE_CONFERENCE_CHANS)) { + // "Direct Message" rooms + s.lists["im.vector.fake.direct"].push(room); + } else if (me.membership == "join" || me.membership === "ban" || (me.membership === "leave" && me.events.member.getSender() !== me.events.member.getStateKey())) { // Used to split rooms via tags var tagNames = Object.keys(room.tags); - // Used for 1:1 direct chats - var joinedMembers = room.getJoinedMembers(); - // Show 1:1 chats in seperate "Direct Messages" section as long as they haven't - // been moved to a different tag section - if (joinedMembers.length === 2 && !tagNames.length) { - var otherMember = joinedMembers.filter(function(m) { - return m.userId !== me.userId - })[0]; - - var ConfHandler = self.props.ConferenceHandler; - if (ConfHandler && ConfHandler.isConferenceUser(otherMember.userId)) { - // console.log("Hiding conference 1:1 room %s", room.roomId); - if (!HIDE_CONFERENCE_CHANS) { - s.lists["im.vector.fake.direct"].push(room); - } - } else { - s.lists["im.vector.fake.direct"].push(room); - } - } else if (tagNames.length) { + if (tagNames.length) { for (var i = 0; i < tagNames.length; i++) { var tagName = tagNames[i]; s.lists[tagName] = s.lists[tagName] || [];