From fc892b3580ea6b6f8ed10f82b2aa952760db38a7 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 11 Sep 2015 16:55:48 +0100 Subject: [PATCH] Hide 1:1 conference rooms --- src/CallHandler.js | 6 ++--- src/ConferenceHandler.js | 32 +++++++++++++++++++++------ src/controllers/organisms/RoomList.js | 22 +++++++++++++++++- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/CallHandler.js b/src/CallHandler.js index dbdb84e459..42cc5d57e2 100644 --- a/src/CallHandler.js +++ b/src/CallHandler.js @@ -57,7 +57,7 @@ var MatrixClientPeg = require("./MatrixClientPeg"); var Modal = require("./Modal"); var ComponentBroker = require('./ComponentBroker'); var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog"); -var ConferenceHandler = require("./ConferenceHandler"); +var ConferenceCall = require("./ConferenceHandler").ConferenceCall; var Matrix = require("matrix-js-sdk"); var dis = require("./dispatcher"); @@ -196,10 +196,10 @@ dis.register(function(payload) { } else { // > 2 console.log("Place conference call in %s", payload.room_id); - var confHandler = new ConferenceHandler( + var confCall = new ConferenceCall( MatrixClientPeg.get(), payload.room_id ); - confHandler.setup().done(function(call) { + confCall.setup().done(function(call) { placeCall(call); }, function(err) { console.error("Failed to setup conference call: %s", err); diff --git a/src/ConferenceHandler.js b/src/ConferenceHandler.js index ef36094306..6a43fe24a4 100644 --- a/src/ConferenceHandler.js +++ b/src/ConferenceHandler.js @@ -6,15 +6,15 @@ var Room = Matrix.Room; var USER_PREFIX = "fs_"; var DOMAIN = "matrix.org"; -function ConferenceHandler(matrixClient, groupChatRoomId) { +function ConferenceCall(matrixClient, groupChatRoomId) { this.client = matrixClient; this.groupRoomId = groupChatRoomId; // abuse browserify's core node Buffer support (strip padding ='s) - this.base64RoomId = new Buffer(this.groupRoomId).toString("base64").replace(/=/g, ""); - this.confUserId = "@" + USER_PREFIX + this.base64RoomId + ":" + DOMAIN; + var base64RoomId = new Buffer(groupChatRoomId).toString("base64").replace(/=/g, ""); + this.confUserId = "@" + USER_PREFIX + base64RoomId + ":" + DOMAIN; } -ConferenceHandler.prototype.setup = function() { +ConferenceCall.prototype.setup = function() { var self = this; return this._joinConferenceUser().then(function() { return self._getConferenceUserRoom(); @@ -24,7 +24,7 @@ ConferenceHandler.prototype.setup = function() { }); }; -ConferenceHandler.prototype._joinConferenceUser = function() { +ConferenceCall.prototype._joinConferenceUser = function() { // Make sure the conference user is in the group chat room var groupRoom = this.client.getRoom(this.groupRoomId); if (!groupRoom) { @@ -37,7 +37,7 @@ ConferenceHandler.prototype._joinConferenceUser = function() { return this.client.invite(this.groupRoomId, this.confUserId); }; -ConferenceHandler.prototype._getConferenceUserRoom = function() { +ConferenceCall.prototype._getConferenceUserRoom = function() { // Use an existing 1:1 with the conference user; else make one var rooms = this.client.getRooms(); var confRoom = null; @@ -60,5 +60,23 @@ ConferenceHandler.prototype._getConferenceUserRoom = function() { }); }; -module.exports = ConferenceHandler; +/** + * Check if this room member is in fact a conference bot. + * @param {RoomMember} The room member to check + * @return {boolean} True if it is a conference bot. + */ +module.exports.isConferenceUser = function(roomMember) { + if (roomMember.userId.indexOf("@" + USER_PREFIX) !== 0) { + return false; + } + var base64part = roomMember.userId.split(":")[0].substring(1 + USER_PREFIX.length); + if (base64part) { + var decoded = new Buffer(base64part, "base64").toString(); + // ! $STUFF : $STUFF + return /^!.+:.+/.test(decoded); + } + return false; +}; + +module.exports.ConferenceCall = ConferenceCall; diff --git a/src/controllers/organisms/RoomList.js b/src/controllers/organisms/RoomList.js index 91c384a02b..bc58ed7968 100644 --- a/src/controllers/organisms/RoomList.js +++ b/src/controllers/organisms/RoomList.js @@ -21,9 +21,12 @@ var MatrixClientPeg = require("../../MatrixClientPeg"); var RoomListSorter = require("../../RoomListSorter"); var ComponentBroker = require('../../ComponentBroker'); +var ConferenceHandler = require("../../ConferenceHandler"); var RoomTile = ComponentBroker.get("molecules/RoomTile"); +var HIDE_CONFERENCE_CHANS = true; + module.exports = { componentWillMount: function() { var cli = MatrixClientPeg.get(); @@ -97,7 +100,24 @@ module.exports = { return RoomListSorter.mostRecentActivityFirst( MatrixClientPeg.get().getRooms().filter(function(room) { var member = room.getMember(MatrixClientPeg.get().credentials.userId); - return member && (member.membership == "join" || member.membership == "invite"); + var shouldShowRoom = ( + member && (member.membership == "join" || member.membership == "invite") + ); + // hiding conf rooms only ever toggles shouldShowRoom to false + if (shouldShowRoom && HIDE_CONFERENCE_CHANS) { + // we want to hide the 1:1 conf<->user room and not the group chat + var joinedMembers = room.getJoinedMembers(); + if (joinedMembers.length === 2) { + var otherMember = joinedMembers.filter(function(m) { + return m.userId !== member.userId + })[0]; + if (ConferenceHandler.isConferenceUser(otherMember)) { + console.log("Hiding conference 1:1 room %s", room.roomId); + shouldShowRoom = false; + } + } + } + return shouldShowRoom; }) ); },