Bug 1669044 - Add MailFolder's subfolders to displayedFolder and selectedFolder. r=darktrojan a=wsmwk
authorJoaquín Serna <bubuanabelas@cryptolab.net>
Tue, 06 Oct 2020 01:06:43 -0300
changeset 40835 53db3388ea2444944cdc50a9212bcbd317ba08a6
parent 40834 a2762c45c863cbb88ccb00b29f55c65f29490aec
child 40836 eb4cc5f09c040b9b0bd7db93f451833934190f60
push id406
push userthunderbird@calypsoblue.org
push dateMon, 19 Oct 2020 19:46:44 +0000
reviewersdarktrojan, wsmwk
bugs1669044
Bug 1669044 - Add MailFolder's subfolders to displayedFolder and selectedFolder. r=darktrojan a=wsmwk Test additions by darktrojan.
mail/components/extensions/parent/.eslintrc.js
mail/components/extensions/parent/ext-accounts.js
mail/components/extensions/parent/ext-mail.js
mail/components/extensions/parent/ext-menus.js
mail/components/extensions/test/browser/browser_ext_menus.js
--- a/mail/components/extensions/parent/.eslintrc.js
+++ b/mail/components/extensions/parent/.eslintrc.js
@@ -36,16 +36,17 @@ module.exports = {
     COMPOSE_WINDOW_URI: true,
     ExtensionError: true,
     Tab: true,
     TabmailTab: true,
     Window: true,
     TabmailWindow: true,
     clickModifiersFromEvent: true,
     convertFolder: true,
+    traverseSubfolders: true,
     convertMailIdentity: true,
     convertMessage: true,
     folderPathToURI: true,
     folderURIToPath: true,
     getTabBrowser: true,
     getTabTabmail: true,
     getTabWindow: true,
     makeWidgetId: true,
--- a/mail/components/extensions/parent/ext-accounts.js
+++ b/mail/components/extensions/parent/ext-accounts.js
@@ -4,41 +4,31 @@
 
 ChromeUtils.defineModuleGetter(
   this,
   "MailServices",
   "resource:///modules/MailServices.jsm"
 );
 ChromeUtils.defineModuleGetter(
   this,
-  "fixIterator",
-  "resource:///modules/iteratorUtils.jsm"
-);
-ChromeUtils.defineModuleGetter(
-  this,
   "toXPCOMArray",
   "resource:///modules/iteratorUtils.jsm"
 );
 
 function convertAccount(account) {
   account = account.QueryInterface(Ci.nsIMsgAccount);
   let server = account.incomingServer;
   if (server.type == "im") {
     return null;
   }
 
-  let traverse = function(folder) {
-    let f = convertFolder(folder, account.key);
-    f.subFolders = [];
-    for (let subFolder of fixIterator(folder.subFolders, Ci.nsIMsgFolder)) {
-      f.subFolders.push(traverse(subFolder));
-    }
-    return f;
-  };
-  let folders = traverse(account.incomingServer.rootFolder).subFolders;
+  let folders = traverseSubfolders(
+    account.incomingServer.rootFolder,
+    account.key
+  ).subFolders;
 
   return {
     id: account.key,
     name: account.incomingServer.prettyName,
     type: account.incomingServer.type,
     folders,
     identities: account.identities.map(id => convertMailIdentity(account, id)),
   };
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -18,16 +18,17 @@ var { defineLazyGetter } = ExtensionComm
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   AppConstants: "resource://gre/modules/AppConstants.jsm",
   ExtensionPageChild: "resource://gre/modules/ExtensionPageChild.jsm",
   ExtensionProcessScript: "resource://gre/modules/ExtensionProcessScript.jsm",
   ExtensionContent: "resource://gre/modules/ExtensionContent.jsm",
   MailServices: "resource:///modules/MailServices.jsm",
   Schemas: "resource://gre/modules/Schemas.jsm",
+  fixIterator: "resource:///modules/iteratorUtils.jsm",
 });
 
 XPCOMUtils.defineLazyPreferenceGetter(
   this,
   "gJunkThreshold",
   "mail.adaptivefilters.junk_threshold",
   90
 );
@@ -1529,16 +1530,29 @@ function convertFolder(folder, accountId
     if (folder.flags & flag) {
       folderObject.type = typeName;
     }
   }
 
   return folderObject;
 }
 
+/**
+ * Traverses a nsIMsgFolder to get all subfolders.
+ * @return {Array}
+ */
+function traverseSubfolders(folder) {
+  let f = convertFolder(folder);
+  f.subFolders = [];
+  for (let subFolder of fixIterator(folder.subFolders, Ci.nsIMsgFolder)) {
+    f.subFolders.push(traverseSubfolders(subFolder));
+  }
+  return f;
+}
+
 class FolderManager {
   constructor(extension) {
     this.extension = extension;
   }
 
   convert(folder, accountId) {
     return convertFolder(folder, accountId);
   }
--- a/mail/components/extensions/parent/ext-menus.js
+++ b/mail/components/extensions/parent/ext-menus.js
@@ -670,17 +670,17 @@ function addMenuEventInfo(info, contextD
   if (contextData.selectedMessages && extension.hasPermission("messagesRead")) {
     info.selectedMessages = messageListTracker.startList(
       contextData.selectedMessages,
       extension
     );
   }
   for (let folderType of ["displayedFolder", "selectedFolder"]) {
     if (contextData[folderType] && extension.hasPermission("accountsRead")) {
-      info[folderType] = convertFolder(contextData[folderType]);
+      info[folderType] = traverseSubfolders(contextData[folderType]);
     }
   }
 }
 
 function MenuItem(extension, createProperties, isRoot = false) {
   this.extension = extension;
   this.children = [];
   this.parent = null;
--- a/mail/components/extensions/test/browser/browser_ext_menus.js
+++ b/mail/components/extensions/test/browser/browser_ext_menus.js
@@ -106,16 +106,17 @@ add_task(async function test_folder_pane
 
   let [info] = await checkShownEvent(
     extension,
     ["folder_pane"],
     ["folder_pane", "all"]
   );
   is(info.selectedFolder.accountId, gAccount.key);
   is(info.selectedFolder.path, "/Trash");
+  ok(Array.isArray(info.selectedFolder.subFolders));
   ok(!info.displayedFolder);
   ok(!info.selectedMessages);
 
   await extension.unload();
 });
 
 add_task(async function test_thread_pane() {
   let extension = createExtension();
@@ -132,17 +133,19 @@ add_task(async function test_thread_pane
 
   let [info] = await checkShownEvent(
     extension,
     ["message_list"],
     ["message_list", "all"]
   );
   is(info.displayedFolder.accountId, gAccount.key);
   is(info.displayedFolder.path, "/Trash");
-  is(info.selectedMessages.cursor, undefined);
+  ok(Array.isArray(info.displayedFolder.subFolders));
+  is(info.selectedMessages.id, null);
+  is(info.selectedMessages.messages.length, 1);
   ok(!info.selectedFolder);
 
   await extension.unload();
 });
 
 add_task(async function test_tab() {
   async function checkTabEvent(index, active, mailTab) {
     EventUtils.synthesizeMouseAtCenter(