A platform for community discussion. Free, open, simple.
DEV: Remove unused countTags method from TopicTrackingState (#37077)
Alan Guo Xiang Tan1790c8c6680d
diff --git a/frontend/discourse/app/models/topic-tracking-state.js b/frontend/discourse/app/models/topic-tracking-state.jsindex 85dd6f778de..a47b8de4314 100644--- a/frontend/discourse/app/models/topic-tracking-state.js+++ b/frontend/discourse/app/models/topic-tracking-state.js@@ -671,59 +671,6 @@ export default class TopicTrackingState extends EmberObject {});}- /**- * Using the array of tags provided, tallies up all topics via forEachTracked- * that we are tracking, separated into new/unread/total.- *- * Total is only counted if opts.includeTotal is specified.- *- * Output (from input ["pending", "bug"]):- *- * {- * pending: { unreadCount: 6, newCount: 1, totalCount: 10 },- * bug: { unreadCount: 0, newCount: 4, totalCount: 20 }- * }- *- * @method countTags- * @param opts - Valid options:- * * includeTotal - When true, a totalCount is incremented for- * all topics matching a tag.- */- countTags(tags, opts = {}) {- let counts = {};-- tags.forEach((tag) => {- counts[tag] = { unreadCount: 0, newCount: 0 };- if (opts.includeTotal) {- counts[tag].totalCount = 0;- }- });-- this.forEachTracked(- (topic, newTopic, unreadTopic) => {- if (topic.tags && topic.tags.length > 0) {- tags.forEach((tag) => {- if (topic.tags.includes(tag)) {- if (unreadTopic) {- counts[tag].unreadCount++;- }- if (newTopic) {- counts[tag].newCount++;- }-- if (opts.includeTotal) {- counts[tag].totalCount++;- }- }- });- }- },- { includeAll: opts.includeTotal }- );-- return counts;- }-countCategory(category_id, tagId) {let sum = 0;for (let topic of this.states.values()) {diff --git a/frontend/discourse/tests/unit/models/topic-tracking-state-test.js b/frontend/discourse/tests/unit/models/topic-tracking-state-test.jsindex 601fcfd0a86..69a6fce5d68 100644--- a/frontend/discourse/tests/unit/models/topic-tracking-state-test.js+++ b/frontend/discourse/tests/unit/models/topic-tracking-state-test.js@@ -41,164 +41,6 @@ module("Unit | Model | topic-tracking-state", function (hooks) {assert.strictEqual(stateCallbackCalled, 1, "callback is only called once");});- test("tag counts", function (assert) {- const trackingState = this.store.createRecord("topic-tracking-state");-- trackingState.loadStates([- {- topic_id: 1,- last_read_post_number: null,- tags: ["foo", "baz"],- created_in_new_period: true,- },- {- topic_id: 2,- last_read_post_number: null,- tags: ["baz"],- created_in_new_period: true,- },- {- topic_id: 3,- last_read_post_number: null,- tags: ["random"],- },- {- topic_id: 4,- last_read_post_number: 1,- highest_post_number: 7,- tags: ["pending"],- notification_level: NotificationLevels.TRACKING,- },- {- topic_id: 5,- last_read_post_number: 1,- highest_post_number: 7,- tags: ["bar", "pending"],- notification_level: NotificationLevels.TRACKING,- },- {- topic_id: 6,- last_read_post_number: 1,- highest_post_number: 7,- tags: null,- notification_level: NotificationLevels.TRACKING,- },- ]);-- const tagCounts = trackingState.countTags(["baz", "pending"]);-- assert.strictEqual(tagCounts["baz"].newCount, 2, "baz tag new counts");- assert.strictEqual(- tagCounts["baz"].unreadCount,- 0,- "baz tag unread counts"- );- assert.strictEqual(- tagCounts["pending"].unreadCount,- 2,- "pending tag unread counts"- );- assert.strictEqual(- tagCounts["pending"].newCount,- 0,- "pending tag new counts"- );-- // Ensure it is not throwing an error when filterTag is set and message payload is missing tags- trackingState.trackIncoming("tag/test/l/latest");- trackingState.notifyIncoming({- message_type: "new_topic",- topic_id: 4,- payload: { category_id: 2 },- });- const testTagCount = trackingState.countTags(["test"]);- assert.strictEqual(testTagCount["test"].unreadCount, 0);- });-- test("tag counts - with total", function (assert) {- const trackingState = this.store.createRecord("topic-tracking-state");-- trackingState.loadStates([- {- topic_id: 1,- last_read_post_number: null,- tags: ["foo", "baz"],- created_in_new_period: true,- },- {- topic_id: 2,- last_read_post_number: null,- tags: ["baz"],- created_in_new_period: true,- },- {- topic_id: 3,- last_read_post_number: null,- tags: ["random"],- },- {- topic_id: 4,- last_read_post_number: 1,- highest_post_number: 7,- tags: ["pending"],- notification_level: NotificationLevels.TRACKING,- },- {- topic_id: 5,- last_read_post_number: 1,- highest_post_number: 7,- tags: ["bar", "pending"],- notification_level: NotificationLevels.TRACKING,- },- {- topic_id: 6,- last_read_post_number: 1,- highest_post_number: 7,- tags: null,- notification_level: NotificationLevels.TRACKING,- },- {- topic_id: 7,- last_read_post_number: 7,- highest_post_number: 7,- tags: ["foo", "baz"],- },- {- topic_id: 8,- last_read_post_number: 4,- highest_post_number: 4,- tags: ["pending"],- notification_level: NotificationLevels.TRACKING,- },- {- topic_id: 9,- last_read_post_number: 88,- highest_post_number: 88,- tags: ["pending"],- notification_level: NotificationLevels.TRACKING,- },- ]);-- const states = trackingState.countTags(["baz", "pending"], {- includeTotal: true,- });-- assert.strictEqual(states["baz"].newCount, 2, "baz tag new counts");- assert.strictEqual(states["baz"].unreadCount, 0, "baz tag unread counts");- assert.strictEqual(states["baz"].totalCount, 3, "baz tag total counts");- assert.strictEqual(- states["pending"].unreadCount,- 2,- "pending tag unread counts"- );- assert.strictEqual(states["pending"].newCount, 0, "pending tag new counts");- assert.strictEqual(- states["pending"].totalCount,- 4,- "pending tag total counts"- );- });-test("forEachTracked", function (assert) {const trackingState = this.store.createRecord("topic-tracking-state");