A platform for community discussion. Free, open, simple.
FIX: Respect title_count_mode preference in chat (#36930)
Osama Sayegha9008966f0b3
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat.js b/plugins/chat/assets/javascripts/discourse/services/chat.jsindex eef4967c822..1e802d50f6a 100644--- a/plugins/chat/assets/javascripts/discourse/services/chat.js+++ b/plugins/chat/assets/javascripts/discourse/services/chat.js@@ -253,10 +253,11 @@ export default class Chat extends Service {}getDocumentTitleCount() {- return (- this.chatTrackingStateManager.allChannelUrgentCount +- this.chatPanePendingManager.totalPendingMessageCount- );+ if (this.currentUser?.user_option?.title_count_mode === "notifications") {+ return this.chatTrackingStateManager.allChannelUrgentCount;+ } else {+ return this.chatPanePendingManager.totalPendingMessageCount;+ }}switchChannelUpOrDown(direction, unreadOnly = false) {diff --git a/plugins/chat/test/javascripts/unit/services/chat-test.js b/plugins/chat/test/javascripts/unit/services/chat-test.jsnew file mode 100644index 00000000000..20b164270a3--- /dev/null+++ b/plugins/chat/test/javascripts/unit/services/chat-test.js@@ -0,0 +1,56 @@+import { test } from "qunit";+import sinon from "sinon";+import { acceptance } from "discourse/tests/helpers/qunit-helpers";++acceptance("Discourse Chat | Unit | Service | chat", function (needs) {+ needs.user();++ needs.hooks.beforeEach(function () {+ Object.defineProperty(this, "currentUser", {+ get: () => this.container.lookup("service:current-user"),+ });+ Object.defineProperty(this, "chat", {+ get: () => this.container.lookup("service:chat"),+ });+ this.chatTrackingStateManager = this.container.lookup(+ "service:chat-tracking-state-manager"+ );+ this.chatPanePendingManager = this.container.lookup(+ "service:chat-pane-pending-manager"+ );+ sinon+ .stub(this.chatTrackingStateManager, "allChannelUrgentCount")+ .get(() => 5);+ sinon+ .stub(this.chatPanePendingManager, "totalPendingMessageCount")+ .get(() => 10);+ });++ test("getDocumentTitleCount returns urget count when title_count_mode is 'notifications'", function (assert) {+ this.currentUser.user_option.title_count_mode = "notifications";++ const count = this.chat.getDocumentTitleCount();++ assert.strictEqual(+ count,+ 5,+ "returns only urgent count (mentions, DMs, watched threads)"+ );+ });++ test("getDocumentTitleCount returns pending count when title_count_mode is 'contextual'", function (assert) {+ this.currentUser.user_option.title_count_mode = "contextual";++ const count = this.chat.getDocumentTitleCount();++ assert.strictEqual(count, 10, "returns pending count");+ });++ test("getDocumentTitleCount returns pending count when user_option is null", function (assert) {+ this.currentUser.user_option = null;++ const count = this.chat.getDocumentTitleCount();++ assert.strictEqual(count, 10, "returns pending count");+ });+});