FIX: notifications not updating correctly from background tab

FIX: notifications not updating correctly from background tab

We refactored some code to avoid app event leak in tests at c462c2f2

Unfortunately this broke all background notifications in title and they were broken for the past multiple months.

diff --git a/app/assets/javascripts/discourse/initializers/title-notifications.js.es6 b/app/assets/javascripts/discourse/initializers/title-notifications.js.es6
index ba24755..ca83d7a 100644
--- a/app/assets/javascripts/discourse/initializers/title-notifications.js.es6
+++ b/app/assets/javascripts/discourse/initializers/title-notifications.js.es6
@@ -6,8 +6,7 @@ export default {
     const user = container.lookup("current-user:main");
     if (!user) return; // must be logged in
 
-    this.notifications =
-      user.unread_notifications + user.unread_private_messages;
+    this.container = container;
 
     container
       .lookup("app-events:main")
@@ -15,6 +14,12 @@ export default {
   },
 
   _updateTitle() {
-    Discourse.updateNotificationCount(this.notifications);
+    const user = this.container.lookup("current-user:main");
+    if (!user) return; // must be logged in
+
+    const notifications =
+      user.unread_notifications + user.unread_private_messages;
+
+    Discourse.updateNotificationCount(notifications);
   }
 };

GitHub sha: 3e855e33

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: