FIX: Stop tracking incoming message after navigating away take 2. (#14508)

FIX: Stop tracking incoming message after navigating away take 2. (#14508)

  • FIX: Stop tracking incoming message after navigating away take 2.

Previous fix in d82e5cd37c1c3b2377507ed0354bbdce6a96ae99 resulted in counts being flappy as we cleared the active inbox between routes.

Co-authored-by: Osama Sayegh asooomaasoooma90@gmail.com

diff --git a/app/assets/javascripts/discourse/app/models/private-message-topic-tracking-state.js b/app/assets/javascripts/discourse/app/models/private-message-topic-tracking-state.js
index 2d7e369..f2a7fb0 100644
--- a/app/assets/javascripts/discourse/app/models/private-message-topic-tracking-state.js
+++ b/app/assets/javascripts/discourse/app/models/private-message-topic-tracking-state.js
@@ -78,21 +78,20 @@ const PrivateMessageTopicTrackingState = EmberObject.extend({
 
   trackIncoming(inbox, filter, group) {
     this.setProperties({ inbox, filter, activeGroup: group });
+    this.set("isTrackingIncoming", true);
   },
 
   resetIncomingTracking() {
-    if (this.inbox) {
+    if (this.isTrackingIncoming) {
       this.set("newIncoming", []);
     }
   },
 
   stopIncomingTracking() {
-    if (this.inbox) {
+    if (this.isTrackingIncoming) {
       this.setProperties({
+        isTrackingIncoming: false,
         newIncoming: [],
-        inbox: null,
-        filter: null,
-        activeGroup: null,
       });
     }
   },
@@ -213,7 +212,7 @@ const PrivateMessageTopicTrackingState = EmberObject.extend({
   },
 
   _notifyIncoming(topicId) {
-    if (this.newIncoming.indexOf(topicId) === -1) {
+    if (this.isTrackingIncoming && this.newIncoming.indexOf(topicId) === -1) {
       this.newIncoming.pushObject(topicId);
     }
   },
diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js
index ac97cb5..8ffcbce 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/user-private-messages-test.js
@@ -423,6 +423,21 @@ acceptance(
       );
     });
 
+    test("incoming messages is not tracked on non user messages route", async function (assert) {
+      await visit("/u/charlie/messages");
+      await visit("/t/13");
+
+      publishNewToMessageBus({ topicId: 1, userId: 5 });
+
+      await visit("/t/13"); // await re-render
+      await visit("/u/charlie/messages");
+
+      assert.ok(
+        !exists(".show-mores"),
+        "does not display the topic incoming info"
+      );
+    });
+
     test("dismissing all unread messages", async function (assert) {
       await visit("/u/charlie/messages/unread");
 

GitHub sha: 12856ab8c2f0d843f533547e9c1719d3cde1c00b

This commit appears in #14508 which was approved by OsamaSayegh. It was merged by tgxworld.