mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Extract topic_list.build_list().
This used to be stream_list._build_subject_list(). The code didn't change except for one s/subject/topic fix.
This commit is contained in:
		@@ -20,6 +20,9 @@ set_global('message_store', {
 | 
			
		||||
 | 
			
		||||
var stream_list = require('js/stream_list.js');
 | 
			
		||||
 | 
			
		||||
// TODO: split out topic_list stuff to its own test module.
 | 
			
		||||
var topic_list = require('js/topic_list.js');
 | 
			
		||||
 | 
			
		||||
var jsdom = require("jsdom");
 | 
			
		||||
var window = jsdom.jsdom().defaultView;
 | 
			
		||||
global.$ = require('jquery')(window);
 | 
			
		||||
@@ -33,7 +36,7 @@ global.use_template('sidebar_private_message_list');
 | 
			
		||||
global.use_template('stream_sidebar_row');
 | 
			
		||||
global.use_template('stream_privacy');
 | 
			
		||||
 | 
			
		||||
(function test_build_subject_list() {
 | 
			
		||||
(function test_topic_list_build_list() {
 | 
			
		||||
    var stream = "devel";
 | 
			
		||||
    var active_topic = "testing";
 | 
			
		||||
    var max_topics = 5;
 | 
			
		||||
@@ -46,8 +49,8 @@ global.use_template('stream_privacy');
 | 
			
		||||
        return 1;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    var topic_html = stream_list._build_subject_list(stream, active_topic, max_topics);
 | 
			
		||||
    global.write_test_output("test_build_subject_list", topic_html);
 | 
			
		||||
    var topic_html = topic_list.build_list(stream, active_topic, max_topics);
 | 
			
		||||
    global.write_test_output("test_topic_list_build_list", topic_html);
 | 
			
		||||
 | 
			
		||||
    var topic = $(topic_html).find('a').text().trim();
 | 
			
		||||
    assert.equal(topic, 'coding');
 | 
			
		||||
 
 | 
			
		||||
@@ -360,46 +360,6 @@ exports.remove_narrow_filter = function (name, type) {
 | 
			
		||||
    get_filter_li(type, name).remove();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports._build_subject_list = function (stream, active_topic, max_subjects) {
 | 
			
		||||
    var subjects = stream_data.recent_subjects.get(stream) || [];
 | 
			
		||||
 | 
			
		||||
    if (active_topic) {
 | 
			
		||||
        active_topic = active_topic.toLowerCase();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var display_subjects = [];
 | 
			
		||||
    var hiding_topics = false;
 | 
			
		||||
 | 
			
		||||
    _.each(subjects, function (subject_obj, idx) {
 | 
			
		||||
        var topic_name = subject_obj.subject;
 | 
			
		||||
        var num_unread = unread.num_unread_for_subject(stream, subject_obj.canon_subject);
 | 
			
		||||
 | 
			
		||||
        // Show the most recent subjects, as well as any with unread messages
 | 
			
		||||
        var always_visible = (idx < max_subjects) || (num_unread > 0) || (active_topic === topic_name);
 | 
			
		||||
 | 
			
		||||
        if (!always_visible) {
 | 
			
		||||
            hiding_topics = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var display_subject = {
 | 
			
		||||
            topic_name: topic_name,
 | 
			
		||||
            unread: num_unread,
 | 
			
		||||
            is_zero: num_unread === 0,
 | 
			
		||||
            is_muted: muting.is_topic_muted(stream, topic_name),
 | 
			
		||||
            zoom_out_hide: !always_visible,
 | 
			
		||||
            url: narrow.by_stream_subject_uri(stream, topic_name)
 | 
			
		||||
        };
 | 
			
		||||
        display_subjects.push(display_subject);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    var topic_dom = templates.render('sidebar_subject_list',
 | 
			
		||||
                                      {subjects: display_subjects,
 | 
			
		||||
                                       want_show_more_topics_links: hiding_topics,
 | 
			
		||||
                                       stream: stream});
 | 
			
		||||
 | 
			
		||||
    return topic_dom;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports._build_private_messages_list = function (active_conversation, max_private_messages) {
 | 
			
		||||
 | 
			
		||||
    var private_messages = message_store.recent_private_messages || [];
 | 
			
		||||
@@ -443,7 +403,7 @@ function rebuild_recent_topics(stream, active_topic) {
 | 
			
		||||
    var max_subjects = 5;
 | 
			
		||||
    var stream_li = get_filter_li('stream', stream);
 | 
			
		||||
 | 
			
		||||
    var topic_dom = exports._build_subject_list(stream, active_topic, max_subjects);
 | 
			
		||||
    var topic_dom = topic_list.build_list(stream, active_topic, max_subjects);
 | 
			
		||||
    stream_li.append(topic_dom);
 | 
			
		||||
 | 
			
		||||
    if (active_topic) {
 | 
			
		||||
 
 | 
			
		||||
@@ -55,6 +55,46 @@ exports.set_count = function (stream_li, topic, count) {
 | 
			
		||||
    exports.update_count_in_dom(count_span, value_span, count);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.build_list = function (stream, active_topic, max_topics) {
 | 
			
		||||
    var subjects = stream_data.recent_subjects.get(stream) || [];
 | 
			
		||||
 | 
			
		||||
    if (active_topic) {
 | 
			
		||||
        active_topic = active_topic.toLowerCase();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var display_subjects = [];
 | 
			
		||||
    var hiding_topics = false;
 | 
			
		||||
 | 
			
		||||
    _.each(subjects, function (subject_obj, idx) {
 | 
			
		||||
        var topic_name = subject_obj.subject;
 | 
			
		||||
        var num_unread = unread.num_unread_for_subject(stream, subject_obj.canon_subject);
 | 
			
		||||
 | 
			
		||||
        // Show the most recent subjects, as well as any with unread messages
 | 
			
		||||
        var always_visible = (idx < max_topics) || (num_unread > 0) || (active_topic === topic_name);
 | 
			
		||||
 | 
			
		||||
        if (!always_visible) {
 | 
			
		||||
            hiding_topics = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var display_subject = {
 | 
			
		||||
            topic_name: topic_name,
 | 
			
		||||
            unread: num_unread,
 | 
			
		||||
            is_zero: num_unread === 0,
 | 
			
		||||
            is_muted: muting.is_topic_muted(stream, topic_name),
 | 
			
		||||
            zoom_out_hide: !always_visible,
 | 
			
		||||
            url: narrow.by_stream_subject_uri(stream, topic_name)
 | 
			
		||||
        };
 | 
			
		||||
        display_subjects.push(display_subject);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    var topic_dom = templates.render('sidebar_subject_list',
 | 
			
		||||
                                      {subjects: display_subjects,
 | 
			
		||||
                                       want_show_more_topics_links: hiding_topics,
 | 
			
		||||
                                       stream: stream});
 | 
			
		||||
 | 
			
		||||
    return topic_dom;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
return exports;
 | 
			
		||||
}());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user