diff --git a/.gitignore b/.gitignore index 8a95538..2788dbb 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,7 @@ package-lock.json # Optional REPL history .node_repl_history + +# sensitive configuration +config +config.json diff --git a/lib/doorman.js b/lib/doorman.js index 1ea960b..576274e 100644 --- a/lib/doorman.js +++ b/lib/doorman.js @@ -106,6 +106,13 @@ Doorman.prototype.enable = function enable (name) { }); }); + service.on('join', async function (join) { + self.emit('join', { + user: [name, 'users', join.user].join('/'), + channel: [name, 'channels', join.channel].join('/') + }); + }); + service.on('message', async function (msg) { let now = Date.now(); let id = [now, msg.actor, msg.target, msg.object].join('/'); @@ -115,8 +122,8 @@ Doorman.prototype.enable = function enable (name) { self.emit('message', { id: full, created: now, - actor: msg.actor, - target: [name, msg.target].join('/'), + actor: [name, 'users', msg.actor].join('/'), + target: [name, 'channels', msg.target].join('/'), object: msg.object, '@data': msg }); @@ -168,6 +175,11 @@ Doorman.prototype.use = function assemble (plugin) { let handler = new Handler(self.config[name]); + handler.on('message', function (message) { + let parts = message.target.split('/'); + self.services[parts[0]].send(parts[2], message.object); + }); + self.plugins[name] = handler; self.plugins[name].trust(self).start(); diff --git a/services/matrix.js b/services/matrix.js index 3851238..21e6538 100644 --- a/services/matrix.js +++ b/services/matrix.js @@ -110,6 +110,11 @@ Matrix.prototype._getChannels = async function getChannels () { room.id = room.roomId; return room; }); + + for (let i in result) { + await this._registerChannel(result[i]); + } + return result; }; @@ -118,6 +123,11 @@ Matrix.prototype._getUsers = async function getUsers () { user.id = user.userId; return user; }); + + for (let i in result) { + await this._registerUser(result[i]); + } + return result; }; @@ -128,7 +138,10 @@ Matrix.prototype._getPresences = async function getPresences () { }; Matrix.prototype._getMembers = async function getMembers(id) { - let room = this.connection.getRoom(id); + let room = await this.connection.getRoom(id); + for (let i in room.currentState.members) { + await this._registerUser(room.currentState.members[i]); + } return Object.keys(room.currentState.members); }; @@ -167,6 +180,14 @@ Matrix.prototype._presence_change = function handlePresence (message) { }); }; +Matrix.prototype._member_joined_channel = function handleJoin (message) { + if (message.event.content.membership !== 'join') return; + this.emit('join', { + user: message.sender.userId, + channel: message.target.roomId + }); +}; + Matrix.prototype.error = function errorHandler (error) { console.error('[MATRIX]', error); };