Bug 1562158 - Remove xpidl [array] use from nsIMsgFolder. r=jorgk DONTBUILD
authorBen Campbell <benc@thunderbird.net>
Thu, 17 Oct 2019 11:44:10 +0200
changeset 37173 c5b6c5441abac875155c7d754b4d673612c83838
parent 37172 47dd97e031f9ac387001cda9e97f26aeae3216fb
child 37174 985a460f82026adfed2bf9b8e5bc00234edd5698
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersjorgk
bugs1562158
Bug 1562158 - Remove xpidl [array] use from nsIMsgFolder. r=jorgk DONTBUILD
mailnews/base/public/nsIMsgFolder.idl
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/base/util/nsMsgDBFolder.h
--- a/mailnews/base/public/nsIMsgFolder.idl
+++ b/mailnews/base/public/nsIMsgFolder.idl
@@ -600,23 +600,20 @@ interface nsIMsgFolder : nsISupports {
   boolean isCommandEnabled(in ACString command);
   boolean matchOrChangeFilterDestination(in nsIMsgFolder folder,
                                          in boolean caseInsensitive);
   boolean confirmFolderDeletionForFilter(in nsIMsgWindow msgWindow);
   void alertFilterChanged(in nsIMsgWindow msgWindow);
   void throwAlertMsg(in string msgName, in nsIMsgWindow msgWindow);
   AString getStringWithFolderNameFromBundle(in string msgName);
   void notifyCompactCompleted();
+  /**
+   * Calculate ordering of this folder against another.
+   */
   long compareSortKeys(in nsIMsgFolder msgFolder);
-  /**
-   * Returns a sort key that can be used to sort a list of folders.
-   *
-   * Prefer nsIMsgFolder::compareSortKeys over this function.
-   */
-  void getSortKey(out unsigned long length, [array, size_is(length), retval] out octet key);
 
   attribute nsIMsgRetentionSettings retentionSettings;
   attribute nsIMsgDownloadSettings downloadSettings;
   boolean callFilterPlugins(in nsIMsgWindow aMsgWindow);
   /**
    * used for order in the folder pane, folder pickers, etc.
    */
   attribute long sortOrder;
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -4929,48 +4929,47 @@ NS_IMETHODIMP nsMsgDBFolder::GetSortOrde
   else if (flags & nsMsgFolderFlags::Queue)
     *order = 8;
   else
     *order = 9;
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsMsgDBFolder::GetSortKey(uint32_t *aLength, uint8_t **aKey) {
+// Helper function for CompareSortKeys().
+// Builds a collation key for a given folder based on "{sortOrder}{name}"
+nsresult nsMsgDBFolder::BuildFolderSortKey(nsIMsgFolder *aFolder,
+                                           uint32_t *aLength, uint8_t **aKey) {
   NS_ENSURE_ARG(aKey);
   int32_t order;
-  nsresult rv = GetSortOrder(&order);
+  nsresult rv = aFolder->GetSortOrder(&order);
   NS_ENSURE_SUCCESS(rv, rv);
   nsAutoString orderString;
   orderString.AppendInt(order);
   nsString folderName;
-  rv = GetName(folderName);
+  rv = aFolder->GetName(folderName);
   NS_ENSURE_SUCCESS(rv, rv);
   orderString.Append(folderName);
-  return CreateCollationKey(orderString, aKey, aLength);
-}
-
-nsresult nsMsgDBFolder::CreateCollationKey(const nsString &aSource,
-                                           uint8_t **aKey, uint32_t *aLength) {
   NS_ENSURE_TRUE(gCollationKeyGenerator, NS_ERROR_NULL_POINTER);
   return gCollationKeyGenerator->AllocateRawSortKey(
-      nsICollation::kCollationCaseInSensitive, aSource, aKey, aLength);
+      nsICollation::kCollationCaseInSensitive, orderString, aKey, aLength);
 }
 
 NS_IMETHODIMP nsMsgDBFolder::CompareSortKeys(nsIMsgFolder *aFolder,
                                              int32_t *sortOrder) {
+  // nsICollation interface will likely change to use nsTArray<> at some point.
+  // So this can be simplified then (see Bug 1509981).
   uint8_t *sortKey1 = nullptr;
   uint8_t *sortKey2 = nullptr;
   uint32_t sortKey1Length;
   uint32_t sortKey2Length;
-  nsresult rv = GetSortKey(&sortKey1Length, &sortKey1);
+  nsresult rv = BuildFolderSortKey(this, &sortKey1Length, &sortKey1);
   NS_ENSURE_SUCCESS(rv, rv);
-  aFolder->GetSortKey(&sortKey2Length, &sortKey2);
+  rv = BuildFolderSortKey(aFolder, &sortKey2Length, &sortKey2);
   NS_ENSURE_SUCCESS(rv, rv);
-
   rv = gCollationKeyGenerator->CompareRawSortKey(
       sortKey1, sortKey1Length, sortKey2, sortKey2Length, sortOrder);
   PR_Free(sortKey1);
   PR_Free(sortKey2);
   return rv;
 }
 
 NS_IMETHODIMP nsMsgDBFolder::FetchMsgPreviewText(nsMsgKey *aKeysToFetch,
--- a/mailnews/base/util/nsMsgDBFolder.h
+++ b/mailnews/base/util/nsMsgDBFolder.h
@@ -185,17 +185,18 @@ class NS_MSG_BASE nsMsgDBFolder : public
   void SetMRMTime();
   /**
    * Clear all processing flags, presumably because message keys are no longer
    * valid.
    */
   void ClearProcessingFlags();
 
   nsresult NotifyHdrsNotBeingClassified();
-
+  nsresult BuildFolderSortKey(nsIMsgFolder *aFolder, uint32_t *aLength,
+                              uint8_t **aKey);
   /**
    * Produce an array of messages ordered like the input keys.
    */
   nsresult MessagesInKeyOrder(nsTArray<nsMsgKey> &aKeyArray,
                               nsIMsgFolder *srcFolder,
                               nsIMutableArray *messages);
   nsCString mURI;