Show a desktop notification when a contact request is received
updates #443
This commit is contained in:
parent
0aa0c02124
commit
d92645c8d3
|
@ -659,8 +659,13 @@ show_desktop_notifications
|
||||||
|
|
||||||
* Default: ``true``
|
* Default: ``true``
|
||||||
|
|
||||||
Should HTML5 desktop notifications be shown when the browser is not visible or
|
Should HTML5 desktop notifications be shown?
|
||||||
not focused?
|
|
||||||
|
Notification will be shown in the following cases:
|
||||||
|
|
||||||
|
* the browser is not visible nor focused and a private message is received.
|
||||||
|
* the browser is not visible nor focused and a groupchat message is received which mentions you.
|
||||||
|
* `auto_subscribe` is set to `false` and a new contact request is received.
|
||||||
|
|
||||||
Requires the `src/converse-notification.js` plugin.
|
Requires the `src/converse-notification.js` plugin.
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
}).c('body').t(message).up()
|
}).c('body').t(message).up()
|
||||||
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
||||||
converse.chatboxes.onMessage(msg); // This will emit 'message'
|
converse.chatboxes.onMessage(msg); // This will emit 'message'
|
||||||
|
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
|
||||||
expect(converse.showMessageNotification).toHaveBeenCalled();
|
expect(converse.showMessageNotification).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@
|
||||||
spyOn(converse, 'showChatStateNotification');
|
spyOn(converse, 'showChatStateNotification');
|
||||||
var jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
var jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
||||||
converse.roster.get(jid).set('chat_status', 'busy'); // This will emit 'contactStatusChanged'
|
converse.roster.get(jid).set('chat_status', 'busy'); // This will emit 'contactStatusChanged'
|
||||||
|
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
|
||||||
expect(converse.showChatStateNotification).toHaveBeenCalled();
|
expect(converse.showChatStateNotification).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -57,7 +59,11 @@
|
||||||
|
|
||||||
describe("When a new contact request is received", function () {
|
describe("When a new contact request is received", function () {
|
||||||
it("an HTML5 Notification is received", function () {
|
it("an HTML5 Notification is received", function () {
|
||||||
// TODO
|
spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
|
||||||
|
spyOn(converse, 'showContactRequestNotification');
|
||||||
|
converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'});
|
||||||
|
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
|
||||||
|
expect(converse.showContactRequestNotification).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -105,11 +105,15 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
converse.areDesktopNotificationsEnabled = function () {
|
converse.areDesktopNotificationsEnabled = function (ignore_blur) {
|
||||||
return (supports_html5_notification &&
|
var enabled = supports_html5_notification &&
|
||||||
converse.show_desktop_notifications &&
|
converse.show_desktop_notifications &&
|
||||||
converse.windowState === 'blur' &&
|
Notification.permission === "granted";
|
||||||
Notification.permission === "granted");
|
if (ignore_blur) {
|
||||||
|
return enabled;
|
||||||
|
} else {
|
||||||
|
return enabled && converse.windowState === 'blur';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
converse.showMessageNotification = function ($message) {
|
converse.showMessageNotification = function ($message) {
|
||||||
|
@ -152,6 +156,15 @@
|
||||||
setTimeout(n.close.bind(n), 5000);
|
setTimeout(n.close.bind(n), 5000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
converse.showContactRequestNotification = function (contact) {
|
||||||
|
var n = new Notification(contact.fullname, {
|
||||||
|
body: __('is requesting to be your contact'),
|
||||||
|
lang: converse.i18n.locale_data.converse[""].lang,
|
||||||
|
icon: 'logo/conversejs.png'
|
||||||
|
});
|
||||||
|
setTimeout(n.close.bind(n), 5000);
|
||||||
|
};
|
||||||
|
|
||||||
converse.handleChatStateNotification = function (evt, contact) {
|
converse.handleChatStateNotification = function (evt, contact) {
|
||||||
/* Event handler for on('contactStatusChanged').
|
/* Event handler for on('contactStatusChanged').
|
||||||
* Will show an HTML5 notification to indicate that the chat
|
* Will show an HTML5 notification to indicate that the chat
|
||||||
|
@ -176,6 +189,13 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
converse.handleContactRequestNotification = function (evt, contact) {
|
||||||
|
if (converse.areDesktopNotificationsEnabled(true)) {
|
||||||
|
converse.showContactRequestNotification(contact);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
converse.on('contactRequest', converse.handleContactRequestNotification);
|
||||||
converse.on('contactStatusChanged', converse.handleChatStateNotification);
|
converse.on('contactStatusChanged', converse.handleChatStateNotification);
|
||||||
converse.on('message', converse.handleMessageNotification);
|
converse.on('message', converse.handleMessageNotification);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user