From 79872be9f5418cbb052495a53bf155c57212f66a Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 27 Apr 2017 18:21:52 -0700 Subject: [PATCH] Unfurl notifications Since we no longer have support for list-style notifications, stop coalescing notifications into batches and just show contents of the last message received. Also open the window when clicking on a notification if it has previously been closed. // FREEBIE --- js/background.js | 1 + js/notifications.js | 75 +++++++++++++-------------------------------- 2 files changed, 22 insertions(+), 54 deletions(-) diff --git a/js/background.js b/js/background.js index aede0192dc..331a3f1404 100644 --- a/js/background.js +++ b/js/background.js @@ -98,6 +98,7 @@ }); Whisper.Notifications.on('click', function(conversation) { + showWindow(); if (conversation) { appView.openConversation(conversation); } else { diff --git a/js/notifications.js b/js/notifications.js index f7f16943c1..efd997940e 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -16,7 +16,7 @@ Whisper.Notifications = new (Backbone.Collection.extend({ initialize: function() { - this.on('add', _.debounce(this.update.bind(this), 1000)); + this.on('add', this.update); this.on('remove', this.onRemove); }, onclick: function() { @@ -59,61 +59,28 @@ return; } - if (this.length > 1) { - var conversationIds = _.uniq(this.map(function(m) { - return m.get('conversationId'); - })); - if (conversationIds.length === 1 && this.showSender()) { - iconUrl = this.at(0).get('iconUrl'); + var m = this.last(); + var type = 'basic'; + var message = i18n('newMessage'); + var imageUrl; + if (this.showMessage()) { + message = m.get('message'); + if (m.get('imageUrl')) { + type = 'image'; + imageUrl = m.get('imageUrl'); } - extension.notification.update({ - type : 'list', - iconUrl : iconUrl, - title : title, - message : 'Most recent from ' + this.last().get('title'), - items : this.map(function(m) { - var message, title; - if (this.showMessage()) { - return { - title : m.get('title'), - message : m.get('message') - }; - } else if (this.showSender()) { - return { - title : m.get('title'), - message : i18n('newMessage') - }; - } - }.bind(this)), - buttons : [{ - title : 'Mark all as read', - iconUrl : 'images/check.svg' - }] - }); - } else { - var m = this.at(0); - var type = 'basic'; - var message = i18n('newMessage'); - var imageUrl; - if (this.showMessage()) { - message = m.get('message'); - if (m.get('imageUrl')) { - type = 'image'; - imageUrl = m.get('imageUrl'); - } - } - if (this.showSender()) { - title = m.get('title'); - iconUrl = m.get('iconUrl'); - } - extension.notification.update({ - type : type, - title : title, - message : message, - iconUrl : iconUrl, - imageUrl : imageUrl - }); } + if (this.showSender()) { + title = m.get('title'); + iconUrl = m.get('iconUrl'); + } + extension.notification.update({ + type : type, + title : title, + message : message, + iconUrl : iconUrl, + imageUrl : imageUrl + }); }, getSetting: function() { return storage.get('notification-setting') || 'message';