Add topic_data.get_server_history().

This isn't connected to anything yet, but you can now get
all the historical topics for a stream by calling
topic_data.get_server_history().
This commit is contained in:
Steve Howell
2017-08-08 13:54:07 -04:00
committed by showell
parent 9bbcb712ec
commit 3b88e592d0
2 changed files with 47 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
var topic_data = require('js/topic_data.js');
set_global('channel', {});
(function test_basics() {
var stream_id = 55;
@@ -126,3 +128,34 @@ var topic_data = require('js/topic_data.js');
(function test_server_history_end_to_end() {
topic_data.reset();
var stream_id = 99;
var topics = [
{ name: 'topic3', max_id: 501 },
{ name: 'topic2', max_id: 31 },
{ name: 'topic1', max_id: 30 },
];
var get_success_callback;
var on_success_called;
channel.get = function (opts) {
assert.equal(opts.url, '/json/users/me/99/topics');
assert.deepEqual(opts.data, {});
get_success_callback = opts.success;
};
topic_data.get_server_history(stream_id, function () {
on_success_called = true;
});
get_success_callback({topics: topics});
assert(on_success_called);
var history = topic_data.get_recent_names(stream_id);
assert.deepEqual(history, ['topic3', 'topic2', 'topic1']);
}());

View File

@@ -156,6 +156,20 @@ exports.add_history = function (stream_id, server_history) {
history.add_history(server_history);
};
exports.get_server_history = function (stream_id, on_success) {
var url = '/json/users/me/' + stream_id + '/topics';
channel.get({
url: url,
data: {},
success: function (data) {
var server_history = data.topics;
exports.add_history(stream_id, server_history);
on_success();
},
});
};
exports.get_recent_names = function (stream_id) {
var history = stream_dict.get(stream_id);