mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	topic_data: Rename topic_data module to stream_topic_history.
				
					
				
			`stream_topic_history` is a more appropriate name as this module will contain information about last message of a stream in upcoming commits. Function and variable names are changed accordingly like: * topic_history() -> per_stream_history() * get_recent_names() -> get_recent_topic_names() * name -> topic_name
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							c5eddcb1ca
						
					
				
				
					commit
					ee0d4541b4
				
			@@ -367,6 +367,7 @@
 | 
			
		||||
                "stream_data": false,
 | 
			
		||||
                "stream_edit": false,
 | 
			
		||||
                "stream_events": false,
 | 
			
		||||
                "stream_topic_history": false,
 | 
			
		||||
                "stream_list": false,
 | 
			
		||||
                "stream_muting": false,
 | 
			
		||||
                "stream_popover": false,
 | 
			
		||||
@@ -381,7 +382,6 @@
 | 
			
		||||
                "timerender": false,
 | 
			
		||||
                "todo_widget": false,
 | 
			
		||||
                "top_left_corner": false,
 | 
			
		||||
                "topic_data": false,
 | 
			
		||||
                "topic_generator": false,
 | 
			
		||||
                "topic_list": false,
 | 
			
		||||
                "topic_zoom": false,
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@ set_global('md5', function (s) {
 | 
			
		||||
stream_data.update_calculated_fields = () => {};
 | 
			
		||||
stream_data.set_filter_out_inactives = () => false;
 | 
			
		||||
 | 
			
		||||
set_global('topic_data', {
 | 
			
		||||
set_global('stream_topic_history', {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
set_global('message_store', {
 | 
			
		||||
@@ -281,7 +281,7 @@ const make_emoji = function (emoji_dict) {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
run_test('topics_seen_for', () => {
 | 
			
		||||
    topic_data.get_recent_names = (stream_id) => {
 | 
			
		||||
    stream_topic_history.get_recent_topic_names = (stream_id) => {
 | 
			
		||||
        assert.equal(stream_id, denmark_stream.stream_id);
 | 
			
		||||
        return ['With Twisted Metal', 'acceptance', 'civil fears'];
 | 
			
		||||
    };
 | 
			
		||||
@@ -560,7 +560,7 @@ run_test('initialize', () => {
 | 
			
		||||
    let subject_typeahead_called = false;
 | 
			
		||||
    $('#stream_message_recipient_topic').typeahead = function (options) {
 | 
			
		||||
        const topics = ['<&>', 'even more ice', 'furniture', 'ice', 'kronor', 'more ice'];
 | 
			
		||||
        topic_data.get_recent_names = (stream_id) => {
 | 
			
		||||
        stream_topic_history.get_recent_topic_names = (stream_id) => {
 | 
			
		||||
            assert.equal(stream_id, sweden_stream.stream_id);
 | 
			
		||||
            return topics;
 | 
			
		||||
        };
 | 
			
		||||
@@ -1282,7 +1282,8 @@ run_test('begins_typeahead', () => {
 | 
			
		||||
    assert_typeahead_equals("#**Sweden>some topic** >", false); // Already completed a topic.
 | 
			
		||||
 | 
			
		||||
    // topic_list
 | 
			
		||||
    const sweden_topics_to_show = topic_data.get_recent_names(1); //includes "more ice"
 | 
			
		||||
    // includes "more ice"
 | 
			
		||||
    const sweden_topics_to_show = stream_topic_history.get_recent_topic_names(1);
 | 
			
		||||
    assert_typeahead_equals("#**Sweden>more ice", sweden_topics_to_show);
 | 
			
		||||
    sweden_topics_to_show.push('totally new topic');
 | 
			
		||||
    assert_typeahead_equals("#**Sweden>totally new topic", sweden_topics_to_show);
 | 
			
		||||
 
 | 
			
		||||
@@ -92,7 +92,7 @@ set_global('overlays', {
 | 
			
		||||
// For data-oriented modules, just use them, don't stub them.
 | 
			
		||||
zrequire('alert_words');
 | 
			
		||||
zrequire('unread');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_topic_history');
 | 
			
		||||
zrequire('stream_list');
 | 
			
		||||
zrequire('message_flags');
 | 
			
		||||
zrequire('message_store');
 | 
			
		||||
@@ -1540,7 +1540,7 @@ with_overrides(function (override) {
 | 
			
		||||
        assert_same(args.message_ids, [1337]);
 | 
			
		||||
    });
 | 
			
		||||
    global.with_stub(function (stub) {
 | 
			
		||||
        override('topic_data.remove_message', stub.f);
 | 
			
		||||
        override('stream_topic_history.remove_message', stub.f);
 | 
			
		||||
        dispatch(event);
 | 
			
		||||
        const args = stub.get_args('opts');
 | 
			
		||||
        assert_same(args.opts.stream_id, 99);
 | 
			
		||||
 
 | 
			
		||||
@@ -98,7 +98,7 @@ alert_words.process_message = noop;
 | 
			
		||||
// We can also bring in real code:
 | 
			
		||||
zrequire('recent_senders');
 | 
			
		||||
zrequire('unread');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_topic_history');
 | 
			
		||||
 | 
			
		||||
// And finally require the module that we will test directly:
 | 
			
		||||
zrequire('message_store');
 | 
			
		||||
@@ -118,7 +118,7 @@ run_test('message_store', () => {
 | 
			
		||||
    assert.equal(message, in_message);
 | 
			
		||||
 | 
			
		||||
    // There are more side effects.
 | 
			
		||||
    const topic_names = topic_data.get_recent_names(denmark_stream.stream_id);
 | 
			
		||||
    const topic_names = stream_topic_history.get_recent_topic_names(denmark_stream.stream_id);
 | 
			
		||||
    assert.deepEqual(topic_names, ['copenhagen']);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ zrequire('muting');
 | 
			
		||||
zrequire('people');
 | 
			
		||||
zrequire('recent_senders');
 | 
			
		||||
zrequire('stream_data');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_topic_history');
 | 
			
		||||
zrequire('unread');
 | 
			
		||||
 | 
			
		||||
set_global('alert_words', {});
 | 
			
		||||
@@ -75,7 +75,7 @@ run_test('update_messages', () => {
 | 
			
		||||
    assert.equal(original_message.unread, true);
 | 
			
		||||
 | 
			
		||||
    assert.deepEqual(
 | 
			
		||||
        topic_data.get_recent_names(denmark.stream_id),
 | 
			
		||||
        stream_topic_history.get_recent_topic_names(denmark.stream_id),
 | 
			
		||||
        ['lunch']
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ set_global('alert_words', {
 | 
			
		||||
    process_message: noop,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
set_global('topic_data', {
 | 
			
		||||
set_global('stream_topic_history', {
 | 
			
		||||
    add_message: noop,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -213,7 +213,7 @@ run_test('show_invalid_narrow_message', () => {
 | 
			
		||||
 | 
			
		||||
run_test('narrow_to_compose_target', () => {
 | 
			
		||||
    set_global('compose_state', {});
 | 
			
		||||
    set_global('topic_data', {});
 | 
			
		||||
    set_global('stream_topic_history', {});
 | 
			
		||||
    const args = {called: false};
 | 
			
		||||
    const activate_backup = narrow.activate;
 | 
			
		||||
    narrow.activate = function (operators, opts) {
 | 
			
		||||
@@ -239,7 +239,7 @@ run_test('narrow_to_compose_target', () => {
 | 
			
		||||
    global.compose_state.get_message_type = () => 'stream';
 | 
			
		||||
    stream_data.add_sub({name: 'ROME', stream_id: 99});
 | 
			
		||||
    global.compose_state.stream_name = () => 'ROME';
 | 
			
		||||
    global.topic_data.get_recent_names = () => ['one', 'two', 'three'];
 | 
			
		||||
    global.stream_topic_history.get_recent_topic_names = () => ['one', 'two', 'three'];
 | 
			
		||||
 | 
			
		||||
    // Test with existing topic
 | 
			
		||||
    global.compose_state.topic = () => 'one';
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ set_global('Handlebars', global.make_handlebars());
 | 
			
		||||
zrequire('Filter', 'js/filter');
 | 
			
		||||
zrequire('narrow_state');
 | 
			
		||||
zrequire('stream_data');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_topic_history');
 | 
			
		||||
zrequire('people');
 | 
			
		||||
zrequire('unread');
 | 
			
		||||
zrequire('common');
 | 
			
		||||
@@ -41,7 +41,7 @@ init();
 | 
			
		||||
page_params.is_admin = true;
 | 
			
		||||
set_global('narrow', {});
 | 
			
		||||
 | 
			
		||||
topic_data.reset();
 | 
			
		||||
stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
function get_suggestions(base_query, query) {
 | 
			
		||||
    return search.get_suggestions(base_query, query);
 | 
			
		||||
@@ -832,20 +832,20 @@ run_test('topic_suggestions', () => {
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
    suggestions = get_suggestions('', 'te');
 | 
			
		||||
    expected = [
 | 
			
		||||
        "te",
 | 
			
		||||
    ];
 | 
			
		||||
    assert.deepEqual(suggestions.strings, expected);
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: devel_id,
 | 
			
		||||
        topic_name: 'REXX',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    for (const topic_name of ['team', 'ignore', 'test']) {
 | 
			
		||||
        topic_data.add_message({
 | 
			
		||||
        stream_topic_history.add_message({
 | 
			
		||||
            stream_id: office_id,
 | 
			
		||||
            topic_name: topic_name,
 | 
			
		||||
        });
 | 
			
		||||
@@ -924,7 +924,7 @@ run_test('whitespace_glitch', () => {
 | 
			
		||||
        return;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
    const suggestions = get_suggestions('', query);
 | 
			
		||||
 | 
			
		||||
@@ -944,7 +944,7 @@ run_test('stream_completion', () => {
 | 
			
		||||
        return;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
    let query = 'stream:of';
 | 
			
		||||
    let suggestions = get_suggestions('s', query);
 | 
			
		||||
@@ -996,7 +996,7 @@ function people_suggestion_setup() {
 | 
			
		||||
    };
 | 
			
		||||
    people.add(alice);
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
run_test('people_suggestions', () => {
 | 
			
		||||
@@ -1151,7 +1151,7 @@ run_test('queries_with_spaces', () => {
 | 
			
		||||
        return;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
    // test allowing spaces with quotes surrounding operand
 | 
			
		||||
    let query = 'stream:"dev he"';
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ set_global('Handlebars', global.make_handlebars());
 | 
			
		||||
zrequire('Filter', 'js/filter');
 | 
			
		||||
zrequire('narrow_state');
 | 
			
		||||
zrequire('stream_data');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_topic_history');
 | 
			
		||||
zrequire('people');
 | 
			
		||||
zrequire('unread');
 | 
			
		||||
zrequire('common');
 | 
			
		||||
@@ -39,7 +39,7 @@ set_global('narrow', {});
 | 
			
		||||
 | 
			
		||||
page_params.is_admin = true;
 | 
			
		||||
 | 
			
		||||
topic_data.reset();
 | 
			
		||||
stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
run_test('basic_get_suggestions', () => {
 | 
			
		||||
    const query = 'fred';
 | 
			
		||||
@@ -801,20 +801,20 @@ run_test('topic_suggestions', () => {
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
    suggestions = search.get_suggestions_legacy('te');
 | 
			
		||||
    expected = [
 | 
			
		||||
        "te",
 | 
			
		||||
    ];
 | 
			
		||||
    assert.deepEqual(suggestions.strings, expected);
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: devel_id,
 | 
			
		||||
        topic_name: 'REXX',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    for (const topic_name of ['team', 'ignore', 'test']) {
 | 
			
		||||
        topic_data.add_message({
 | 
			
		||||
        stream_topic_history.add_message({
 | 
			
		||||
            stream_id: office_id,
 | 
			
		||||
            topic_name: topic_name,
 | 
			
		||||
        });
 | 
			
		||||
@@ -903,7 +903,7 @@ run_test('whitespace_glitch', () => {
 | 
			
		||||
        return;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
    const suggestions = search.get_suggestions_legacy(query);
 | 
			
		||||
 | 
			
		||||
@@ -923,7 +923,7 @@ run_test('stream_completion', () => {
 | 
			
		||||
        return;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
    let query = 'stream:of';
 | 
			
		||||
    let suggestions = search.get_suggestions_legacy(query);
 | 
			
		||||
@@ -982,7 +982,8 @@ run_test('people_suggestions', () => {
 | 
			
		||||
    people.add(bob);
 | 
			
		||||
    people.add(alice);
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
    let suggestions = search.get_suggestions_legacy(query);
 | 
			
		||||
 | 
			
		||||
@@ -1099,7 +1100,7 @@ run_test('queries_with_spaces', () => {
 | 
			
		||||
        return;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
    // test allowing spaces with quotes surrounding operand
 | 
			
		||||
    let query = 'stream:"dev he"';
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ global.stub_out_jquery();
 | 
			
		||||
 | 
			
		||||
zrequire('color_data');
 | 
			
		||||
zrequire('hash_util');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_topic_history');
 | 
			
		||||
zrequire('people');
 | 
			
		||||
zrequire('stream_color');
 | 
			
		||||
zrequire('stream_data');
 | 
			
		||||
@@ -347,7 +347,7 @@ run_test('is_active', () => {
 | 
			
		||||
        message_id: 108,
 | 
			
		||||
        topic_name: 'topic2',
 | 
			
		||||
    };
 | 
			
		||||
    topic_data.add_message(opts);
 | 
			
		||||
    stream_topic_history.add_message(opts);
 | 
			
		||||
 | 
			
		||||
    assert(stream_data.is_active(sub));
 | 
			
		||||
 | 
			
		||||
@@ -375,7 +375,7 @@ run_test('is_active', () => {
 | 
			
		||||
 | 
			
		||||
    assert(stream_data.is_active(sub));
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message(opts);
 | 
			
		||||
    stream_topic_history.add_message(opts);
 | 
			
		||||
 | 
			
		||||
    assert(stream_data.is_active(sub));
 | 
			
		||||
 | 
			
		||||
@@ -397,7 +397,7 @@ run_test('is_active', () => {
 | 
			
		||||
    sub.pin_to_top = true;
 | 
			
		||||
    assert(stream_data.is_active(sub));
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message(opts);
 | 
			
		||||
    stream_topic_history.add_message(opts);
 | 
			
		||||
 | 
			
		||||
    assert(stream_data.is_active(sub));
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,6 @@ set_global('$', global.make_zjquery());
 | 
			
		||||
 | 
			
		||||
zrequire('unread_ui');
 | 
			
		||||
zrequire('Filter', 'js/filter');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_sort');
 | 
			
		||||
zrequire('colorspace');
 | 
			
		||||
zrequire('stream_color');
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
 | 
			
		||||
zrequire('unread');
 | 
			
		||||
zrequire('stream_data');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_topic_history');
 | 
			
		||||
 | 
			
		||||
set_global('channel', {});
 | 
			
		||||
set_global('message_list', {});
 | 
			
		||||
@@ -9,57 +9,57 @@ set_global('message_list', {});
 | 
			
		||||
run_test('basics', () => {
 | 
			
		||||
    const stream_id = 55;
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        message_id: 101,
 | 
			
		||||
        topic_name: 'toPic1',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    let history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    let history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['toPic1']);
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        message_id: 102,
 | 
			
		||||
        topic_name: 'Topic1',
 | 
			
		||||
    });
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['Topic1']);
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        message_id: 103,
 | 
			
		||||
        topic_name: 'topic2',
 | 
			
		||||
    });
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['topic2', 'Topic1']);
 | 
			
		||||
 | 
			
		||||
    // Removing first topic1 message has no effect.
 | 
			
		||||
    topic_data.remove_message({
 | 
			
		||||
    stream_topic_history.remove_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        topic_name: 'toPic1',
 | 
			
		||||
    });
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['topic2', 'Topic1']);
 | 
			
		||||
 | 
			
		||||
    // Removing second topic1 message removes the topic.
 | 
			
		||||
    topic_data.remove_message({
 | 
			
		||||
    stream_topic_history.remove_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        topic_name: 'Topic1',
 | 
			
		||||
    });
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['topic2']);
 | 
			
		||||
 | 
			
		||||
    // Test that duplicate remove does not crash us.
 | 
			
		||||
    topic_data.remove_message({
 | 
			
		||||
    stream_topic_history.remove_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        topic_name: 'Topic1',
 | 
			
		||||
    });
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['topic2']);
 | 
			
		||||
 | 
			
		||||
    // get to 100% coverage for defensive code
 | 
			
		||||
    topic_data.remove_message({
 | 
			
		||||
    stream_topic_history.remove_message({
 | 
			
		||||
        stream_id: 9999999,
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
@@ -83,7 +83,7 @@ run_test('is_complete_for_stream_id', () => {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    assert.equal(
 | 
			
		||||
        topic_data.is_complete_for_stream_id(sub.stream_id),
 | 
			
		||||
        stream_topic_history.is_complete_for_stream_id(sub.stream_id),
 | 
			
		||||
        true);
 | 
			
		||||
 | 
			
		||||
    // Now simulate a more recent message id.
 | 
			
		||||
@@ -94,15 +94,15 @@ run_test('is_complete_for_stream_id', () => {
 | 
			
		||||
    // Note that we'll return `true` here due to
 | 
			
		||||
    // fetched_stream_ids having the stream_id now.
 | 
			
		||||
    assert.equal(
 | 
			
		||||
        topic_data.is_complete_for_stream_id(sub.stream_id),
 | 
			
		||||
        stream_topic_history.is_complete_for_stream_id(sub.stream_id),
 | 
			
		||||
        true);
 | 
			
		||||
 | 
			
		||||
    // But now clear the data to see what we'd have without
 | 
			
		||||
    // the previous call.
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
    assert.equal(
 | 
			
		||||
        topic_data.is_complete_for_stream_id(sub.stream_id),
 | 
			
		||||
        stream_topic_history.is_complete_for_stream_id(sub.stream_id),
 | 
			
		||||
        false);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@@ -117,20 +117,20 @@ run_test('server_history', () => {
 | 
			
		||||
    message_list.all.fetch_status.has_found_newest = () => false;
 | 
			
		||||
 | 
			
		||||
    assert.equal(
 | 
			
		||||
        topic_data.is_complete_for_stream_id(stream_id),
 | 
			
		||||
        stream_topic_history.is_complete_for_stream_id(stream_id),
 | 
			
		||||
        false);
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        message_id: 501,
 | 
			
		||||
        topic_name: 'local',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    function add_server_history() {
 | 
			
		||||
        topic_data.add_history(stream_id, [
 | 
			
		||||
            { name: 'local', max_id: 501 },
 | 
			
		||||
            { name: 'hist2', max_id: 31 },
 | 
			
		||||
            { name: 'hist1', max_id: 30 },
 | 
			
		||||
        stream_topic_history.add_history(stream_id, [
 | 
			
		||||
            { topic_name: 'local', max_id: 501 },
 | 
			
		||||
            { topic_name: 'hist2', max_id: 31 },
 | 
			
		||||
            { topic_name: 'hist1', max_id: 30 },
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -139,73 +139,73 @@ run_test('server_history', () => {
 | 
			
		||||
    // Since we added history, now subsequent calls
 | 
			
		||||
    // to is_complete_for_stream_id will return true.
 | 
			
		||||
    assert.equal(
 | 
			
		||||
        topic_data.is_complete_for_stream_id(stream_id),
 | 
			
		||||
        stream_topic_history.is_complete_for_stream_id(stream_id),
 | 
			
		||||
        true);
 | 
			
		||||
 | 
			
		||||
    let history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    let history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['local', 'hist2', 'hist1']);
 | 
			
		||||
 | 
			
		||||
    // If new activity comes in for historical messages,
 | 
			
		||||
    // they can bump to the front of the list.
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        message_id: 502,
 | 
			
		||||
        topic_name: 'hist1',
 | 
			
		||||
    });
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['hist1', 'local', 'hist2']);
 | 
			
		||||
 | 
			
		||||
    // server history is allowed to backdate hist1
 | 
			
		||||
    add_server_history();
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['local', 'hist2', 'hist1']);
 | 
			
		||||
 | 
			
		||||
    // Removing a local message removes the topic if we have
 | 
			
		||||
    // our counts right.
 | 
			
		||||
    topic_data.remove_message({
 | 
			
		||||
    stream_topic_history.remove_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        topic_name: 'local',
 | 
			
		||||
    });
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['hist2', 'hist1']);
 | 
			
		||||
 | 
			
		||||
    // We can try to remove a historical message, but it should
 | 
			
		||||
    // have no effect.
 | 
			
		||||
    topic_data.remove_message({
 | 
			
		||||
    stream_topic_history.remove_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        topic_name: 'hist2',
 | 
			
		||||
    });
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['hist2', 'hist1']);
 | 
			
		||||
 | 
			
		||||
    // If we call back to the server for history, the
 | 
			
		||||
    // effect is always additive.  We may decide to prune old
 | 
			
		||||
    // topics in the future, if they dropped off due to renames,
 | 
			
		||||
    // but that is probably an edge case we can ignore for now.
 | 
			
		||||
    topic_data.add_history(stream_id, [
 | 
			
		||||
        { name: 'hist2', max_id: 931 },
 | 
			
		||||
        { name: 'hist3', max_id: 5 },
 | 
			
		||||
    stream_topic_history.add_history(stream_id, [
 | 
			
		||||
        { topic_name: 'hist2', max_id: 931 },
 | 
			
		||||
        { topic_name: 'hist3', max_id: 5 },
 | 
			
		||||
    ]);
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['hist2', 'hist1', 'hist3']);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
run_test('test_unread_logic', () => {
 | 
			
		||||
    const stream_id = 77;
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        message_id: 201,
 | 
			
		||||
        topic_name: 'toPic1',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        message_id: 45,
 | 
			
		||||
        topic_name: 'topic2',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    let history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    let history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['toPic1', 'topic2']);
 | 
			
		||||
 | 
			
		||||
    const msgs = [
 | 
			
		||||
@@ -223,39 +223,39 @@ run_test('test_unread_logic', () => {
 | 
			
		||||
 | 
			
		||||
    unread.process_loaded_messages(msgs);
 | 
			
		||||
 | 
			
		||||
    history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['toPic1', 'unread1', 'topic2', 'UNREAD2']);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
run_test('test_stream_has_topics', () => {
 | 
			
		||||
    const stream_id = 88;
 | 
			
		||||
 | 
			
		||||
    assert.equal(topic_data.stream_has_topics(stream_id), false);
 | 
			
		||||
    assert.equal(stream_topic_history.stream_has_topics(stream_id), false);
 | 
			
		||||
 | 
			
		||||
    topic_data.find_or_create(stream_id);
 | 
			
		||||
    stream_topic_history.find_or_create(stream_id);
 | 
			
		||||
 | 
			
		||||
    // This was a bug before--just creating a bucket does not
 | 
			
		||||
    // mean we have actual topics.
 | 
			
		||||
    assert.equal(topic_data.stream_has_topics(stream_id), false);
 | 
			
		||||
    assert.equal(stream_topic_history.stream_has_topics(stream_id), false);
 | 
			
		||||
 | 
			
		||||
    topic_data.add_message({
 | 
			
		||||
    stream_topic_history.add_message({
 | 
			
		||||
        stream_id: stream_id,
 | 
			
		||||
        message_id: 888,
 | 
			
		||||
        topic_name: 'whatever',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    assert.equal(topic_data.stream_has_topics(stream_id), true);
 | 
			
		||||
    assert.equal(stream_topic_history.stream_has_topics(stream_id), true);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
run_test('server_history_end_to_end', () => {
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
 | 
			
		||||
    const stream_id = 99;
 | 
			
		||||
 | 
			
		||||
    const topics = [
 | 
			
		||||
        { name: 'topic3', max_id: 501 },
 | 
			
		||||
        { name: 'topic2', max_id: 31 },
 | 
			
		||||
        { name: 'topic1', max_id: 30 },
 | 
			
		||||
        { topic_name: 'topic3', max_id: 501 },
 | 
			
		||||
        { topic_name: 'topic2', max_id: 31 },
 | 
			
		||||
        { topic_name: 'topic1', max_id: 30 },
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    let get_success_callback;
 | 
			
		||||
@@ -267,7 +267,7 @@ run_test('server_history_end_to_end', () => {
 | 
			
		||||
        get_success_callback = opts.success;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.get_server_history(stream_id, () => {
 | 
			
		||||
    stream_topic_history.get_server_history(stream_id, () => {
 | 
			
		||||
        on_success_called = true;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
@@ -275,7 +275,7 @@ run_test('server_history_end_to_end', () => {
 | 
			
		||||
 | 
			
		||||
    assert(on_success_called);
 | 
			
		||||
 | 
			
		||||
    const history = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    const history = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    assert.deepEqual(history, ['topic3', 'topic2', 'topic1']);
 | 
			
		||||
 | 
			
		||||
    // Try getting server history for a second time.
 | 
			
		||||
@@ -285,7 +285,7 @@ run_test('server_history_end_to_end', () => {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    on_success_called = false;
 | 
			
		||||
    topic_data.get_server_history(stream_id, () => {
 | 
			
		||||
    stream_topic_history.get_server_history(stream_id, () => {
 | 
			
		||||
        on_success_called = true;
 | 
			
		||||
    });
 | 
			
		||||
    assert(on_success_called);
 | 
			
		||||
@@ -5,7 +5,7 @@ set_global('pm_conversations', {
 | 
			
		||||
zrequire('muting');
 | 
			
		||||
zrequire('unread');
 | 
			
		||||
zrequire('stream_data');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_topic_history');
 | 
			
		||||
zrequire('stream_sort');
 | 
			
		||||
const tg = zrequire('topic_generator');
 | 
			
		||||
 | 
			
		||||
@@ -264,7 +264,7 @@ run_test('topics', () => {
 | 
			
		||||
        devel: devel_stream_id,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    topic_data.get_recent_names = function (stream_id) {
 | 
			
		||||
    stream_topic_history.get_recent_topic_names = function (stream_id) {
 | 
			
		||||
        switch (stream_id) {
 | 
			
		||||
        case muted_stream_id:
 | 
			
		||||
            return ['ms-topic1', 'ms-topic2'];
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ set_global('message_list', {});
 | 
			
		||||
zrequire('hash_util');
 | 
			
		||||
zrequire('stream_data');
 | 
			
		||||
zrequire('unread');
 | 
			
		||||
zrequire('topic_data');
 | 
			
		||||
zrequire('stream_topic_history');
 | 
			
		||||
const topic_list_data = zrequire('topic_list_data');
 | 
			
		||||
 | 
			
		||||
const general = {
 | 
			
		||||
@@ -18,7 +18,7 @@ stream_data.add_sub(general);
 | 
			
		||||
 | 
			
		||||
function clear() {
 | 
			
		||||
    narrow_state.topic = () => undefined;
 | 
			
		||||
    topic_data.reset();
 | 
			
		||||
    stream_topic_history.reset();
 | 
			
		||||
    muting.is_topic_muted = () => false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -28,7 +28,7 @@ function get_list_info(zoomed) {
 | 
			
		||||
        stream_id, zoomed);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
run_test('get_list_info w/real topic_data', () => {
 | 
			
		||||
run_test('get_list_info w/real stream_topic_history', () => {
 | 
			
		||||
    clear();
 | 
			
		||||
 | 
			
		||||
    let list_info;
 | 
			
		||||
@@ -42,7 +42,7 @@ run_test('get_list_info w/real topic_data', () => {
 | 
			
		||||
 | 
			
		||||
    for (const i of _.range(7)) {
 | 
			
		||||
        const topic_name = 'topic ' + i;
 | 
			
		||||
        topic_data.add_message({
 | 
			
		||||
        stream_topic_history.add_message({
 | 
			
		||||
            stream_id: general.stream_id,
 | 
			
		||||
            topic_name: topic_name,
 | 
			
		||||
            message_id: 1000 + i,
 | 
			
		||||
@@ -78,9 +78,9 @@ run_test('get_list_info unreads', () => {
 | 
			
		||||
 | 
			
		||||
    let list_info;
 | 
			
		||||
 | 
			
		||||
    // Going forward, we just stub get_recent_names
 | 
			
		||||
    // Going forward, we just stub get_recent_topic_names
 | 
			
		||||
    // for simpler test setup.
 | 
			
		||||
    topic_data.get_recent_names = () => {
 | 
			
		||||
    stream_topic_history.get_recent_topic_names = () => {
 | 
			
		||||
        return _.range(15).map(i => 'topic ' + i);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -90,7 +90,7 @@ import "../upload.js";
 | 
			
		||||
import "../color_data.js";
 | 
			
		||||
import "../stream_color.js";
 | 
			
		||||
import "../stream_data.js";
 | 
			
		||||
import "../topic_data.js";
 | 
			
		||||
import "../stream_topic_history.js";
 | 
			
		||||
import "../stream_muting.js";
 | 
			
		||||
import "../stream_events.js";
 | 
			
		||||
import "../stream_create.js";
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,7 @@ exports.topics_seen_for = function (stream_name) {
 | 
			
		||||
    if (!stream_id) {
 | 
			
		||||
        return [];
 | 
			
		||||
    }
 | 
			
		||||
    const topic_names = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    const topic_names = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
    return topic_names;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -192,14 +192,14 @@ exports.edit_locally = function (message, request) {
 | 
			
		||||
 | 
			
		||||
    if (request.new_topic !== undefined) {
 | 
			
		||||
        const new_topic = request.new_topic;
 | 
			
		||||
        topic_data.remove_message({
 | 
			
		||||
        stream_topic_history.remove_message({
 | 
			
		||||
            stream_id: message.stream_id,
 | 
			
		||||
            topic_name: message.topic,
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        message.topic = new_topic;
 | 
			
		||||
 | 
			
		||||
        topic_data.add_message({
 | 
			
		||||
        stream_topic_history.add_message({
 | 
			
		||||
            stream_id: message.stream_id,
 | 
			
		||||
            topic_name: message.topic,
 | 
			
		||||
            message_id: message.id,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -153,7 +153,7 @@ declare let templates: any;
 | 
			
		||||
declare let tictactoe_widget: any;
 | 
			
		||||
declare let timerender: any;
 | 
			
		||||
declare let todo_widget: any;
 | 
			
		||||
declare let topic_data: any;
 | 
			
		||||
declare let stream_topic_history: any;
 | 
			
		||||
declare let topic_generator: any;
 | 
			
		||||
declare let topic_list: any;
 | 
			
		||||
declare let topic_zoom: any;
 | 
			
		||||
 
 | 
			
		||||
@@ -229,7 +229,7 @@ exports.update_messages = function update_messages(events) {
 | 
			
		||||
 | 
			
		||||
                // Remove the recent topics entry for the old topics;
 | 
			
		||||
                // must be called before we call set_message_topic.
 | 
			
		||||
                topic_data.remove_message({
 | 
			
		||||
                stream_topic_history.remove_message({
 | 
			
		||||
                    stream_id: msg.stream_id,
 | 
			
		||||
                    topic_name: msg.topic,
 | 
			
		||||
                });
 | 
			
		||||
@@ -251,7 +251,7 @@ exports.update_messages = function update_messages(events) {
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Add the recent topics entry for the new stream/topics.
 | 
			
		||||
                topic_data.add_message({
 | 
			
		||||
                stream_topic_history.add_message({
 | 
			
		||||
                    stream_id: msg.stream_id,
 | 
			
		||||
                    topic_name: msg.topic,
 | 
			
		||||
                    message_id: msg.id,
 | 
			
		||||
 
 | 
			
		||||
@@ -169,7 +169,7 @@ exports.add_message_metadata = function (message) {
 | 
			
		||||
        message.stream = message.display_recipient;
 | 
			
		||||
        message.reply_to = message.sender_email;
 | 
			
		||||
 | 
			
		||||
        topic_data.add_message({
 | 
			
		||||
        stream_topic_history.add_message({
 | 
			
		||||
            stream_id: message.stream_id,
 | 
			
		||||
            topic_name: message.topic,
 | 
			
		||||
            message_id: message.id,
 | 
			
		||||
 
 | 
			
		||||
@@ -701,7 +701,7 @@ exports.to_compose_target = function () {
 | 
			
		||||
        }
 | 
			
		||||
        // If we are composing to a new topic, we narrow to the stream but
 | 
			
		||||
        // grey-out the message view instead of narrowing to an empty view.
 | 
			
		||||
        const topics = topic_data.get_recent_names(stream_id);
 | 
			
		||||
        const topics = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
        const operators = [{operator: 'stream', operand: stream_name}];
 | 
			
		||||
        const topic = compose_state.topic();
 | 
			
		||||
        if (topics.includes(topic)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -337,7 +337,7 @@ function get_topic_suggestions(last, operators) {
 | 
			
		||||
        return [];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let topics = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    let topics = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
 | 
			
		||||
    if (!topics || !topics.length) {
 | 
			
		||||
        return [];
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
 | 
			
		||||
        // So double marking something as read would not occur
 | 
			
		||||
        unread_ops.process_read_messages_event([msg_id]);
 | 
			
		||||
        if (event.message_type === 'stream') {
 | 
			
		||||
            topic_data.remove_message({
 | 
			
		||||
            stream_topic_history.remove_message({
 | 
			
		||||
                stream_id: event.stream_id,
 | 
			
		||||
                topic_name: event.topic,
 | 
			
		||||
            });
 | 
			
		||||
 
 | 
			
		||||
@@ -142,7 +142,7 @@ exports.is_active = function (sub) {
 | 
			
		||||
        // to set_filter_out_inactives.
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    return topic_data.stream_has_topics(sub.stream_id) || sub.newly_subscribed;
 | 
			
		||||
    return stream_topic_history.stream_has_topics(sub.stream_id) || sub.newly_subscribed;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.rename_sub = function (sub, new_name) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
const FoldDict = require('./fold_dict').FoldDict;
 | 
			
		||||
 | 
			
		||||
const stream_dict = new Map(); // stream_id -> topic_history object
 | 
			
		||||
const stream_dict = new Map(); // stream_id -> per_stream_history object
 | 
			
		||||
const fetched_stream_ids = new Set();
 | 
			
		||||
 | 
			
		||||
exports.is_complete_for_stream_id = (stream_id) => {
 | 
			
		||||
@@ -42,12 +42,13 @@ exports.stream_has_topics = function (stream_id) {
 | 
			
		||||
    return history.has_topics();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.topic_history = function (stream_id) {
 | 
			
		||||
exports.per_stream_history = function (stream_id) {
 | 
			
		||||
    /*
 | 
			
		||||
        Each stream has a dictionary of topics.
 | 
			
		||||
        The main getter of this object is
 | 
			
		||||
        get_recent_names, and we just sort on
 | 
			
		||||
        the fly every time we are called.
 | 
			
		||||
        get_recent_topic_names, and we just
 | 
			
		||||
        sort on the fly every time we are
 | 
			
		||||
        called.
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    const topics = new FoldDict();
 | 
			
		||||
@@ -59,17 +60,17 @@ exports.topic_history = function (stream_id) {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    self.add_or_update = function (opts) {
 | 
			
		||||
        const name = opts.name;
 | 
			
		||||
        const topic_name = opts.topic_name;
 | 
			
		||||
        let message_id = opts.message_id || 0;
 | 
			
		||||
 | 
			
		||||
        message_id = parseInt(message_id, 10);
 | 
			
		||||
 | 
			
		||||
        const existing = topics.get(name);
 | 
			
		||||
        const existing = topics.get(topic_name);
 | 
			
		||||
 | 
			
		||||
        if (!existing) {
 | 
			
		||||
            topics.set(opts.name, {
 | 
			
		||||
            topics.set(opts.topic_name, {
 | 
			
		||||
                message_id: message_id,
 | 
			
		||||
                pretty_name: name,
 | 
			
		||||
                pretty_name: topic_name,
 | 
			
		||||
                historical: false,
 | 
			
		||||
                count: 1,
 | 
			
		||||
            });
 | 
			
		||||
@@ -82,7 +83,7 @@ exports.topic_history = function (stream_id) {
 | 
			
		||||
 | 
			
		||||
        if (message_id > existing.message_id) {
 | 
			
		||||
            existing.message_id = message_id;
 | 
			
		||||
            existing.pretty_name = name;
 | 
			
		||||
            existing.pretty_name = topic_name;
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@@ -114,10 +115,10 @@ exports.topic_history = function (stream_id) {
 | 
			
		||||
        // client can maintain for newer topics.
 | 
			
		||||
 | 
			
		||||
        for (const obj of server_history) {
 | 
			
		||||
            const name = obj.name;
 | 
			
		||||
            const topic_name = obj.topic_name;
 | 
			
		||||
            const message_id = obj.max_id;
 | 
			
		||||
 | 
			
		||||
            const existing = topics.get(name);
 | 
			
		||||
            const existing = topics.get(topic_name);
 | 
			
		||||
 | 
			
		||||
            if (existing) {
 | 
			
		||||
                if (!existing.historical) {
 | 
			
		||||
@@ -131,15 +132,15 @@ exports.topic_history = function (stream_id) {
 | 
			
		||||
            // the topic for the first time, or we are getting
 | 
			
		||||
            // more current data for it.
 | 
			
		||||
 | 
			
		||||
            topics.set(name, {
 | 
			
		||||
            topics.set(topic_name, {
 | 
			
		||||
                message_id: message_id,
 | 
			
		||||
                pretty_name: name,
 | 
			
		||||
                pretty_name: topic_name,
 | 
			
		||||
                historical: true,
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    self.get_recent_names = function () {
 | 
			
		||||
    self.get_recent_topic_names = function () {
 | 
			
		||||
        const my_recents = Array.from(topics.values());
 | 
			
		||||
 | 
			
		||||
        const missing_topics = unread.get_missing_topics({
 | 
			
		||||
@@ -163,7 +164,7 @@ exports.topic_history = function (stream_id) {
 | 
			
		||||
 | 
			
		||||
exports.remove_message = function (opts) {
 | 
			
		||||
    const stream_id = opts.stream_id;
 | 
			
		||||
    const name = opts.topic_name;
 | 
			
		||||
    const topic_name = opts.topic_name;
 | 
			
		||||
    const history = stream_dict.get(stream_id);
 | 
			
		||||
 | 
			
		||||
    // This is the special case of "removing" a message from
 | 
			
		||||
@@ -174,14 +175,14 @@ exports.remove_message = function (opts) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // This is the normal case of an incoming message.
 | 
			
		||||
    history.maybe_remove(name);
 | 
			
		||||
    history.maybe_remove(topic_name);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.find_or_create = function (stream_id) {
 | 
			
		||||
    let history = stream_dict.get(stream_id);
 | 
			
		||||
 | 
			
		||||
    if (!history) {
 | 
			
		||||
        history = exports.topic_history(stream_id);
 | 
			
		||||
        history = exports.per_stream_history(stream_id);
 | 
			
		||||
        stream_dict.set(stream_id, history);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -191,12 +192,12 @@ exports.find_or_create = function (stream_id) {
 | 
			
		||||
exports.add_message = function (opts) {
 | 
			
		||||
    const stream_id = opts.stream_id;
 | 
			
		||||
    const message_id = opts.message_id;
 | 
			
		||||
    const name = opts.topic_name;
 | 
			
		||||
    const topic_name = opts.topic_name;
 | 
			
		||||
 | 
			
		||||
    const history = exports.find_or_create(stream_id);
 | 
			
		||||
 | 
			
		||||
    history.add_or_update({
 | 
			
		||||
        name: name,
 | 
			
		||||
        topic_name: topic_name,
 | 
			
		||||
        message_id: message_id,
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
@@ -226,10 +227,10 @@ exports.get_server_history = function (stream_id, on_success) {
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.get_recent_names = function (stream_id) {
 | 
			
		||||
exports.get_recent_topic_names = function (stream_id) {
 | 
			
		||||
    const history = exports.find_or_create(stream_id);
 | 
			
		||||
 | 
			
		||||
    return history.get_recent_names();
 | 
			
		||||
    return history.get_recent_topic_names();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.reset = function () {
 | 
			
		||||
@@ -238,4 +239,4 @@ exports.reset = function () {
 | 
			
		||||
    fetched_stream_ids.clear();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
window.topic_data = exports;
 | 
			
		||||
window.stream_topic_history = exports;
 | 
			
		||||
@@ -207,7 +207,7 @@ exports.get_next_topic = function (curr_stream, curr_topic) {
 | 
			
		||||
 | 
			
		||||
    function get_unmuted_topics(stream_name) {
 | 
			
		||||
        const stream_id = stream_data.get_stream_id(stream_name);
 | 
			
		||||
        let topics = topic_data.get_recent_names(stream_id);
 | 
			
		||||
        let topics = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
        topics = topics.filter(topic => !muting.is_topic_muted(stream_id, topic));
 | 
			
		||||
        return topics;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -129,7 +129,7 @@ exports.widget = function (parent_elem, my_stream_id) {
 | 
			
		||||
 | 
			
		||||
        const is_showing_all_possible_topics =
 | 
			
		||||
            list_info.items.length === num_possible_topics &&
 | 
			
		||||
            topic_data.is_complete_for_stream_id(my_stream_id);
 | 
			
		||||
            stream_topic_history.is_complete_for_stream_id(my_stream_id);
 | 
			
		||||
 | 
			
		||||
        const attrs = [
 | 
			
		||||
            ['class', 'topic-list'],
 | 
			
		||||
@@ -256,7 +256,7 @@ exports.zoom_in = function () {
 | 
			
		||||
    const spinner = true;
 | 
			
		||||
    active_widget.build(spinner);
 | 
			
		||||
 | 
			
		||||
    topic_data.get_server_history(stream_id, on_success);
 | 
			
		||||
    stream_topic_history.get_server_history(stream_id, on_success);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.initialize = function () {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ exports.get_list_info = function (stream_id, zoomed) {
 | 
			
		||||
        active_topic = active_topic.toLowerCase();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const topic_names = topic_data.get_recent_names(stream_id);
 | 
			
		||||
    const topic_names = stream_topic_history.get_recent_topic_names(stream_id);
 | 
			
		||||
 | 
			
		||||
    const items = [];
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user