mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04: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 Modal = require("./Modal");
|
||||||
var ComponentBroker = require('./ComponentBroker');
|
var ComponentBroker = require('./ComponentBroker');
|
||||||
var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog");
|
var ErrorDialog = ComponentBroker.get("organisms/ErrorDialog");
|
||||||
var ConferenceHandler = require("./ConferenceHandler");
|
var ConferenceCall = require("./ConferenceHandler").ConferenceCall;
|
||||||
var Matrix = require("matrix-js-sdk");
|
var Matrix = require("matrix-js-sdk");
|
||||||
var dis = require("./dispatcher");
|
var dis = require("./dispatcher");
|
||||||
|
|
||||||
@ -196,10 +196,10 @@ dis.register(function(payload) {
|
|||||||
}
|
}
|
||||||
else { // > 2
|
else { // > 2
|
||||||
console.log("Place conference call in %s", payload.room_id);
|
console.log("Place conference call in %s", payload.room_id);
|
||||||
var confHandler = new ConferenceHandler(
|
var confCall = new ConferenceCall(
|
||||||
MatrixClientPeg.get(), payload.room_id
|
MatrixClientPeg.get(), payload.room_id
|
||||||
);
|
);
|
||||||
confHandler.setup().done(function(call) {
|
confCall.setup().done(function(call) {
|
||||||
placeCall(call);
|
placeCall(call);
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
console.error("Failed to setup conference call: %s", err);
|
console.error("Failed to setup conference call: %s", err);
|
||||||
|
@ -6,15 +6,15 @@ var Room = Matrix.Room;
|
|||||||
var USER_PREFIX = "fs_";
|
var USER_PREFIX = "fs_";
|
||||||
var DOMAIN = "matrix.org";
|
var DOMAIN = "matrix.org";
|
||||||
|
|
||||||
function ConferenceHandler(matrixClient, groupChatRoomId) {
|
function ConferenceCall(matrixClient, groupChatRoomId) {
|
||||||
this.client = matrixClient;
|
this.client = matrixClient;
|
||||||
this.groupRoomId = groupChatRoomId;
|
this.groupRoomId = groupChatRoomId;
|
||||||
// abuse browserify's core node Buffer support (strip padding ='s)
|
// abuse browserify's core node Buffer support (strip padding ='s)
|
||||||
this.base64RoomId = new Buffer(this.groupRoomId).toString("base64").replace(/=/g, "");
|
var base64RoomId = new Buffer(groupChatRoomId).toString("base64").replace(/=/g, "");
|
||||||
this.confUserId = "@" + USER_PREFIX + this.base64RoomId + ":" + DOMAIN;
|
this.confUserId = "@" + USER_PREFIX + base64RoomId + ":" + DOMAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConferenceHandler.prototype.setup = function() {
|
ConferenceCall.prototype.setup = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return this._joinConferenceUser().then(function() {
|
return this._joinConferenceUser().then(function() {
|
||||||
return self._getConferenceUserRoom();
|
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
|
// Make sure the conference user is in the group chat room
|
||||||
var groupRoom = this.client.getRoom(this.groupRoomId);
|
var groupRoom = this.client.getRoom(this.groupRoomId);
|
||||||
if (!groupRoom) {
|
if (!groupRoom) {
|
||||||
@ -37,7 +37,7 @@ ConferenceHandler.prototype._joinConferenceUser = function() {
|
|||||||
return this.client.invite(this.groupRoomId, this.confUserId);
|
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
|
// Use an existing 1:1 with the conference user; else make one
|
||||||
var rooms = this.client.getRooms();
|
var rooms = this.client.getRooms();
|
||||||
var confRoom = null;
|
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 RoomListSorter = require("../../RoomListSorter");
|
||||||
|
|
||||||
var ComponentBroker = require('../../ComponentBroker');
|
var ComponentBroker = require('../../ComponentBroker');
|
||||||
|
var ConferenceHandler = require("../../ConferenceHandler");
|
||||||
|
|
||||||
var RoomTile = ComponentBroker.get("molecules/RoomTile");
|
var RoomTile = ComponentBroker.get("molecules/RoomTile");
|
||||||
|
|
||||||
|
var HIDE_CONFERENCE_CHANS = true;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
var cli = MatrixClientPeg.get();
|
var cli = MatrixClientPeg.get();
|
||||||
@ -97,7 +100,24 @@ module.exports = {
|
|||||||
return RoomListSorter.mostRecentActivityFirst(
|
return RoomListSorter.mostRecentActivityFirst(
|
||||||
MatrixClientPeg.get().getRooms().filter(function(room) {
|
MatrixClientPeg.get().getRooms().filter(function(room) {
|
||||||
var member = room.getMember(MatrixClientPeg.get().credentials.userId);
|
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