Trigger desktop notifications

Notifications show the conversation name, avatar, and new message text.
Clicking the notification opens the conversation.
This commit is contained in:
lilia 2015-03-17 15:06:21 -07:00
parent f8e69fa8e7
commit fa3699cdd3
7 changed files with 115 additions and 4 deletions

View file

@ -41,9 +41,32 @@
windowMap.remove('windowId', windowId);
}
window.openConversation = function openConversation (modelId) {
function getConversation(modelId) {
var conversation = window.inbox.get(modelId) || {id: modelId};
conversation = conversations.add(conversation);
return conversation;
}
window.notifyConversation = function(message) {
if (Whisper.Notifications.isEnabled()) {
var conversation = getConversation(message.get('conversationId'));
conversation.fetch().then(function() {
var notification = new Notification(conversation.getTitle(), {
body: message.get('body'),
icon: conversation.getAvatarUrl(),
tag: conversation.id
});
notification.onclick = function() {
openConversation(conversation.id);
};
});
} else {
openConversation(message.get('conversationId'));
}
};
window.openConversation = function openConversation (modelId) {
var conversation = getConversation(modelId);
conversation.fetch().then(function() {
conversation.fetchContacts();
});