diff --git a/app/assets/javascripts/discourse/app/components/d-document.js b/app/assets/javascripts/discourse/app/components/d-document.js
index 1fa22a778ad..7e8fef1bd3a 100644
--- a/app/assets/javascripts/discourse/app/components/d-document.js
+++ b/app/assets/javascripts/discourse/app/components/d-document.js
@@ -44,16 +44,23 @@ export default Component.extend({
);
},
- _updateNotifications() {
+ _updateNotifications(opts) {
if (!this.currentUser) {
return;
}
- const count =
- pluginCounterFunctions.reduce((sum, fn) => sum + fn(), 0) +
- this.currentUser.unread_notifications +
- this.currentUser.unread_high_priority_notifications;
- this.documentTitle.updateNotificationCount(count);
+ let count = pluginCounterFunctions.reduce((sum, fn) => sum + fn(), 0);
+ if (this.currentUser.redesigned_user_menu_enabled) {
+ count += this.currentUser.all_unread_notifications_count;
+ if (this.currentUser.unseen_reviewable_count) {
+ count += this.currentUser.unseen_reviewable_count;
+ }
+ } else {
+ count +=
+ this.currentUser.unread_notifications +
+ this.currentUser.unread_high_priority_notifications;
+ }
+ this.documentTitle.updateNotificationCount(count, { forced: opts?.forced });
},
@bind
diff --git a/app/assets/javascripts/discourse/app/services/document-title.js b/app/assets/javascripts/discourse/app/services/document-title.js
index c8b90105f0a..b4d0a4b4b1d 100644
--- a/app/assets/javascripts/discourse/app/services/document-title.js
+++ b/app/assets/javascripts/discourse/app/services/document-title.js
@@ -4,6 +4,7 @@ import updateTabCount from "discourse/lib/update-tab-count";
export default Service.extend({
appEvents: service(),
+ currentUser: service(),
contextCount: null,
notificationCount: null,
_title: null,
@@ -53,8 +54,8 @@ export default Service.extend({
this._renderTitle();
},
- updateNotificationCount(count) {
- if (!this.session.hasFocus) {
+ updateNotificationCount(count, { forced = false } = {}) {
+ if (!this.session.hasFocus || forced) {
this.notificationCount = count;
this._renderFavicon();
this._renderTitle();
diff --git a/app/assets/javascripts/discourse/tests/integration/components/d-document-test.js b/app/assets/javascripts/discourse/tests/integration/components/d-document-test.js
new file mode 100644
index 00000000000..361c55b5707
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/integration/components/d-document-test.js
@@ -0,0 +1,77 @@
+import { module, test } from "qunit";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import { render } from "@ember/test-helpers";
+import { hbs } from "ember-cli-htmlbars";
+
+function getTitleCount() {
+ const match = document.title.match(/^\((\d+)\)\s/);
+ if (match) {
+ return parseInt(match[1], 10);
+ } else {
+ return null;
+ }
+}
+
+function triggerTitleUpdate(appEvents) {
+ appEvents.trigger("notifications:changed", { forced: true });
+}
+
+module("Integration | Component | d-document", function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("when experimental user menu is enabled", async function (assert) {
+ const titleBefore = document.title;
+ try {
+ this.currentUser.redesigned_user_menu_enabled = true;
+ this.currentUser.title_count_mode = "notifications";
+ await render(hbs``);
+ assert.strictEqual(
+ getTitleCount(),
+ null,
+ "title doesn't have a count initially"
+ );
+
+ this.currentUser.unread_high_priority_notifications = 1;
+ this.currentUser.unread_notifications = 2;
+ this.currentUser.all_unread_notifications_count = 4;
+ this.currentUser.unseen_reviewable_count = 8;
+ triggerTitleUpdate(this.currentUser.appEvents);
+
+ assert.strictEqual(
+ getTitleCount(),
+ 12,
+ "count in the title is the sum of all_unread_notifications_count and unseen_reviewable_count"
+ );
+ } finally {
+ document.title = titleBefore;
+ }
+ });
+
+ test("when experimental user menu is disabled", async function (assert) {
+ const titleBefore = document.title;
+ try {
+ this.currentUser.redesigned_user_menu_enabled = false;
+ this.currentUser.title_count_mode = "notifications";
+ await render(hbs``);
+ assert.strictEqual(
+ getTitleCount(),
+ null,
+ "title doesn't have a count initially"
+ );
+
+ this.currentUser.unread_high_priority_notifications = 1;
+ this.currentUser.unread_notifications = 2;
+ this.currentUser.all_unread_notifications_count = 4;
+ this.currentUser.unseen_reviewable_count = 8;
+ triggerTitleUpdate(this.currentUser.appEvents);
+
+ assert.strictEqual(
+ getTitleCount(),
+ 3,
+ "count in the title is the sum of unread_notifications and unread_high_priority_notifications"
+ );
+ } finally {
+ document.title = titleBefore;
+ }
+ });
+});