Add topic_generator.get_next_topic().

This commit is contained in:
Steve Howell
2017-04-21 11:36:12 -07:00
committed by Tim Abbott
parent 079885770b
commit 6ddbf12376
2 changed files with 55 additions and 0 deletions

View File

@@ -1,3 +1,9 @@
add_dependencies({
stream_data: 'js/stream_data',
stream_sort: 'js/stream_sort',
unread: 'js/unread',
});
var tg = require('js/topic_generator.js'); var tg = require('js/topic_generator.js');
function is_even(i) { return i % 2 === 0; } function is_even(i) { return i % 2 === 0; }
@@ -143,4 +149,33 @@ function is_odd(i) { return i % 2 === 1; }
{stream: 1, topic: '1a'}); {stream: 1, topic: '1a'});
assert.deepEqual(next_topic(undefined, undefined), assert.deepEqual(next_topic(undefined, undefined),
{stream: 1, topic: '1a'}); {stream: 1, topic: '1a'});
// Now test the deeper function that is wired up to
// real functions stream_data/stream_sort/unread.
var curr_stream = 'announce';
var curr_topic = 'whatever';
global.stream_sort.get_streams = function () {
return ['announce', 'devel', 'test here'];
};
global.stream_data.get_recent_topics = function (stream) {
if (stream === 'devel') {
return [
{subject: 'javascript'},
{subject: 'python'},
];
}
};
global.unread.topic_has_any_unread = function (stream, topic) {
return (stream === 'devel' && topic === 'python');
};
var next_item = tg.get_next_topic(curr_stream, curr_topic);
assert.deepEqual(next_item, {
stream: 'devel',
topic: 'python',
});
}()); }());

View File

@@ -155,6 +155,26 @@ exports.next_topic = function (streams, get_topics, has_unread_messages, curr_st
return outer_gen.next(); return outer_gen.next();
}; };
exports.get_next_topic = function (curr_stream, curr_topic) {
var my_streams = stream_sort.get_streams();
function get_topics(stream) {
var topics = stream_data.get_recent_topics(stream) || [];
return _.map(topics, function (obj) { return obj.subject; });
}
function has_unread_messages(stream, topic) {
return unread.topic_has_any_unread(stream, topic);
}
return exports.next_topic(
my_streams,
get_topics,
has_unread_messages,
curr_stream,
curr_topic
);
};
return exports; return exports;
}()); }());