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

View File

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