expand collapsed threads when new messages come into open views, r/sr=standard8, 494811
authorDavid Bienvenu <bienvenu@nventure.com>
Tue, 16 Jun 2009 07:10:00 -0700
changeset 2848 0149b4882d78ab355d604166224102583b199dca
parent 2847 907e95be514285e568bb2c56cc1123821a0baa41
child 2849 8a2b5c33ab6f787b69dda4198eee28eeebdc1f33
push idunknown
push userunknown
push dateunknown
bugs494811
expand collapsed threads when new messages come into open views, r/sr=standard8, 494811
mailnews/base/src/nsMsgThreadedDBView.cpp
--- a/mailnews/base/src/nsMsgThreadedDBView.cpp
+++ b/mailnews/base/src/nsMsgThreadedDBView.cpp
@@ -136,21 +136,21 @@ nsresult nsMsgThreadedDBView::InitThread
   m_havePrevView = PR_FALSE;
   nsresult getSortrv = NS_OK; // ### TODO m_db->GetSortInfo(&sortType, &sortOrder);
   
   // list all the ids into m_keys.
   nsMsgKey startMsg = 0; 
   do
   {
     const PRInt32 kIdChunkSize = 400;
-    PRInt32			numListed = 0;
-    nsMsgKey	idArray[kIdChunkSize];
-    PRInt32		flagArray[kIdChunkSize];
-    char		levelArray[kIdChunkSize];
-    
+    PRInt32  numListed = 0;
+    nsMsgKey idArray[kIdChunkSize];
+    PRInt32  flagArray[kIdChunkSize];
+    char     levelArray[kIdChunkSize];
+
     rv = ListThreadIds(&startMsg, (m_viewFlags & nsMsgViewFlagsType::kUnreadOnly) != 0, idArray, flagArray, 
       levelArray, kIdChunkSize, &numListed, nsnull);
     if (NS_SUCCEEDED(rv))
     {
       PRInt32 numAdded = AddKeys(idArray, flagArray, levelArray, m_sortType, numListed);
       if (pCount)
         *pCount += numAdded;
     }
@@ -603,49 +603,49 @@ nsresult nsMsgThreadedDBView::OnNewHeade
     PRUint32 msgFlags;
     newHdr->GetFlags(&msgFlags);
     if ((m_viewFlags & nsMsgViewFlagsType::kUnreadOnly) && !ensureListed && (msgFlags & nsMsgMessageFlags::Read))
       return NS_OK;
     // Currently, we only add the header in a threaded view if it's a thread.
     // We used to check if this was the first header in the thread, but that's
     // a bit harder in the unreadOnly view. But we'll catch it below.
 
-    // for search view we don't support threaded display so just add it to the view.   
-    if (!(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay)) // || msgHdr->GetMessageKey() == m_messageDB->GetKeyOfFirstMsgInThread(msgHdr->GetMessageKey()))
+    // for search view we don't support threaded display so just add it to the view.
+    if (!(m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))
       rv = AddHdr(newHdr);
-    else	// need to find the thread we added this to so we can change the hasnew flag
-      // added message to existing thread, but not to view
-    {	// Fix flags on thread header.
+    else // need to find the thread we added this to so we can change the hasnew flag
+         // added message to existing thread, but not to view
+    {    // Fix flags on thread header.
       PRInt32 threadCount;
       PRUint32 threadFlags;
       PRBool moveThread = PR_FALSE;
       nsMsgViewIndex threadIndex = ThreadIndexOfMsg(newKey, nsMsgViewIndex_None, &threadCount, &threadFlags);
       nsCOMPtr <nsIMsgThread> threadHdr;
       m_db->GetThreadContainingMsgHdr(newHdr, getter_AddRefs(threadHdr));
       if (threadHdr && m_sortType == nsMsgViewSortType::byDate)
       {
         PRUint32 newestMsgInThread = 0, msgDate = 0;
         threadHdr->GetNewestMsgDate(&newestMsgInThread);
         newHdr->GetDateInSeconds(&msgDate);
         moveThread = (msgDate == newestMsgInThread);
       }
       if (threadIndex != nsMsgViewIndex_None)
       {
-        PRUint32	flags = m_flags[threadIndex];
+        PRUint32 flags = m_flags[threadIndex];
         if (!(flags & MSG_VIEW_FLAG_HASCHILDREN))
         {
           flags |= MSG_VIEW_FLAG_HASCHILDREN | MSG_VIEW_FLAG_ISTHREAD;
           if (!(m_viewFlags & nsMsgViewFlagsType::kUnreadOnly))
             flags |= nsMsgMessageFlags::Elided;
           m_flags[threadIndex] = flags;
         }
-        if (!(flags & nsMsgMessageFlags::Elided))	// thread is expanded
-        {								// insert child into thread
+        if (!(flags & nsMsgMessageFlags::Elided)) // thread is expanded
+        {  // insert child into thread
           // levels of other hdrs may have changed!
-          PRUint32	newFlags = msgFlags;
+          PRUint32 newFlags = msgFlags;
           PRInt32 level = 0;
           nsMsgViewIndex insertIndex = threadIndex;
           if (aParentKey == nsMsgKey_None)
           {
             newFlags |= MSG_VIEW_FLAG_ISTHREAD | MSG_VIEW_FLAG_HASCHILDREN;
           }
           else
           {
@@ -659,31 +659,35 @@ nsresult nsMsgThreadedDBView::OnNewHeade
           NoteChange(insertIndex, 1, nsMsgViewNotificationCode::insertOrDelete);
 
           if (aParentKey == nsMsgKey_None)
           {
             // this header is the new king! try collapsing the existing thread,
             // removing it, installing this header as king, and expanding it.
             CollapseByIndex(threadIndex, nsnull);
             // call base class, so child won't get promoted.
-            // nsMsgDBView::RemoveByIndex(threadIndex);	
+            // nsMsgDBView::RemoveByIndex(threadIndex);
             ExpandByIndex(threadIndex, nsnull);
           }
         }
         else if (aParentKey == nsMsgKey_None)
         {
           // if we have a collapsed thread which just got a new
           // top of thread, change the keys array.
           m_keys[threadIndex] = newKey;
         }
         if (moveThread)
           MoveThreadAt(threadIndex);
         else
         // note change, to update the parent thread's unread and total counts
           NoteChange(threadIndex, 1, nsMsgViewNotificationCode::changed);
+        // if this message is new, and the thread is collapsed, expand it.
+        if (msgFlags & nsMsgMessageFlags::New &&
+            m_flags[threadIndex] & nsMsgMessageFlags::Elided)
+          ExpandByIndex(threadIndex, nsnull);
       }
       else // adding msg to thread that's not in view.
       {
         if (threadHdr)
         {
           AddMsgToThreadNotInView(threadHdr, newHdr, ensureListed);
         }
       }