mirror of
https://github.com/zulip/zulip.git
synced 2026-07-06 21:18:58 +08:00
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)
This commit is contained in:
parent
c7b7f8d79a
commit
2a4cd3c69a
@ -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)) {
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user