Add stream_data.get_recent_topics().

This removes the last remaining references to
stream_data.recent_subjects() outside of stream_data.js.
This commit is contained in:
Steve Howell
2016-10-28 09:47:57 -07:00
committed by Tim Abbott
parent 6a54dfc127
commit 0a4579711d
4 changed files with 12 additions and 8 deletions

View File

@@ -157,7 +157,7 @@ var stream_data = require('js/stream_data.js');
}; };
stream_data.process_message_for_recent_topics(message); stream_data.process_message_for_recent_topics(message);
var history = stream_data.recent_subjects.get('Rome'); var history = stream_data.get_recent_topics('Rome');
assert.deepEqual(history, [ assert.deepEqual(history, [
{ {
subject: 'toPic1', subject: 'toPic1',
@@ -173,7 +173,7 @@ var stream_data = require('js/stream_data.js');
subject: 'Topic1' subject: 'Topic1'
}; };
stream_data.process_message_for_recent_topics(message); stream_data.process_message_for_recent_topics(message);
history = stream_data.recent_subjects.get('Rome'); history = stream_data.get_recent_topics('Rome');
assert.deepEqual(history, [ assert.deepEqual(history, [
{ {
subject: 'Topic1', subject: 'Topic1',
@@ -189,7 +189,7 @@ var stream_data = require('js/stream_data.js');
subject: 'topic2' subject: 'topic2'
}; };
stream_data.process_message_for_recent_topics(message); stream_data.process_message_for_recent_topics(message);
history = stream_data.recent_subjects.get('Rome'); history = stream_data.get_recent_topics('Rome');
assert.deepEqual(history, [ assert.deepEqual(history, [
{ {
subject: 'topic2', subject: 'topic2',
@@ -206,7 +206,7 @@ var stream_data = require('js/stream_data.js');
]); ]);
stream_data.process_message_for_recent_topics(message, true); stream_data.process_message_for_recent_topics(message, true);
history = stream_data.recent_subjects.get('Rome'); history = stream_data.get_recent_topics('Rome');
assert.deepEqual(history, [ assert.deepEqual(history, [
{ {
subject: 'Topic1', subject: 'Topic1',

View File

@@ -254,7 +254,7 @@ function get_topic_suggestions(query_operators) {
return []; return [];
} }
var topics = stream_data.recent_subjects.get(stream); var topics = stream_data.get_recent_topics(stream);
stream = stream_data.get_name(stream); stream = stream_data.get_name(stream);
@@ -262,8 +262,8 @@ function get_topic_suggestions(query_operators) {
return []; return [];
} }
// Be defensive here in case stream_data.recent_subjects gets super huge, but // Be defensive here in case stream_data.get_recent_topics gets
// still slice off enough topics to find matches. // super huge, but still slice off enough topics to find matches.
topics = topics.slice(0, 300); topics = topics.slice(0, 300);
topics = _.map(topics, function (topic) { topics = _.map(topics, function (topic) {

View File

@@ -324,6 +324,10 @@ exports.initialize_from_page_params = function () {
delete page_params.email_dict; delete page_params.email_dict;
}; };
exports.get_recent_topics = function (stream_name) {
return exports.recent_subjects.get(stream_name);
};
exports.populate_stream_topics_for_tests = function (stream_map) { exports.populate_stream_topics_for_tests = function (stream_map) {
// This is only used by tests. // This is only used by tests.
exports.recent_subjects = new Dict.from(stream_map, {fold_case: true}); exports.recent_subjects = new Dict.from(stream_map, {fold_case: true});

View File

@@ -56,7 +56,7 @@ exports.set_count = function (stream_li, topic, count) {
}; };
exports.build_list = function (stream, active_topic, max_topics) { exports.build_list = function (stream, active_topic, max_topics) {
var subjects = stream_data.recent_subjects.get(stream) || []; var subjects = stream_data.get_recent_topics(stream) || [];
if (active_topic) { if (active_topic) {
active_topic = active_topic.toLowerCase(); active_topic = active_topic.toLowerCase();