diff --git a/clientapp/models/message.js b/clientapp/models/message.js index 8124fca..57261ea 100644 --- a/clientapp/models/message.js +++ b/clientapp/models/message.js @@ -91,13 +91,18 @@ module.exports = HumanModel.define({ } }, processedBody: { - deps: ['body', 'meAction'], + deps: ['body', 'meAction', 'mentions'], fn: function () { var body = this.body; if (this.meAction) { body = body.substr(4); } - return htmlify.toHTML(body); + body = htmlify.toHTML(body); + if (this.mentions) { + var existing = htmlify.toHTML(this.mentions); + body = body.replace(existing, '' + existing + ''); + } + return body; } }, partialTemplateHtml: { @@ -146,7 +151,8 @@ module.exports = HumanModel.define({ _mucMine: 'bool', receiptReceived: ['bool', true, false], edited: ['bool', true, false], - delay: 'object' + delay: 'object', + mentions: ['string', false, ''] }, correct: function (msg) { if (this.from.full !== msg.from.full) return false; diff --git a/clientapp/models/muc.js b/clientapp/models/muc.js index d2a2ec5..9c91939 100644 --- a/clientapp/models/muc.js +++ b/clientapp/models/muc.js @@ -61,22 +61,33 @@ module.exports = HumanModel.define({ addMessage: function (message, notify) { message.owner = me.jid.bare; - if (notify && (!this.activeContact || (this.activeContact && !app.state.focused)) && message.from.resource !== this.nick) { + var mine = message.from.resource === this.nick; + + if (mine) { + message._mucMine = true; + } + if (!mine && message.body.toLowerCase().indexOf(this.nick.toLowerCase()) >= 0) { + message.mentions = this.nick; + } + + if (notify && (!this.activeContact || (this.activeContact && !app.state.focused)) && !mine) { this.unreadCount++; - app.notifications.create(this.displayName, { - body: message.body, - icon: this.avatar, - tag: this.id, - onclick: _.bind(app.navigate, app, '/groupchat/' + this.jid) - }); + if (message.mentions) { + app.notifications.create(this.displayName, { + body: message.body, + icon: this.avatar, + tag: this.id, + onclick: _.bind(app.navigate, app, '/groupchat/' + this.jid) + }); + } } message.acked = true; this.messages.add(message); - if (message.from.resource === this.nick) { - message = this.messages.get(message.id); // Grab the existing message object that was updated - message._mucMine = true; + if (mine) { + // Grab and save the existing message object that was updated + message = this.messages.get(message.id); this.lastSentMessage = message; } diff --git a/clientapp/pages/chat.js b/clientapp/pages/chat.js index 18d4005..40bba31 100644 --- a/clientapp/pages/chat.js +++ b/clientapp/pages/chat.js @@ -20,7 +20,6 @@ module.exports = BasePage.extend(chatHelpers).extend({ this.listenTo(this, 'pageunloaded', this.handlePageUnloaded); this.listenTo(this.model.messages, 'change:body', this.refreshModel); - this.listenTo(this.model.messages, 'change:meAction', this.refreshModel); this.listenTo(this.model.messages, 'change:edited', this.refreshModel); this.listenTo(this.model.messages, 'change:pending', this.refreshModel); diff --git a/clientapp/pages/groupchat.js b/clientapp/pages/groupchat.js index 8377998..aa7bc3a 100644 --- a/clientapp/pages/groupchat.js +++ b/clientapp/pages/groupchat.js @@ -20,7 +20,6 @@ module.exports = BasePage.extend(chatHelpers).extend({ this.listenTo(this.model.messages, 'change:body', this.refreshModel); this.listenTo(this.model.messages, 'change:edited', this.refreshModel); this.listenTo(this.model.messages, 'change:pending', this.refreshModel); - this.listenTo(this.model.messages, 'change:mine', this.refreshModel); this.render(); }, @@ -33,9 +32,6 @@ module.exports = BasePage.extend(chatHelpers).extend({ classBindings: { joined: '.controls' }, - srcBindings: { - avatar: 'header .avatar' - }, textBindings: { displayName: 'header .name' }, diff --git a/clientapp/templates.js b/clientapp/templates.js index cb0f784..91aca71 100644 --- a/clientapp/templates.js +++ b/clientapp/templates.js @@ -120,12 +120,7 @@ exports.includes.mucBareMessage = function anonymous(locals) { exports.includes.mucListItem = function anonymous(locals) { var buf = []; with (locals || {}) { - buf.push('