Commit 14c66ff7 authored by JC Brand's avatar JC Brand

Also show HTML5 notifications for chat state changes.

updates #443
parent 578ca540
...@@ -882,6 +882,7 @@ ...@@ -882,6 +882,7 @@
this.RosterContact = Backbone.Model.extend({ this.RosterContact = Backbone.Model.extend({
initialize: function (attributes, options) { initialize: function (attributes, options) {
var jid = attributes.jid; var jid = attributes.jid;
var bare_jid = Strophe.getBareJidFromJid(jid); var bare_jid = Strophe.getBareJidFromJid(jid);
...@@ -1019,6 +1020,7 @@ ...@@ -1019,6 +1020,7 @@
this.RosterContacts = Backbone.Collection.extend({ this.RosterContacts = Backbone.Collection.extend({
model: converse.RosterContact, model: converse.RosterContact,
comparator: function (contact1, contact2) { comparator: function (contact1, contact2) {
var name1, name2; var name1, name2;
var status1 = contact1.get('chat_status') || 'offline'; var status1 = contact1.get('chat_status') || 'offline';
...@@ -2124,6 +2126,7 @@ ...@@ -2124,6 +2126,7 @@
this.$el.find('div.chat-event').remove(); this.$el.find('div.chat-event').remove();
} }
} }
// FIXME: multiple parameters not accepted?
converse.emit('contactStatusChanged', item.attributes, item.get('chat_status')); converse.emit('contactStatusChanged', item.attributes, item.get('chat_status'));
}, },
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
notifyOfNewMessage: function ($message) { notifyOfNewMessage: function ($message) {
var result = this._super.notifyOfNewMessage.apply(this, arguments); var result = this._super.notifyOfNewMessage.apply(this, arguments);
if (result && (this.windowState === 'blur') && (Notification.permission === "granted")) { if (result && (this.windowState === 'blur') && (Notification.permission === "granted")) {
this.showNotification($message); this.showMessageNotification($message);
} }
return result; return result;
} }
...@@ -51,7 +51,35 @@ ...@@ -51,7 +51,35 @@
*/ */
var converse = this.converse; var converse = this.converse;
converse.showNotification = function ($message) { converse.showChatStateNotification = function (event, contact) {
/* Show an HTML5 notification indicating that a contact changed
* their chat state.
*/
var chat_state = contact.chat_status,
message = null;
if (chat_state === 'offline') {
message = __('has gone offline');
} else if (chat_state === 'away') {
message = __('has gone away');
} else if ((chat_state === 'dnd')) {
message = __('is busy');
} else if (chat_state === 'online') {
message = __('has come online');
}
if (message === null) {
return;
}
var n = new Notification(contact.fullname, {
body: message,
lang: converse.i18n.locale_data.converse[""].lang,
icon: 'logo/conversejs.png'
});
setTimeout(n.close.bind(n), 5000);
};
converse.on('contactStatusChanged', converse.showChatStateNotification);
converse.showMessageNotification = function ($message) {
/* Show an HTML5 notification of a received message. /* Show an HTML5 notification of a received message.
*/ */
var contact_jid = Strophe.getBareJidFromJid($message.attr('from')); var contact_jid = Strophe.getBareJidFromJid($message.attr('from'));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment