Bug 1003105 - TB IM search results show the findbar with incorrect content and don't always highlight a match. r=nhnt11, a=rkent
authoraleth <aleth@instantbird.org>
Mon, 23 Feb 2015 20:03:50 +0100
changeset 25758 a62603c7746927f8525fa7f069d19e8f8ef21813
parent 25757 4880a53c711bf4a0707ddbe109844f7bfd933783
child 25759 37d096d3bf18b87adc55253baca2e59a45e4e018
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnhnt11, rkent
bugs1003105
Bug 1003105 - TB IM search results show the findbar with incorrect content and don't always highlight a match. r=nhnt11, a=rkent
chat/content/convbrowser.xml
mail/components/im/content/chat-messenger-overlay.js
--- a/chat/content/convbrowser.xml
+++ b/chat/content/convbrowser.xml
@@ -421,37 +421,38 @@
               if (!msg)
                 break;
               this.displayMessage(msg.msg, msg.context,
                                   ++this._pendingMessagesDisplayed < max,
                                   msg.firstUnread);
             }
             let event = document.createEvent("UIEvents");
             event.initUIEvent("MessagesDisplayed", false, false, window, 0);
-            this.dispatchEvent(event);
             if (this._pendingMessagesDisplayed < max) {
               if (this.progressBar) {
                 // Show progress bar if after the third call (ca. 120ms)
                 // less than half the messages have been displayed.
                 if (++this._displayPendingMessagesCalls > 2 &&
                     max > 2 * this._pendingMessagesDisplayed)
                   this.progressBar.hidden = false;
                 this.progressBar.max = max;
                 this.progressBar.value = this._pendingMessagesDisplayed;
               }
               Services.tm.mainThread.dispatch(this.displayPendingMessages.bind(this),
                                               Ci.nsIEventTarget.DISPATCH_NORMAL);
+              this.dispatchEvent(event);
               return;
             }
             this.contentWindow.messageInsertPending = false;
             this._messageDisplayPending = false;
             this._pendingMessagesDisplayed = 0;
             this._displayPendingMessagesCalls = 0;
             if (this.progressBar)
               this.progressBar.hidden = true;
+            this.dispatchEvent(event);
           ]]>
         </body>
       </method>
 
       <!-- This is reset in onStateChange. -->
       <field name="_sessions">[]</field>
       <method name="displayMessage">
         <parameter name="aMsg"/>
--- a/mail/components/im/content/chat-messenger-overlay.js
+++ b/mail/components/im/content/chat-messenger-overlay.js
@@ -399,16 +399,19 @@ var chatHandler = {
       browser._conv = aConversation;
       return;
     }
     browser.init(aConversation);
     this._pendingLogBrowserLoad = true;
     if (aSearchTerm)
       this._pendingSearchTerm = aSearchTerm;
     Services.obs.addObserver(this, "conversation-loaded", false);
