Bug 1535119 - avoid updating the title once per message when displaying a conversation with unread messages for the first time, r=clokep.
authorFlorian Quèze <florian@queze.net>
Tue, 03 Dec 2019 15:35:52 -0500
changeset 28314 2cfb1d544ba0442fce04865f94804fd79ddeb30e
parent 28313 792c378e19bcedb1a164a6621d0e734f7236a88d
child 28315 040ffadfe15ffb98f834ef9495a4dbf87b2f413b
push id16765
push userclokep@gmail.com
push dateWed, 04 Dec 2019 17:23:13 +0000
treeherdercomm-central@2cfb1d544ba0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
bugs1535119
Bug 1535119 - avoid updating the title once per message when displaying a conversation with unread messages for the first time, r=clokep.
mail/components/im/content/chat-conversation.js
--- a/mail/components/im/content/chat-conversation.js
+++ b/mail/components/im/content/chat-conversation.js
@@ -58,18 +58,20 @@
             }
 
             Services.obs.removeObserver(this.observer, "conversation-loaded");
             return;
           }
 
           switch (topic) {
             case "new-text":
-              if (this.loaded) {
-                this.addMsg(subject);
+              if (this.loaded && this.addMsg(subject)) {
+                // This will mark the conv as read, but also update the conv title
+                // with the new unread count etc.
+                this.tab.update();
               }
               break;
 
             case "status-text-changed":
               this._statusText = data || "";
               this.displayStatusText();
               break;
 
@@ -338,16 +340,22 @@
       this.loaded = true;
       let messages = this._conv.getMessages();
       this._readCount = messages.length - this._conv.unreadMessageCount;
       if (this._readCount) {
         this._writingContextMessages = true;
       }
       messages.forEach(this.addMsg.bind(this));
       delete this._writingContextMessages;
+
+      if (this.tab && this.tab.selected && document.hasFocus()) {
+        // This will mark the conv as read, but also update the conv title
+        // with the new unread count etc.
+        this.tab.update();
+      }
     }
 
     displayStatusText() {
       this.convStatus.value = this._statusText;
       if (this._statusText) {
         this.convStatusContainer.removeAttribute("hidden");
       } else {
         this.convStatusContainer.setAttribute("hidden", "true");
@@ -359,17 +367,17 @@
         throw new Error("Calling addMsg before the browser is ready?");
       }
 
       var conv = aMsg.conversation;
       if (!conv) {
         // The conversation has already been destroyed,
         // probably because the window was closed.
         // Return without doing anything.
-        return;
+        return false;
       }
 
       // Ugly hack... :(
       if (!aMsg.system && conv.isChat) {
         let name = aMsg.who;
         let color;
         if (this.buddies.has(name)) {
           let buddy = this.buddies.get(name);
@@ -410,36 +418,32 @@
       if (read) {
         --this._readCount;
         if (!this._readCount && !this._isAfterFirstRealMessage) {
           // If all the context messages were system messages, we don't want
           // an unread ruler after the context messages, so we forget that
           // we had context messages.
           delete this._writingContextMessages;
         }
-        return;
+        return false;
       }
 
       if (isUnreadMessage && (!aMsg.conversation.isChat || aMsg.containsNick)) {
         this._lastPing = aMsg.who;
         this._lastPingTime = aMsg.time;
       }
 
-      if (isTabFocused) {
-        // Porting note: This will mark the conv as read, but also update
-        // the conv title with the new unread count etc. as required for TB.
-        this.tab.update();
-      }
-
       if (shouldSetUnreadFlag) {
         if (conv.isChat && aMsg.containsNick) {
           this.tab.setAttribute("attention", "true");
         }
         this.tab.setAttribute("unread", "true");
       }
+
+      return isTabFocused;
     }
 
     sendMsg(aMsg) {
       if (!aMsg) {
         return;
       }
 
       let account = this._conv.account;