Hide 1:1 conference rooms

This commit is contained in:
Kegan Dougal 2015-09-11 16:55:48 +01:00
parent e3b02a295c
commit fc892b3580
3 changed files with 49 additions and 11 deletions

View file

@ -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;