+    // Conversation title may not be set yet if this is a search result.
+    let cti = document.getElementById("conv-top-info");
+    cti.setAttribute("displayName", aConversation.title);
   },
   _makeFriendlyDate: function(aDate) {
     let dts = Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
                         .getService(Components.interfaces.nsIScriptableDateFormat);
 
     // Figure out when today begins
     let now = new Date();
     let today = new Date(now.getFullYear(), now.getMonth(),
@@ -439,45 +442,52 @@ var chatHandler = {
    * item that needs to be selected.
    * @returns true if there's at least one log in the list, false if empty.
    */
   _showLogList: function(aLogs, aShouldSelect) {
     let logTree = document.getElementById("logTree");
     let treeView = this._treeView = new chatLogTreeView(logTree, aLogs);
     if (!treeView._rowMap.length)
       return false;
-    if (aShouldSelect) {
-      if (aShouldSelect === true) {
-        // Select the first line.
-        let selectIndex = 0;
-        if (treeView.isContainer(selectIndex)) {
-          // If the first line is a group, open it and select the
-          // next line instead.
-          treeView.toggleOpenState(selectIndex++);
-        }
-        logTree.view.selection.select(selectIndex);
+    if (!aShouldSelect)
+      return true;
+    if (aShouldSelect === true) {
+      // Select the first line.
+      let selectIndex = 0;
+      if (treeView.isContainer(selectIndex)) {
+        // If the first line is a group, open it and select the
+        // next line instead.
+        treeView.toggleOpenState(selectIndex++);
       }
-      else {
-        let logTime = aShouldSelect.time;
-        for (let index = 0; index < treeView._rowMap.length; ++index) {
-          if (!treeView._rowMap[index].children.some(function (i) i.log.time == logTime))
-            continue;
-          treeView.toggleOpenState(index);
-          ++index;
-          while (index < treeView._rowMap.length && treeView._rowMap[index].log.time != logTime)
-            ++index;
-          if (treeView._rowMap[index].log.time == logTime) {
-            logTree.view.selection.select(index);
-            logTree.treeBoxObject.ensureRowIsVisible(index);
-          }
-          return true;
-        }
+      logTree.view.selection.select(selectIndex);
+      return true;
+    }
+    // Find the aShouldSelect log and select it.
+    let logTime = aShouldSelect.time;
+    for (let index = 0; index < treeView._rowMap.length; ++index) {
+      if (!treeView.isContainer(index) &&
+          treeView._rowMap[index].log.time == logTime) {
+        logTree.view.selection.select(index);
+        logTree.treeBoxObject.ensureRowIsVisible(index);
+        return true;
       }
+      if (!treeView._rowMap[index].children.some(i => i.log.time == logTime))
+        continue;
+      treeView.toggleOpenState(index);
+      ++index;
+      while (index < treeView._rowMap.length &&
+             treeView._rowMap[index].log.time != logTime)
+        ++index;
+      if (treeView._rowMap[index].log.time == logTime) {
+        logTree.view.selection.select(index);
+        logTree.treeBoxObject.ensureRowIsVisible(index);
+      }
+      return true;
     }
-    return true;
+    throw("Couldn't find the log to select among the set of logs passed.");
   },
 
   onLogSelect: function() {
     let selection = this._treeView.selection;
     let currentIndex = selection.currentIndex;
     // The current (focused) row may not be actually selected...
     if (!selection.isSelected(currentIndex))
       return;
@@ -599,22 +609,19 @@ var chatHandler = {
       cti.removeAttribute("statusTooltiptext");
       cti.removeAttribute("topicEditable");
       cti.removeAttribute("noTopic");
       this.observedContact = null;
 
       let path = "logs/" + item.log.path;
       path = OS.Path.join(OS.Constants.Path.profileDir, ...path.split("/"));
       imServices.logs.getLogFromFile(path, true).then(aLog => {
-        aLog.getConversation().then(aConv => {
-          this._showLog(aConv, item.searchTerm || undefined);
-          cti.setAttribute("displayName", aConv.title);
-          imServices.logs.getSimilarLogs(aLog, true).then(aSimilarLogs => {
-            this._showLogList(aSimilarLogs, aLog);
-          });
+        imServices.logs.getSimilarLogs(aLog, true).then(aSimilarLogs => {
+          this._pendingSearchTerm = item.searchTerm || undefined;
+          this._showLogList(aSimilarLogs, aLog);
         });
       });
     }
     else if (item.localName == "imconv") {
       let convDeck = document.getElementById("conversationsDeck");
       if (!item.convView) {
         // Create new conversation binding.
         let conv = document.createElement("imconversation");
@@ -893,30 +900,30 @@ var chatHandler = {
       for each (let msg in browser._conv.getMessages()) {
         if (!msg.system)
           msg.color = "color: hsl(" + this._computeColor(msg.who) + ", 100%, 40%);";
         browser.appendMessage(msg);
       }
 
       if (this._pendingSearchTerm) {
         let findbar = document.getElementById("log-findbar");
-        let findField = findbar._findField;
-        findField.value = this._pendingSearchTerm;
+        findbar._findField.value = this._pendingSearchTerm;
         findbar.open();
-        findField.focus();
+        browser.focus();
         delete this._pendingSearchTerm;
         let eventListener = function() {
           findbar.onFindAgainCommand();
-          if (findbar._findField.getAttribute("status") != "notfound" ||
-              !browser._messageDisplayPending)
-            browser.removeEventListener("MessagesDisplayed", eventListener);
+          if (findbar._findFailedString && browser._messageDisplayPending)
+            return;
+          // Search result found or all messages added, we're done.
+          browser.removeEventListener("MessagesDisplayed", eventListener);
         };
         browser.addEventListener("MessagesDisplayed", eventListener);
       }
-      delete this._pendingLogBrowserLoad;
+      this._pendingLogBrowserLoad = false;
       Services.obs.removeObserver(this, "conversation-loaded");
       return;
     }
 
     if (aTopic == "account-connected" || aTopic == "account-disconnected" ||
         aTopic == "account-added" || aTopic == "account-removed") {
       this._updateNoConvPlaceHolder();
       return;