From 718f1a5e3d5ad6676b4e54e7e9903d4bcce0daec Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 19 Mar 2015 16:17:26 -0700 Subject: [PATCH] Improve notification contents Include sensible descriptions of non-content messages. For group messages, display the sender's name and avatar rather than the group's. --- js/models/messages.js | 10 ++++++++++ js/panel_controller.js | 17 ++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/js/models/messages.js b/js/models/messages.js index b02212eb..1d76cf36 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -43,6 +43,16 @@ isIncoming: function() { return this.get('type') === 'incoming'; }, + getDescription: function() { + if (this.isGroupUpdate()) { + return 'Updated the group'; + } + if (this.isEndSession()) { + return 'Secure session ended'; + } + + return this.get('body'); + }, getContact: function() { if (this.collection) { return this.collection.conversation.contactCollection.get(this.get('source')); diff --git a/js/panel_controller.js b/js/panel_controller.js index 2b732eb1..0747db6a 100644 --- a/js/panel_controller.js +++ b/js/panel_controller.js @@ -50,15 +50,18 @@ window.notifyConversation = function(message) { if (Whisper.Notifications.isEnabled()) { var conversation = getConversation({id: message.get('conversationId')}); + var sender = getConversation({id: message.get('source')}); conversation.fetch().then(function() { - var notification = new Notification(conversation.getTitle(), { - body: message.get('body'), - icon: conversation.getAvatarUrl(), - tag: conversation.id + sender.fetch().then(function() { + var notification = new Notification(sender.getTitle(), { + body: message.getDescription(), + icon: sender.getAvatarUrl(), + tag: conversation.id + }); + notification.onclick = function() { + openConversation(conversation.id); + }; }); - notification.onclick = function() { - openConversation(conversation.id); - }; }); conversation.fetchMessages(); } else {