diff --git a/static/js/stream_list.js b/static/js/stream_list.js index 3c3fc1e112..361a13259e 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -317,9 +317,22 @@ exports.update_dom_with_unread_counts = function (counts) { // counts.topic_count maps streams to hashes of topics to counts counts.topic_count.each(function (topic_hash, stream_id) { + // Because the topic_list data structure doesn't keep track of + // which topics the "more topics" unread count came from, we + // need to compute the correct value from scratch here. + let more_topics_total = 0; topic_hash.each(function (count, topic) { - topic_list.set_count(stream_id, topic, count); + const in_more_topics = topic_list.set_count(stream_id, topic, count); + if (in_more_topics === true) { + more_topics_total += count; + } }); + if (topic_list.active_stream_id() === stream_id) { + // Update the "more topics" unread count; we communicate + // this to the `topic_list` library by passing `null` as + // the topic. + topic_list.set_count(stream_id, null, more_topics_total); + } }); }; diff --git a/static/js/topic_list.js b/static/js/topic_list.js index 7a7724517a..9ec5af6a08 100644 --- a/static/js/topic_list.js +++ b/static/js/topic_list.js @@ -61,7 +61,7 @@ function update_unread_count(unread_count_elem, count) { } if (count === 0) { - unread_count_elem.hide(); + unread_count_elem.addClass("zero_count"); value_span.text(''); } else { unread_count_elem.removeClass("zero_count"); @@ -74,10 +74,10 @@ exports.set_count = function (stream_id, topic, count) { const widget = active_widgets.get(stream_id); if (widget === undefined) { - return; + return false; } - widget.set_count(topic, count); + return widget.set_count(topic, count); }; exports.widget = function (parent_elem, my_stream_id) { @@ -85,19 +85,36 @@ exports.widget = function (parent_elem, my_stream_id) { self.build_list = function () { self.topic_items = new Dict({fold_case: true}); + let topics_selected = 0; + let more_topics_unreads = 0; const max_topics = 5; + const max_topics_with_unread = 8; const topic_names = topic_data.get_recent_names(my_stream_id); const ul = $('