[Thunderbird] onselect event for #threadTree element click

Talk about add-ons and extension development.
Post Reply
johnduncan
Posts: 16
Joined: January 8th, 2015, 7:35 pm

[Thunderbird] onselect event for #threadTree element click

Post by johnduncan »

Hello,

I have written an extension (a re-write of the old unix picons newscheck-faces program) that monitors the current state of news/mail accounts and visually cues the user as to how many unread messages they have in each mailbox. Clicking on a mailbox will link the user (into the mailnews window) to whichever folder they click on. I need to update the total unread message count in the XUL label under each image element (picon) when one of two events may occur:
1) a new mail message arrives
2) the user selects a message, marking it as read and thus decreasing the total unread message count for that folder

The first case is working perfectly, but the second (adding a select listener on the mailnews #threadTree) seems to fire before the threadTree updates the total number of unread messages for that folder.

For example, the first time you click on an unread message in a folder, the total count (in my extension) will stay the same. For the next message you click on (marking as read) in the threadTree, the total in my XUL label will be decreased, but it decreases to the previous number of unread messages. This has led me to believe that the event is being fired before the unread message count for that folder is being updated, which doesn't really seem to make any sense to me as my extension is adding an event listener after the built in ThreadPaneSelectionChanged() method.

Here's a code snippet of the relevant portion of my program:

Code: Select all

var w = Components.classes["@mozilla.org/appshell/window-mediator;1"]
    .getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("mail:3pane");
Components.utils.import("resource:///modules/gloda/mimemsg.js");
var newMailListener = {
    msgAdded: function(aMsgHdr) {
	newsCheck();
    }
};

var notificationService =
    Components.classes["@mozilla.org/messenger/msgnotificationservice;1"]
    .getService(Components.interfaces.nsIMsgFolderNotificationService);
notificationService.addListener(newMailListener, notificationService.msgAdded);

// this event is being fired before the folder's unread message count is decreased when clicking on an unread message
w.document.getElementById('threadTree').addEventListener("select", newsCheck, false);
Am I missing something here?

Here's what it looks like in action: Image

Notice the discrepancy between the value (for m.s.se[amonkey]) of 117 and 116 between my custom XUL window and the #folderTree. This persists each time you read an unread message, as the eventListener is not being fired after the unread count for that folder is being updated; it is being fired before that count is updated.
morat
Posts: 6404
Joined: February 3rd, 2009, 6:29 pm

Re: [Thunderbird] onselect event for #threadTree element cli

Post by morat »

Can you use a folder listener to update the total unread messages count?

Code: Select all

var folderListener = {
  OnItemIntPropertyChanged: function(aItem, aProperty, aOldValue, aNewValue) {
    if (aProperty.toString() == "TotalMessages" ||
        aProperty.toString() == "TotalUnreadMessages") {
      Application.console.log("Total unread messages count changed.");
    }
  },
};
var notifyFlags = Components.interfaces.nsIFolderListener.intPropertyChanged;
MailServices.mailSession.AddFolderListener(folderListener, notifyFlags);
Reference
http://dxr.mozilla.org/comm-release/sou ... stener.idl
http://dxr.mozilla.org/comm-release/sou ... ession.idl
johnduncan
Posts: 16
Joined: January 8th, 2015, 7:35 pm

Re: [Thunderbird] onselect event for #threadTree element cli

Post by johnduncan »

This worked perfectly!! Thanks!

Code: Select all

Components.utils.import("resource:///modules/mailServices.js", this);
I just needed to add the above code snippet to the beginning of the snippet that you provided to get it working in my XUL window.
morat
Posts: 6404
Joined: February 3rd, 2009, 6:29 pm

Re: [Thunderbird] onselect event for #threadTree element cli

Post by morat »

You're welcome.
Post Reply