Trigger desktop notifications
Notifications show the conversation name, avatar, and new message text. Clicking the notification opens the conversation.
This commit is contained in:
parent
f8e69fa8e7
commit
fa3699cdd3
7 changed files with 115 additions and 4 deletions
|
@ -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();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue