From 2a4cd3c69a6018331cbbbd1070ee40c98c43b9f6 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 27 Sep 2013 18:00:44 -0400 Subject: [PATCH] Exclude muted topics from stream/home unread counts. Update get_counts() so that it ignores counts for muted topics when calculating stream/home unread counts. (imported from commit 9b4e4da4346c225c535e97d709d3dee032603cc5) --- static/js/unread.js | 4 +++- zerver/tests/frontend/node/unread.js | 32 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/static/js/unread.js b/static/js/unread.js index 69c8d6583a..2e68ccb986 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -118,7 +118,9 @@ exports.get_counts = function () { unread_subjects.get(stream).each(function (msgs, subject) { var subject_count = msgs.num_items(); res.subject_count.get(stream).set(subject, subject_count); - stream_count += subject_count; + if (!muting.is_topic_muted(stream, subject)) { + stream_count += subject_count; + } }); res.stream_count.set(stream, stream_count); if (stream_data.in_home_view(stream)) { diff --git a/zerver/tests/frontend/node/unread.js b/zerver/tests/frontend/node/unread.js index cdbd34bbb8..1ab2b19a7e 100644 --- a/zerver/tests/frontend/node/unread.js +++ b/zerver/tests/frontend/node/unread.js @@ -9,6 +9,7 @@ add_dependencies({ _: 'third/underscore/underscore.js', + muting: 'js/muting.js', Dict: 'js/dict.js' }); @@ -20,6 +21,7 @@ stream_data = { set_global('stream_data', stream_data); var Dict = global.Dict; +var muting = global.muting; var unread = require('js/unread.js'); var assert = require('assert'); @@ -103,9 +105,39 @@ var zero_counts = { assert.equal(count, 0); }()); +(function test_muting() { + stream_data.is_subscribed = function () { + return true; + }; + + stream_data.in_home_view = function () { + return true; + }; + + unread.declare_bankruptcy(); + + var message = { + id: 15, + type: 'stream', + stream: 'social', + subject: 'test_muting' + }; + + unread.process_loaded_messages([message]); + var counts = unread.get_counts(); + assert.equal(counts.stream_count.get('social'), 1); + assert.equal(counts.home_unread_messages, 1); + + muting.mute_topic('social', 'test_muting'); + counts = unread.get_counts(); + assert.equal(counts.stream_count.get('social'), 0); + assert.equal(counts.home_unread_messages, 0); +}()); + (function test_num_unread_for_subject() { // Test the num_unread_for_subject() function using many // messages. + unread.declare_bankruptcy(); var count = unread.num_unread_for_subject('social', 'lunch'); assert.equal(count, 0);