Notify all users of the room with '@all'

This commit is contained in:
Sebastien Hut 2015-02-01 23:44:09 +01:00
parent 4af8998da9
commit 3edfe3da21
2 changed files with 13 additions and 6 deletions

View File

@ -113,8 +113,8 @@ var Message = module.exports = HumanModel.define({
body = body.substr(4); body = body.substr(4);
} }
body = htmlify.toHTML(body); body = htmlify.toHTML(body);
if (this.mentions) { for (var i = 0; i < this.mentions.length; i++) {
var existing = htmlify.toHTML(this.mentions); var existing = htmlify.toHTML(this.mentions[i]);
var parts = body.split(existing); var parts = body.split(existing);
body = parts.join('<span class="mention">' + existing + '</span>'); body = parts.join('<span class="mention">' + existing + '</span>');
} }
@ -202,7 +202,7 @@ var Message = module.exports = HumanModel.define({
receiptReceived: ['bool', true, false], receiptReceived: ['bool', true, false],
edited: ['bool', true, false], edited: ['bool', true, false],
delay: 'object', delay: 'object',
mentions: ['string', false, ''] mentions: ['array', false, []]
}, },
correct: function (msg) { correct: function (msg) {
if (this.from.full !== msg.from.full) return false; if (this.from.full !== msg.from.full) return false;

View File

@ -85,14 +85,21 @@ module.exports = HumanModel.define({
if (mine) { if (mine) {
message._mucMine = true; message._mucMine = true;
} }
if (!mine && message.body.toLowerCase().indexOf(this.nick.toLowerCase()) >= 0) { else {
message.mentions = this.nick; var mentions = [];
if (message.body.toLowerCase().indexOf('@' + this.nick.toLowerCase()) >= 0) {
mentions.push('@' + this.nick);
}
if (message.body.toLowerCase().indexOf('@all') >= 0) {
mentions.push('@all');
}
message.mentions = mentions;
} }
var localTime = new Date(); var localTime = new Date();
if (Math.round((localTime - message.created) / 1000) < 5 && notify && (!this.activeContact || (this.activeContact && !app.state.focused)) && !mine) { if (Math.round((localTime - message.created) / 1000) < 5 && notify && (!this.activeContact || (this.activeContact && !app.state.focused)) && !mine) {
this.unreadCount++; this.unreadCount++;
if (message.mentions) { if (message.mentions.length) {
app.notifications.create(this.displayName, { app.notifications.create(this.displayName, {
body: message.body, body: message.body,
icon: this.avatar, icon: this.avatar,