fix bug 600140, unread quick filter hides some messages, r=bienvenu,a=Standard8
authorOpera Wang <opera.wang@gmail.com>
Fri, 01 Jul 2011 07:57:52 -0700
changeset 7875 f1d1a1749b12f127cb7016ae77c5fe3dbda348c7
parent 7874 59df0ed227cc8a00e16a152cd445aab7b0b72518
child 7876 2fc9664a3b7a749cdfc3dc25b78645aae7711979
push id45
push userbugzilla@standard8.plus.com
push dateTue, 05 Jul 2011 09:54:34 +0000
treeherdercomm-aurora@bea702dd0426 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu, Standard8
bugs600140
fix bug 600140, unread quick filter hides some messages, r=bienvenu,a=Standard8
mailnews/base/src/nsMsgQuickSearchDBView.cpp
mailnews/base/src/nsMsgThreadedDBView.cpp
mailnews/base/test/unit/test_nsMsgDBView.js
--- a/mailnews/base/src/nsMsgQuickSearchDBView.cpp
+++ b/mailnews/base/src/nsMsgQuickSearchDBView.cpp
@@ -448,20 +448,26 @@ nsMsgQuickSearchDBView::OnNewSearch()
   return NS_OK;
 }
 
 nsresult nsMsgQuickSearchDBView::GetFirstMessageHdrToDisplayInThread(nsIMsgThread *threadHdr, nsIMsgDBHdr **result)
 {
   PRUint32 numChildren;
   nsresult rv = NS_OK;
   PRUint8 minLevel = 0xff;
+  threadHdr->GetNumChildren(&numChildren);
   nsMsgKey threadRootKey;
+  nsCOMPtr<nsIMsgDBHdr> rootParent;
+  PRInt32 rootIndex;
+  threadHdr->GetRootHdr(&rootIndex, getter_AddRefs(rootParent));
+  if (rootParent)
+    rootParent->GetMessageKey(&threadRootKey);
+  else
+    threadHdr->GetThreadKey(&threadRootKey);
 
-  threadHdr->GetNumChildren(&numChildren);
-  threadHdr->GetThreadKey(&threadRootKey);
   if ((PRInt32) numChildren < 0)
     numChildren = 0;
 
   nsCOMPtr <nsIMsgDBHdr> retHdr;
 
   // iterate over thread, finding mgsHdr in view with the lowest level.
   for (PRUint32 childIndex = 0; childIndex < numChildren; childIndex++)
   {
--- a/mailnews/base/src/nsMsgThreadedDBView.cpp
+++ b/mailnews/base/src/nsMsgThreadedDBView.cpp
@@ -603,17 +603,17 @@ 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 not threaded display 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.
       PRInt32 threadCount;
       PRUint32 threadFlags;
       PRBool moveThread = PR_FALSE;
--- a/mailnews/base/test/unit/test_nsMsgDBView.js
+++ b/mailnews/base/test/unit/test_nsMsgDBView.js
@@ -45,16 +45,21 @@ function setup_globals(aNextFunc) {
   //    2
   //     4
   //    3
   let msg1 = gMessageGenerator.makeMessage();
   let msg2 = gMessageGenerator.makeMessage({inReplyTo: msg1});
   let msg3 = gMessageGenerator.makeMessage({inReplyTo: msg1});
   let msg4 = gMessageGenerator.makeMessage({inReplyTo: msg2});
   messages = messages.concat([msg1, msg2, msg3, msg4]);
+
+  // test bug 600140, make a thread that Reply message has smaller MsgKey
+  let msgBiggerKey = gMessageGenerator.makeMessage();
+  let msgSmallerKey = gMessageGenerator.makeMessage({inReplyTo: msgBiggerKey});
+  messages = messages.concat([msgSmallerKey, msgBiggerKey]);
   let msgSet = new SyntheticMessageSet(messages);
 
   gTestFolder = make_empty_folder();
   return add_sets_to_folders(gTestFolder, [msgSet]);
 }
 
 var gCommandUpdater = {
   updateCommandStatus : function()
@@ -261,21 +266,16 @@ function setup_view(aViewType, aViewFlag
   gDBView.addColumnHandler("authorFirstLetterCol",
                            authorFirstLetterCustomColumn);
   // XXX this sets the custom column to use for sorting by the custom column.
   // It has been argued (and is generally accepted) that this should not be
   // so limited.
   gDBView.curCustomColumn = "authorFirstLetterCol";
 
   gTreeView = gDBView.QueryInterface(Components.interfaces.nsITreeView);
-
-  // Bug 574799
-  if (gDBView.numMsgsInView != aTestFolder.getTotalMessages(false))
-    do_throw("numMsgsInView is " + gDBView.numMsgsInView + " but should be " +
-               aTestFolder.getTotalMessages(false) + "\n");
 }
 
 /**
  * Comparison func for built-in types (including strings, so no subtraction.)
  */
 function generalCmp(a, b) {
   if (a < b)
     return -1;
@@ -450,16 +450,37 @@ function test_sort_columns() {
   // Custom
   ensure_view_ordering(SortType.byCustom, SortOrder.ascending,
     function (msgHdr) {
       return authorFirstLetterCustomColumn.getSortStringForRow(msgHdr);
     });
   // Received
 }
 
+function  test_number_of_messages() {
+  // Bug 574799
+  if (gDBView.numMsgsInView != gTestFolder.getTotalMessages(false))
+    do_throw("numMsgsInView is " + gDBView.numMsgsInView + " but should be " +
+               aTestFolder.getTotalMessages(false) + "\n");
+  // Bug 600140
+  // Maybe elided so open it, now only consider the first one
+  if (gDBView.isContainer(0) && !gDBView.isContainerOpen(0))
+    gDBView.toggleOpenState(0);
+  let numMsgInTree = gTreeView.rowCount;
+  if ((gDBView.viewFlags & ViewFlags.kGroupBySort))
+    for (let iViewIndex = 0; iViewIndex < gTreeView.rowCount; iViewIndex++) {
+      let flags = gDBView.getFlagsAt(iViewIndex);
+      if (flags & MSG_VIEW_FLAG_DUMMY)
+        numMsgInTree--;
+    }
+  if (gDBView.numMsgsInView != numMsgInTree)
+    view_throw("message in tree is " + numMsgInTree + " but should be " +
+             gDBView.numMsgsInView + "\n");
+}
+
 function test_msg_added_to_search_view() {
   // if the view is a non-grouped search view, test adding a header to
   // the search results, and verify it gets put at top.
   if (! (gDBView.viewFlags & ViewFlags.kGroupBySort)) {
     gDBView.sort(SortType.byDate, SortOrder.descending);
     let [synMsg, synSet] = make_and_add_message();
     let msgHdr = gTestFolder.msgDatabase.getMsgHdrForMessageID(synMsg.messageId);
     gDBView.QueryInterface(Components.interfaces.nsIMsgSearchNotify)
@@ -511,16 +532,17 @@ function test_expand_collapse() {
     view_throw("collapsing first item should have removed 9 items");
 
   // test that expand/collapse works with killed sub-thread.
   oldRowCount = gDBView.rowCount;
   gTestFolder.msgDatabase.MarkHeaderKilled(thirdChild, true, null);
   gDBView.toggleOpenState(0);
   if (gDBView.rowCount != oldRowCount + 2)
     view_throw("expanding first item should have aded 2 items");
+  gTestFolder.msgDatabase.MarkHeaderKilled(thirdChild, false, null);
   oldRowCount = gDBView.rowCount;
   gDBView.toggleOpenState(0);
   if (gDBView.rowCount != oldRowCount - 2)
     view_throw("collapsing first item should have removed 2 items");
 }
 
 function test_qs_results() {
   // This just tests that bug 505967 hasn't regressed.
@@ -599,17 +621,18 @@ var view_types = [
   ["search", ViewFlags.kThreadedDisplay],
   ["search", ViewFlags.kGroupBySort],
   ["xfvf", ViewFlags.kNone],
    // group does unspeakable things to gTestFolder, so put it last.
   ["group", ViewFlags.kGroupBySort]
 ];
 
 var tests_for_all_views = [
-  test_sort_columns
+  test_sort_columns,
+  test_number_of_messages
 ];
 
 var tests_for_specific_views = {
   group: [
     test_group_dummies_under_mutation_by_date
   ],
   threaded: [
     test_expand_collapse