Bug 1508052 - deduplicate code in nsMsgDatabase::SetKeyFlag(). r=jorgk
authoraceman <acelists@atlas.sk>
Sat, 17 Nov 2018 13:52:00 +0100
changeset 33728 ffda4a36eba4288f242646b7ebc89a0dcf96019e
parent 33727 8cf3f95e48e8b97a754cd22446ef6231e65791d3
child 33729 c680423af71f9cc93a50876c0218967b85a8995b
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersjorgk
bugs1508052
Bug 1508052 - deduplicate code in nsMsgDatabase::SetKeyFlag(). r=jorgk
mailnews/db/msgdb/public/nsMsgDatabase.h
mailnews/db/msgdb/src/nsMsgDatabase.cpp
--- a/mailnews/db/msgdb/public/nsMsgDatabase.h
+++ b/mailnews/db/msgdb/public/nsMsgDatabase.h
@@ -268,24 +268,24 @@ protected:
   static PRTime gLastUseTime; // global last use time
   PRTime m_lastUseTime;       // last use time for this db
   // inline to make instrumentation as cheap as possible
   inline void RememberLastUseTime() {gLastUseTime = m_lastUseTime = PR_Now();}
 
   bool    MatchDbName(nsIFile *dbName);  // returns TRUE if they match
 
   // Flag handling routines
-  virtual nsresult SetKeyFlag(nsMsgKey key, bool set, uint32_t flag,
-                              nsIDBChangeListener *instigator = NULL);
-  virtual nsresult SetMsgHdrFlag(nsIMsgDBHdr *msgHdr, bool set, uint32_t flag,
+  virtual nsresult SetKeyFlag(nsMsgKey key, bool set, nsMsgMessageFlagType flag,
+                              nsIDBChangeListener *instigator = nullptr);
+  virtual nsresult SetMsgHdrFlag(nsIMsgDBHdr *msgHdr, bool set, nsMsgMessageFlagType flag,
                                  nsIDBChangeListener *instigator);
 
   virtual bool    SetHdrFlag(nsIMsgDBHdr *, bool bSet, nsMsgMessageFlagType flag);
   virtual bool    SetHdrReadFlag(nsIMsgDBHdr *, bool pRead);
-  virtual uint32_t GetStatusFlags(nsIMsgDBHdr *msgHdr, uint32_t origFlags);
+  virtual uint32_t GetStatusFlags(nsIMsgDBHdr *msgHdr, nsMsgMessageFlagType origFlags);
   // helper function which doesn't involve thread object
 
   virtual nsresult RemoveHeaderFromDB(nsMsgHdr *msgHdr);
   virtual nsresult RemoveHeaderFromThread(nsMsgHdr *msgHdr);
   virtual nsresult AdjustExpungedBytesOnDelete(nsIMsgDBHdr *msgHdr);
 
   nsCOMPtr <nsICollation> m_collationKeyGenerator;
   nsCOMPtr <nsIMimeConverter> m_mimeConverter;
--- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp
+++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp
@@ -2069,17 +2069,17 @@ nsresult nsMsgDatabase::IsRead(nsMsgKey 
 
   nsresult rv = GetMsgHdrForKey(key, getter_AddRefs(msgHdr));
   if (NS_FAILED(rv) || !msgHdr)
     return NS_MSG_MESSAGE_NOT_FOUND; // XXX return rv?
   rv = IsHeaderRead(msgHdr, pRead);
   return rv;
 }
 
-uint32_t  nsMsgDatabase::GetStatusFlags(nsIMsgDBHdr *msgHdr, uint32_t origFlags)
+uint32_t nsMsgDatabase::GetStatusFlags(nsIMsgDBHdr *msgHdr, nsMsgMessageFlagType origFlags)
 {
   uint32_t  statusFlags = origFlags;
   bool    isRead = true;
 
   nsMsgKey key;
   (void)msgHdr->GetMessageKey(&key);
   if ((!m_newSet.IsEmpty() && m_newSet[m_newSet.Length() - 1] == key) ||
       (m_newSet.BinaryIndexOf(key) != m_newSet.NoIndex))
@@ -2547,53 +2547,42 @@ nsresult nsMsgDatabase::IsMDNSent(nsMsgK
 
   uint32_t flags;
   (void)msgHdr->GetFlags(&flags);
   *pSent = !!(flags & nsMsgMessageFlags::MDNReportSent);
   return rv;
 }
 
 
-nsresult  nsMsgDatabase::SetKeyFlag(nsMsgKey key, bool set, uint32_t flag,
-                                     nsIDBChangeListener *instigator)
+nsresult nsMsgDatabase::SetKeyFlag(nsMsgKey key, bool set, nsMsgMessageFlagType flag,
+                                   nsIDBChangeListener *instigator)
 {
   nsresult rv;
   nsCOMPtr <nsIMsgDBHdr> msgHdr;
 
   rv = GetMsgHdrForKey(key, getter_AddRefs(msgHdr));
   if (NS_FAILED(rv) || !msgHdr)
     return NS_MSG_MESSAGE_NOT_FOUND; // XXX return rv?
 
+  return SetMsgHdrFlag(msgHdr, set, flag, instigator);
+}
+
+nsresult nsMsgDatabase::SetMsgHdrFlag(nsIMsgDBHdr *msgHdr, bool set,
+                                      nsMsgMessageFlagType flag,
+                                      nsIDBChangeListener *instigator)
+{
   uint32_t oldFlags;
-  msgHdr->GetFlags(&oldFlags);
-
-  SetHdrFlag(msgHdr, set, flag);
+  (void)msgHdr->GetFlags(&oldFlags);
+
+  if (!SetHdrFlag(msgHdr, set, flag))
+    return NS_OK;
 
   uint32_t flags;
   (void)msgHdr->GetFlags(&flags);
 
-  if (oldFlags == flags)
-    return NS_OK;
-
-  return NotifyHdrChangeAll(msgHdr, oldFlags, flags, instigator);
-}
-
-nsresult nsMsgDatabase::SetMsgHdrFlag(nsIMsgDBHdr *msgHdr, bool set, uint32_t flag, nsIDBChangeListener *instigator)
-{
-  uint32_t oldFlags;
-  msgHdr->GetFlags(&oldFlags);
-
-  SetHdrFlag(msgHdr, set, flag);
-
-  uint32_t flags;
-  (void)msgHdr->GetFlags(&flags);
-
-  if (oldFlags == flags)
-    return NS_OK;
-
   return NotifyHdrChangeAll(msgHdr, oldFlags, flags, instigator);
 }
 
 // Helper routine - lowest level of flag setting - returns true if flags change,
 // false otherwise.
 bool nsMsgDatabase::SetHdrFlag(nsIMsgDBHdr *msgHdr, bool bSet, nsMsgMessageFlagType flag)
 {
   uint32_t statusFlags;