diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index ada2ad3773..9a62031f8d 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -432,16 +432,29 @@ init(); return 'office'; }; - global.stream_data.populate_stream_topics_for_tests({ - devel: [ - {subject: 'REXX'}, - ], - office: [ - {subject: 'team'}, - {subject: 'ignore'}, - {subject: 'test'}, - ], - }); + var devel_id = 44; + var office_id = 77; + + global.stream_data.get_stream_id = function (stream_name) { + switch (stream_name) { + case 'office': return office_id; + case 'devel': return devel_id; + } + }; + + var recent_data = {}; + + recent_data[devel_id] = [ + {subject: 'REXX'}, + ]; + + recent_data[office_id] = [ + {subject: 'team'}, + {subject: 'ignore'}, + {subject: 'test'}, + ]; + + global.stream_data.populate_stream_topics_for_tests(recent_data); suggestions = search.get_suggestions('te'); expected = [ diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index bf24b6eb49..f7dc89f35e 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -240,8 +240,17 @@ var people = global.people; }()); (function test_process_message_for_recent_topics() { + var stream_id = 55; + + var rome = { + name: 'Rome', + stream_id: stream_id, + }; + + stream_data.add_sub('Rome', rome); + var message = { - stream: 'Rome', + stream_id: stream_id, timestamp: 101, subject: 'toPic1', }; @@ -258,7 +267,7 @@ var people = global.people; ]); message = { - stream: 'Rome', + stream_id: stream_id, timestamp: 102, subject: 'Topic1', }; @@ -274,7 +283,7 @@ var people = global.people; ]); message = { - stream: 'Rome', + stream_id: stream_id, timestamp: 103, subject: 'topic2', }; @@ -321,13 +330,13 @@ var people = global.people; stream_data.unsubscribe_myself(sub); assert(!stream_data.is_active(sub)); - sub = {name: 'lunch', subscribed: false, stream_id: 1}; + sub = {name: 'lunch', subscribed: false, stream_id: 222}; stream_data.add_sub('lunch', sub); assert(!stream_data.is_active(sub)); var message = { - stream: 'lunch', + stream_id: 222, timestamp: 108, subject: 'topic2', }; diff --git a/frontend_tests/node_tests/topic_list.js b/frontend_tests/node_tests/topic_list.js index 9963681ac4..fc4e2caadb 100644 --- a/frontend_tests/node_tests/topic_list.js +++ b/frontend_tests/node_tests/topic_list.js @@ -19,19 +19,21 @@ var topic_list = require('js/topic_list.js'); global.compile_template('topic_list_item'); (function test_topic_list_build_widget() { + var stream_id = 555; var stream = "devel"; var active_topic = "testing"; var max_topics = 5; - var topics = [ + var recent_topics = {}; + recent_topics[stream_id] = [ {subject: "coding"}, ]; - global.stream_data.populate_stream_topics_for_tests({devel: topics}); + global.stream_data.populate_stream_topics_for_tests(recent_topics); global.unread.num_unread_for_subject = function () { return 1; }; - global.stream_data.get_stream_id = function () { return 99; }; + global.stream_data.get_stream_id = function () { return stream_id; }; var parent_elem = $('
'); var widget = topic_list.build_widget(parent_elem, stream, active_topic, max_topics); diff --git a/static/js/stream_data.js b/static/js/stream_data.js index 2336198314..8c1cc170db 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -7,7 +7,7 @@ var exports = {}; // Call clear_subscriptions() to initialize it. var stream_info; var subs_by_stream_id; -var recent_topics = new Dict({fold_case: true}); +var recent_topics = new Dict(); // stream_id -> array of objects var stream_ids_by_name = new Dict({fold_case: true}); @@ -21,7 +21,7 @@ exports.clear_subscriptions = function () { exports.clear_subscriptions(); exports.is_active = function (sub) { - return recent_topics.has(sub.name) || sub.newly_subscribed; + return recent_topics.has(sub.stream_id) || sub.newly_subscribed; }; exports.rename_sub = function (sub, new_name) { @@ -367,23 +367,19 @@ exports.process_message_for_recent_topics = function process_message_for_recent_ message, remove_message) { var current_timestamp = 0; var count = 0; - var stream = message.stream; + var stream_id = message.stream_id; var canon_subject = exports.canonicalized_name(message.subject); - if (! recent_topics.has(stream)) { - recent_topics.set(stream, []); - } else { - recent_topics.set(stream, _.filter(recent_topics.get(stream), function (item) { - var is_duplicate = (item.canon_subject.toLowerCase() === canon_subject.toLowerCase()); - if (is_duplicate) { - current_timestamp = item.timestamp; - count = item.count; - } - return !is_duplicate; - })); - } + var recents = recent_topics.get(stream_id) || []; - var recents = recent_topics.get(stream); + recents = _.filter(recents, function (item) { + var is_duplicate = (item.canon_subject.toLowerCase() === canon_subject.toLowerCase()); + if (is_duplicate) { + current_timestamp = item.timestamp; + count = item.count; + } + return !is_duplicate; + }); if (remove_message !== undefined) { count = count - 1; @@ -402,7 +398,7 @@ exports.process_message_for_recent_topics = function process_message_for_recent_ return b.timestamp - a.timestamp; }); - recent_topics.set(stream, recents); + recent_topics.set(stream_id, recents); }; exports.get_streams_for_settings_page = function () { @@ -451,12 +447,17 @@ exports.initialize_from_page_params = function () { }; exports.get_recent_topics = function (stream_name) { - return recent_topics.get(stream_name); + var stream_id = exports.get_stream_id(stream_name); + if (!stream_id) { + return []; + } + + return recent_topics.get(stream_id); }; exports.populate_stream_topics_for_tests = function (stream_map) { // This is only used by tests. - recent_topics = Dict.from(stream_map, {fold_case: true}); + recent_topics = Dict.from(stream_map); }; exports.get_newbie_stream = function () {