Use unread data in topic_data.get_recent_names().

Fixes #9347.
This commit is contained in:
Steve Howell 2018-05-13 10:17:00 +00:00 committed by Tim Abbott
parent 9b4a4d09ea
commit 0dea143fcf
5 changed files with 50 additions and 9 deletions

View File

@ -96,6 +96,7 @@ composebox_typeahead.add_topic = noop;
// We can also bring in real code: // We can also bring in real code:
zrequire('recent_senders'); zrequire('recent_senders');
zrequire('unread');
zrequire('topic_data'); zrequire('topic_data');
// And finally require the module that we will test directly: // 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 // Tracking unread messages is a very fundamental part of the Zulip
// app, and we use the unread object to track unread messages. // app, and we use the unread object to track unread messages.
zrequire('unread');
run_test('unread', () => { run_test('unread', () => {
const stream_id = denmark_stream.stream_id; const stream_id = denmark_stream.stream_id;

View File

@ -6,6 +6,7 @@ zrequire('narrow_state');
zrequire('stream_data'); zrequire('stream_data');
zrequire('topic_data'); zrequire('topic_data');
zrequire('people'); zrequire('people');
zrequire('unread');
var search = zrequire('search_suggestion'); var search = zrequire('search_suggestion');
var bob = { var bob = {

View File

@ -1,3 +1,4 @@
zrequire('unread');
zrequire('topic_data'); zrequire('topic_data');
set_global('channel', {}); set_global('channel', {});
@ -126,7 +127,42 @@ run_test('server_history', () => {
assert.deepEqual(history, ['hist2', 'hist1', 'hist3']); 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', () => { run_test('server_history_end_to_end', () => {
topic_data.reset(); topic_data.reset();

View File

@ -11,6 +11,7 @@ set_global('templates', {});
zrequire('hash_util'); zrequire('hash_util');
zrequire('narrow'); zrequire('narrow');
zrequire('stream_data'); zrequire('stream_data');
zrequire('unread');
zrequire('topic_data'); zrequire('topic_data');
zrequire('topic_list'); zrequire('topic_list');

View File

@ -8,7 +8,7 @@ exports.stream_has_topics = function (stream_id) {
return stream_dict.has(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 topics = new Dict({fold_case: true});
var self = {}; var self = {};
@ -95,7 +95,14 @@ exports.topic_history = function () {
}; };
self.get_recent_names = 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) { recents.sort(function (a, b) {
return b.message_id - a.message_id; 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); var history = stream_dict.get(stream_id);
if (!history) { if (!history) {
history = exports.topic_history(); history = exports.topic_history(stream_id);
stream_dict.set(stream_id, history); 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) { exports.get_recent_names = function (stream_id) {
var history = stream_dict.get(stream_id); var history = exports.find_or_create(stream_id);
if (!history) {
return [];
}
return history.get_recent_names(); return history.get_recent_names();
}; };