Bug 949135 - make number of items in Recent folders list configurable. r=jorgk,ui-r=aleca
authoraceman <acelists@atlas.sk>
Sat, 12 Oct 2019 13:06:00 +0200
changeset 27907 9ec80cfd971196fa362d4dd15e2506af383f8d58
parent 27906 7e9ef7f6158ab14df2c9c439882ff91b0aa2fe47
child 27908 79bcd5d1148477ce4b3c611ebd83205eea186598
push id16549
push usermozilla@jorgk.com
push dateSat, 12 Oct 2019 21:58:00 +0000
treeherdercomm-central@9ec80cfd9711 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk, aleca
bugs949135
Bug 949135 - make number of items in Recent folders list configurable. r=jorgk,ui-r=aleca
mail/base/content/folderPane.js
mailnews/base/content/folder-menupopup.js
mailnews/base/util/folderUtils.jsm
mailnews/mailnews.js
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -1969,22 +1969,20 @@ var gFolderTreeView = {
         return false;
       },
     },
 
     recent_compact: {
       __proto__: IFolderTreeMode,
 
       generateMap(ftv) {
-        const MAXRECENT = 15;
-
-        // Get 15 (MAXRECENT) most recently accessed folders.
+        // Get the most recently accessed folders.
         let recentFolders = getMostRecentFolders(
           ftv._enumerateFolders,
-          MAXRECENT,
+          Services.prefs.getIntPref("mail.folder_widget.max_recent"),
           "MRUTime",
           null
         );
 
         // Sort the folder names alphabetically.
         recentFolders.sort(function(a, b) {
           let aLabel = a.prettyName;
           let bLabel = b.prettyName;
--- a/mailnews/base/content/folder-menupopup.js
+++ b/mailnews/base/content/folder-menupopup.js
@@ -20,16 +20,19 @@
   } = ChromeUtils.import("resource:///modules/folderUtils.jsm");
   const { fixIterator, toArray } = ChromeUtils.import(
     "resource:///modules/iteratorUtils.jsm"
   );
   const { MailServices } = ChromeUtils.import(
     "resource:///modules/MailServices.jsm"
   );
   const { MailUtils } = ChromeUtils.import("resource:///modules/MailUtils.jsm");
+  const { Services } = ChromeUtils.import(
+    "resource://gre/modules/Services.jsm"
+  );
   const { StringBundle } = ChromeUtils.import(
     "resource:///modules/StringBundle.js"
   );
 
   /**
    * Creates an element, sets attributes on it, including always setting the
    * "generated" attribute to "true", and returns the element. The "generated"
    * attribute is used to determine which elements to remove when clearing
@@ -213,19 +216,16 @@
             ) {
               return false;
             }
             // Show parents that might have usable subfolders, or usable folders.
             return folder.hasSubFolders || folder.canFileMessages;
           },
         };
 
-        // The maximum number of entries in the "Recent" menu.
-        this._MAXRECENT = 15;
-
         // Is this list containing only servers (accounts) and no real folders?
         this._serversOnly = true;
 
         /**
          * Our listener to let us know when folders change/appear/disappear so
          * we can know to rebuild ourselves.
          *
          * @implements {nsIFolderListener}
@@ -569,32 +569,32 @@
         if (this._listener._filterFunction) {
           specialFolders = specialFolders.filter(
             this._listener._filterFunction
           );
         }
 
         switch (specialType) {
           case "recent":
-            // Find 15 (_MAXRECENT) of most recently modified ones.
+            // Find the most recently modified ones.
             specialFolders = getMostRecentFolders(
               specialFolders,
-              this._MAXRECENT,
+              Services.prefs.getIntPref("mail.folder_widget.max_recent"),
               "MRMTime"
             );
             break;
           case "favorites":
             specialFolders = specialFolders.filter(folder =>
               folder.getFlag(Ci.nsMsgFolderFlags.Favorite)
             );
             break;
         }
 
         // Cache the pretty names so that they do not need to be fetched
-        // _MAXRECENT^2 times later.
+        // with quadratic complexity when sorting by name.
         let specialFoldersMap = specialFolders.map(folder => {
           return {
             folder,
             name: folder.prettyName,
           };
         });
 
         // Because we're scanning across multiple accounts, we can end up with
--- a/mailnews/base/util/folderUtils.jsm
+++ b/mailnews/base/util/folderUtils.jsm
@@ -183,32 +183,33 @@ function allAccountsSorted(aExcludeIMAcc
  * @param aFolderList       The array of nsIMsgFolders to search for recent folders.
  * @param aMaxHits          How many folders to return.
  * @param aTimeProperty     Which folder time property to use.
  *                          Use "MRMTime" for most recently modified time.
  *                          Use "MRUTime" for most recently used time.
  */
 function getMostRecentFolders(aFolderList, aMaxHits, aTimeProperty) {
   let recentFolders = [];
+  const monthOld = Math.floor((Date.now() - 31 * 24 * 60 * 60 * 1000) / 1000);
 
   /**
    * This sub-function will add a folder to the recentFolders array if it
    * is among the aMaxHits most recent. If we exceed aMaxHits folders,
    * it will pop the oldest folder, ensuring that we end up with the
    * right number.
    *
    * @param aFolder  The folder to check for recency.
    */
   let oldestTime = 0;
   function addIfRecent(aFolder) {
     let time = 0;
     try {
       time = Number(aFolder.getStringProperty(aTimeProperty)) || 0;
     } catch (e) {}
-    if (time <= oldestTime) {
+    if (time <= oldestTime || time < monthOld) {
       return;
     }
 
     if (recentFolders.length == aMaxHits) {
       recentFolders.sort((a, b) => a.time < b.time);
       recentFolders.pop();
       oldestTime = recentFolders[recentFolders.length - 1].time;
     }
--- a/mailnews/mailnews.js
+++ b/mailnews/mailnews.js
@@ -150,16 +150,17 @@ pref("mail.fixed_width_messages",       
 pref("mail.citation_color",                 "#000000"); // quoted color
 pref("mail.strip_sig_on_reply", true); // If true, remove the everything after the "-- \n" signature delimiter when replying.
 pref("mail.quoted_style",                   0); // 0=plain, 1=bold, 2=italic, 3=bolditalic
 pref("mail.quoted_size",                    0); // 0=normal, 1=big, 2=small
 pref("mail.quoted_graphical",               true); // use HTML-style quoting for displaying plain text
 pref("mail.quoteasblock",                   true); // use HTML-style quoting for quoting plain text
 pref("mail.strictly_mime",                  false);
 pref("mail.strictly_mime_headers",          true);
+pref("mail.folder_widget.max_recent",       25); // The maximum number of entries in the "Recent" menu of the folder picker.
 // 0/1 (name param is encoded in a legacy way), 2(RFC 2231 only)
 // 0 the name param is never separated to multiple lines.
 pref("mail.strictly_mime.parm_folding",     1);
 pref("mail.label_ascii_only_mail_as_us_ascii", false);
 pref("mail.file_attach_binary",             false);
 pref("mail.show_headers",                   1); // some
 pref("mailnews.p7m_external", false);          // S/MIME parts are not external (but inline decrypted).
 pref("mailnews.p7m_subparts_external", true);  // S/MIME child parts are external. Protect against efail.