const render_more_topics = require('../templates/more_topics.hbs'); const render_topic_list_item = require('../templates/topic_list_item.hbs'); const Dict = require('./dict').Dict; const FoldDict = require('./fold_dict').FoldDict; /* Track all active widgets with a Dict. (We have at max one for now, but we may eventually allow multiple streams to be expanded.) */ const active_widgets = new Dict(); // We know whether we're zoomed or not. let zoomed = false; exports.remove_expanded_topics = function () { stream_popover.hide_topic_popover(); _.each(active_widgets.values(), function (widget) { widget.remove(); }); active_widgets.clear(); }; exports.close = function () { zoomed = false; exports.remove_expanded_topics(); }; exports.zoom_out = function () { zoomed = false; const stream_ids = active_widgets.keys(); if (stream_ids.length !== 1) { blueslip.error('Unexpected number of topic lists to zoom out.'); return; } const stream_id = stream_ids[0]; const widget = active_widgets.get(stream_id); const parent_widget = widget.get_parent(); exports.rebuild(parent_widget, stream_id); }; function update_unread_count(unread_count_elem, count) { // unread_count_elem is a jquery element...we expect DOM // to look like this: //
//
{{unread}}
//
const value_span = unread_count_elem.find('.value'); if (value_span.length === 0) { blueslip.error('malformed dom for unread count'); return; } if (count === 0) { unread_count_elem.addClass("zero_count"); value_span.text(''); } else { unread_count_elem.removeClass("zero_count"); unread_count_elem.show(); value_span.text(count); } } exports.set_count = function (stream_id, topic, count) { const widget = active_widgets.get(stream_id); if (widget === undefined) { return false; } return widget.set_count(topic, count); }; exports.widget = function (parent_elem, my_stream_id) { const self = {}; self.build_list = function () { self.topic_items = new FoldDict(); 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 = $('