mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
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:
@@ -1,5 +1,7 @@
|
|||||||
var topic_data = require('js/topic_data.js');
|
var topic_data = require('js/topic_data.js');
|
||||||
|
|
||||||
|
set_global('channel', {});
|
||||||
|
|
||||||
(function test_basics() {
|
(function test_basics() {
|
||||||
var stream_id = 55;
|
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']);
|
||||||
|
}());
|
||||||
|
|||||||
@@ -156,6 +156,20 @@ exports.add_history = function (stream_id, server_history) {
|
|||||||
history.add_history(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) {
|
exports.get_recent_names = function (stream_id) {
|
||||||
var history = stream_dict.get(stream_id);
|
var history = stream_dict.get(stream_id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user