diff --git a/lib/gitter-adapter.js b/lib/gitter-adapter.js index 4c79e4b..c48cc1f 100644 --- a/lib/gitter-adapter.js +++ b/lib/gitter-adapter.js @@ -148,6 +148,10 @@ Adapter.prototype.sendMessage = function(target, message) { var uri = target.replace('#',''); var isStatus = /^\u0001ACTION/.test(message); + var regResult = /^((\w+)[:,]\s*).+/.exec(message); + var mention = undefined; + var mentioned = undefined; + // This are /me IRC messages. if (isStatus) { message = message @@ -155,8 +159,23 @@ Adapter.prototype.sendMessage = function(target, message) { .replace(/\u0001$/, ''); } + if (regResult !== undefined) { + var mention = regResult[1]; + var mentioned = regResult[2]; + } + this.gitterClient.rooms.join(uri) .then(function(room) { + return [room, (room.oneToOne ? [] : room.users())]; + }) + .spread(function (room, users) { + users.forEach(function (userFound) { + if(user.username.toLowerCase() === mentioned.toLowerCase()) { + // Mentioned user is in room. + message = message.replace(mention, "@" + mentioned + " "); + } + }); + return isStatus ? room.sendStatus(message) : room.send(message); }) .catch(function(err){