Thunderbird:Threading Cross-folder Saved Searches

From MozillaWiki
Jump to: navigation, search

Currently, you can't thread or group messages in cross-folder saved searches. There are several reasons for this, but the primary reason is that threading is currently done on a per-folder basis, and stored in the database for the folder. The nsMsgDBThreadedView class uses the nsMsgThread object from the database to display the thread tree, with replies indented below their parent.

The nsMsgGroupView class, which does grouping by the current sort column (e.g, date, sender...), has a group object which implements the nsIMsgThread interface, nsMsgGroupThread. This allows a lot of the core view code which works with nsIMsgThreads to "just work". In order to do threading of messages in cross-folder saved searches, I believe we will need to do something similar. My plan is roughly this:

Define an nsMsgXFThread object, which represents all the messages in the saved search that are in the same thread.

nsMsgXFVirtualFolder will have a table of these objects. It will also have a hash table mapping message-id's to thread objects.

For each message in the saved search, we check if its mesage-id or reference id's have an entry in the hash table. If it is, we add the message to the nsMsgXFThread object, after its most immediate ancestor. If not, we create a new nsMsgXFThread object, and add hash table entries that map between its message id and reference ids to the thread object, and add the message to the nsMsgXFThread object.

For subject threading, we could just use the same hash table, since subjects and message-ids shouldn't coincide. If the user has subject threading turned off, we would just not add subjects to the hash table.

There will probably be a bit of code duplication between nsMsgThread and nsMsgXFThread. It's probably hard to share code between the two, since nsMsgThread lives in msgdb, and nsMsgXFThread will live in base.

To do grouping in quick searches and saved searches, my plan is to rearrange the class hierarchy a little bit. nsMsgGroupView will inherit from nsMsgDBView, and nsMsgThreadedDBView will inherit from nsMsgGroupView. Since nsMsgQuickSearch already inherits from nsMsgThreadedDBView, it will inherit from nsMsgGroupView automatically. To do grouping in quick searches, quick searches will need to pay attention to the sort type, and if it's sortByGroup, it will need to directly call the base nsMsgGroupView methods to init the view, and deal with headers getting added, deleted, and changed.

To implement grouping in cross-folder saved searches, I think we just need to make nsMsgXFVirtualFolder inherit from nsMsgGroupView, and override some of the nsMsgGroupView methods to deal with cross-folder groups.

I'd like to do all this without a big rearranging of the view code, but that may not be possible.

See bug 379806