mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 13:14:58 +08:00
Hide 1:1 conference rooms
This commit is contained in:
parent
e3b02a295c
commit
fc892b3580
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
})
|
||||
);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user