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 82247 2cfb1d544ba0442fce04865f94804fd79ddeb30e
parent 82246 792c378e19bcedb1a164a6621d0e734f7236a88d
child 82248 3c37719f7f346108a041629bd224b9fb3ca62ac3
child 82249 e0dc6d3127be0db071411af1acb409f8313fe83c
child 82250 1be215d94d6eda6a2c02ace5c43b3e033e3ab333
child 82252 040ffadfe15ffb98f834ef9495a4dbf87b2f413b
push id9940
push usergeoff@darktrojan.net
push dateWed, 04 Dec 2019 22:28:38 +0000
treeherdertry-comm-central@3c37719f7f34 [default view] [failures only]
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;