mkiol / GNotifier

Thunderbird add-on that replaces built-in notifications with the OS native notifications
https://addons.mozilla.org/thunderbird/addon/gnotifier/
GNU General Public License v3.0
165 stars 25 forks source link

[TB] Aggregated notifications -- display first/last message received #163

Closed cofi89 closed 7 years ago

cofi89 commented 7 years ago

Hi @mkiol:

With 1.9.9pre8 and aggregated notification, clicking on "Open" just presents TB window instead of opening the message. It would be better if this was configurable so that either of "Present Window", "Display first or last msg received" can be user set.

Now, I've been messing with Gnotifier & JS latelly, and actually managed to produce a working patch for the functionality mentioned, however I didn't get to expose it to preferences ( "first message received" is the hardcoded default ) and "Present Window" is missing.
All in all, it should really be done by someone who actually knows JS ( unlike me ), thus I'll just drop the diff here in hope it will be somewhat usefull.
Also patch is against 1.9.9pre7 since it would have taken me a while to figure out the changes in pre8!

--- /tmp/lib/thunderbird.js
+++ /home/filip/.thunderbird/tc416zhu.default/extensions/jid1-OoNOA6XBjznvLQ@jetpack/lib/thunderbird.js
@@ -82,11 +82,15 @@
 }

 function showAggregatedNotification() {
   let title = format2(sps.aggregatedEmailTitleFormat);
   let text = formatAggregated(sps.aggregatedEmailTextFormat.replace(/\\n/, "\n"));
+  let last_msg = bufferedMessages[0]
+  let first_msg = bufferedMessages[bufferedMessages.length -1];
+
   //console.log("title: " + title);
   //console.log("text: " + text);
-  showNotification(title, text, null);
+  showNotification(title, text, first_msg, true);
 }

 function showNewEmailNotification(message) {
@@ -95,7 +99,7 @@
   showNotification(title, text, message);
 }

-function showNotification(title, text, message){
+function showNotification (title, text, message, agregated = false){
   var notifications = require("sdk/notifications");

   // Current implementation of click action doesn't support SeaMonkey,
@@ -124,6 +128,11 @@
           label: _("Mark_as_read"),
           handler: ()=>{message.markRead(true);}
         }];
+      } else if (agregated) {
+          actions = [{
+              label: _("open"),
+              handler: ()=>{display(message);}
+            }];
       } else {
         actions = [{
           label: _("Mark_as_read"),

Cheers! :smiley:

mkiol commented 7 years ago

Totally makes sense. Good idea!

cofi89 commented 7 years ago

I forgot:

--- /tmp/thunderbird.js
+++ /home/filip/.thunderbird/tc416zhu.default/extensions/jid1-OoNOA6XBjznvLQ@jetpack/lib/thunderbird.js
@@ -295,6 +295,7 @@
       win.gFolderDisplay.selectMessage(message);
     }

+    bufferedMessages.length = 0
     focusWindow(false);
     return;
   }

This solves another issue causing the aggregated notifications to always show messages from the first batch. Eg, launch TB --> messages arive --> notification shows as:

10 new messages Johney: MSG1 Github Feed: MSG2 ...

Then, new batch arives but instad of showing the actuall new messages like:

3 new messages Mike: MSG1 Jack: MSG2 ...

it shows the summary from the first batch ( though count is correct ).

mkiol commented 7 years ago

Enhancement you requested is in latest (pre) XPI. There is new option "Click action for multiple messages notification" with possible 3 values: "Open first message", "Open last message" and "None".

Thank you for the patch you prepared and your all involvement!

cofi89 commented 7 years ago

Awesome! :+1:
All that's left now is to get the "mouse" people to implement "on notification click" actions in xfce4-notifyd. :smile:
But regardless of that, for me, Gnotifier is now 100% feature complete! Again, thank you for that!
Cheers!