mirror of https://github.com/zulip/zulip.git
parent
9b4a4d09ea
commit
0dea143fcf
|
@ -96,6 +96,7 @@ composebox_typeahead.add_topic = noop;
|
|||
|
||||
// We can also bring in real code:
|
||||
zrequire('recent_senders');
|
||||
zrequire('unread');
|
||||
zrequire('topic_data');
|
||||
|
||||
// And finally require the module that we will test directly:
|
||||
|
@ -124,7 +125,6 @@ run_test('message_store', () => {
|
|||
|
||||
// Tracking unread messages is a very fundamental part of the Zulip
|
||||
// app, and we use the unread object to track unread messages.
|
||||
zrequire('unread');
|
||||
|
||||
run_test('unread', () => {
|
||||
const stream_id = denmark_stream.stream_id;
|
||||
|
|
|
@ -6,6 +6,7 @@ zrequire('narrow_state');
|
|||
zrequire('stream_data');
|
||||
zrequire('topic_data');
|
||||
zrequire('people');
|
||||
zrequire('unread');
|
||||
var search = zrequire('search_suggestion');
|
||||
|
||||
var bob = {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
zrequire('unread');
|
||||
zrequire('topic_data');
|
||||
|
||||
set_global('channel', {});
|
||||
|
@ -126,7 +127,42 @@ run_test('server_history', () => {
|
|||
assert.deepEqual(history, ['hist2', 'hist1', 'hist3']);
|
||||
});
|
||||
|
||||
(function test_unread_logic() {
|
||||
var stream_id = 77;
|
||||
|
||||
topic_data.add_message({
|
||||
stream_id: stream_id,
|
||||
message_id: 201,
|
||||
topic_name: 'toPic1',
|
||||
});
|
||||
|
||||
topic_data.add_message({
|
||||
stream_id: stream_id,
|
||||
message_id: 45,
|
||||
topic_name: 'topic2',
|
||||
});
|
||||
|
||||
var history = topic_data.get_recent_names(stream_id);
|
||||
assert.deepEqual(history, ['toPic1', 'topic2']);
|
||||
|
||||
const msgs = [
|
||||
{ id: 150, subject: 'TOPIC2' }, // will be ignored
|
||||
{ id: 61, subject: 'unread1' },
|
||||
{ id: 60, subject: 'unread1' },
|
||||
{ id: 20, subject: 'UNREAD2' },
|
||||
];
|
||||
|
||||
_.each(msgs, (msg) => {
|
||||
msg.type = 'stream';
|
||||
msg.stream_id = stream_id;
|
||||
msg.unread = true;
|
||||
});
|
||||
|
||||
unread.process_loaded_messages(msgs);
|
||||
|
||||
history = topic_data.get_recent_names(stream_id);
|
||||
assert.deepEqual(history, ['toPic1', 'unread1', 'topic2', 'UNREAD2']);
|
||||
}());
|
||||
|
||||
run_test('server_history_end_to_end', () => {
|
||||
topic_data.reset();
|
||||
|
|
|
@ -11,6 +11,7 @@ set_global('templates', {});
|
|||
zrequire('hash_util');
|
||||
zrequire('narrow');
|
||||
zrequire('stream_data');
|
||||
zrequire('unread');
|
||||
zrequire('topic_data');
|
||||
zrequire('topic_list');
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ exports.stream_has_topics = function (stream_id) {
|
|||
return stream_dict.has(stream_id);
|
||||
};
|
||||
|
||||
exports.topic_history = function () {
|
||||
exports.topic_history = function (stream_id) {
|
||||
var topics = new Dict({fold_case: true});
|
||||
|
||||
var self = {};
|
||||
|
@ -95,7 +95,14 @@ exports.topic_history = function () {
|
|||
};
|
||||
|
||||
self.get_recent_names = function () {
|
||||
var recents = topics.values();
|
||||
var my_recents = topics.values();
|
||||
|
||||
var missing_topics = unread.get_missing_topics({
|
||||
stream_id: stream_id,
|
||||
topic_dict: topics,
|
||||
});
|
||||
|
||||
var recents = my_recents.concat(missing_topics);
|
||||
|
||||
recents.sort(function (a, b) {
|
||||
return b.message_id - a.message_id;
|
||||
|
@ -131,7 +138,7 @@ exports.find_or_create = function (stream_id) {
|
|||
var history = stream_dict.get(stream_id);
|
||||
|
||||
if (!history) {
|
||||
history = exports.topic_history();
|
||||
history = exports.topic_history(stream_id);
|
||||
stream_dict.set(stream_id, history);
|
||||
}
|
||||
|
||||
|
@ -171,11 +178,7 @@ exports.get_server_history = function (stream_id, on_success) {
|
|||
};
|
||||
|
||||
exports.get_recent_names = function (stream_id) {
|
||||
var history = stream_dict.get(stream_id);
|
||||
|
||||
if (!history) {
|
||||
return [];
|
||||
}
|
||||
var history = exports.find_or_create(stream_id);
|
||||
|
||||
return history.get_recent_names();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue