mirror of https://github.com/zulip/zulip.git
Use local messages for more narrow searches.
We now try harder to find the first unread message in an upcoming narrow, which has the user-visible effect that we select the unread message before waiting for search results. Before this change, we only applied this logic to searches that were things like exactly stream/topic or exactly is-private. Now we will also handle things like stream/topic/sender. For the stream/topic piece we look up candidate unread ids using the steam/topic buckets in unread.js, but then we still filter those messages by stream/topic/sender as we look for the first unread id.
This commit is contained in:
parent
124192a3b9
commit
815f54cda4
|
@ -5,6 +5,9 @@ zrequire('unread');
|
|||
zrequire('util');
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
|
||||
set_global('message_store', {});
|
||||
set_global('page_params', {});
|
||||
|
||||
set_global('muting', {
|
||||
is_topic_muted: () => false,
|
||||
});
|
||||
|
@ -91,6 +94,10 @@ function candidate_ids() {
|
|||
assert_unread_info({flavor: 'not_found'});
|
||||
|
||||
unread.process_loaded_messages([stream_msg]);
|
||||
message_store.get = (msg_id) => {
|
||||
assert.equal(msg_id, stream_msg.id);
|
||||
return stream_msg;
|
||||
};
|
||||
|
||||
unread_ids = candidate_ids();
|
||||
assert.deepEqual(unread_ids, [stream_msg.id]);
|
||||
|
@ -131,9 +138,19 @@ function candidate_ids() {
|
|||
|
||||
unread.process_loaded_messages([private_msg]);
|
||||
|
||||
message_store.get = (msg_id) => {
|
||||
assert.equal(msg_id, private_msg.id);
|
||||
return private_msg;
|
||||
};
|
||||
|
||||
unread_ids = candidate_ids();
|
||||
assert.deepEqual(unread_ids, [private_msg.id]);
|
||||
|
||||
assert_unread_info({
|
||||
flavor: 'found',
|
||||
msg_id: private_msg.id,
|
||||
});
|
||||
|
||||
terms = [
|
||||
{operator: 'is', operand: 'private'},
|
||||
];
|
||||
|
@ -156,4 +173,14 @@ function candidate_ids() {
|
|||
set_filter(terms);
|
||||
unread_ids = candidate_ids();
|
||||
assert.deepEqual(unread_ids, []);
|
||||
|
||||
terms = [
|
||||
{operator: 'search', operand: 'needle'},
|
||||
];
|
||||
set_filter(terms);
|
||||
|
||||
blueslip.set_test_data('error', 'unexpected call to get_first_unread_info');
|
||||
assert_unread_info({
|
||||
flavor: 'cannot_compute',
|
||||
});
|
||||
}());
|
||||
|
|
|
@ -170,6 +170,15 @@ exports.pm_string = function () {
|
|||
};
|
||||
|
||||
exports.get_first_unread_info = function () {
|
||||
if ((current_filter === undefined) || !current_filter.can_apply_locally()) {
|
||||
// we expect our callers to make sure a "local" narrow
|
||||
// makes sense (and we don't yet support the all-messages view)
|
||||
blueslip.error('unexpected call to get_first_unread_info');
|
||||
return {
|
||||
flavor: 'cannot_compute',
|
||||
};
|
||||
}
|
||||
|
||||
var unread_ids = exports._possible_unread_message_ids();
|
||||
|
||||
if (unread_ids === undefined) {
|
||||
|
@ -179,12 +188,15 @@ exports.get_first_unread_info = function () {
|
|||
};
|
||||
}
|
||||
|
||||
if (unread_ids.length === 0) {
|
||||
var msg_id = current_filter.first_valid_id_from(unread_ids);
|
||||
|
||||
if (msg_id === undefined) {
|
||||
return {
|
||||
flavor: 'not_found',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
flavor: 'found',
|
||||
msg_id: unread_ids[0],
|
||||
|
@ -207,7 +219,7 @@ exports._possible_unread_message_ids = function () {
|
|||
var topic_name;
|
||||
var pm_string;
|
||||
|
||||
if (current_filter.is_exactly('stream', 'topic')) {
|
||||
if (current_filter.can_bucket_by('stream', 'topic')) {
|
||||
stream_id = exports.stream_id();
|
||||
if (stream_id === undefined) {
|
||||
return [];
|
||||
|
@ -216,7 +228,7 @@ exports._possible_unread_message_ids = function () {
|
|||
return unread.get_msg_ids_for_topic(stream_id, topic_name);
|
||||
}
|
||||
|
||||
if (current_filter.is_exactly('stream')) {
|
||||
if (current_filter.can_bucket_by('stream')) {
|
||||
stream_id = exports.stream_id();
|
||||
if (stream_id === undefined) {
|
||||
return [];
|
||||
|
@ -224,7 +236,7 @@ exports._possible_unread_message_ids = function () {
|
|||
return unread.get_msg_ids_for_stream(stream_id);
|
||||
}
|
||||
|
||||
if (current_filter.is_exactly('pm-with')) {
|
||||
if (current_filter.can_bucket_by('pm-with')) {
|
||||
pm_string = exports.pm_string();
|
||||
if (pm_string === undefined) {
|
||||
return [];
|
||||
|
@ -232,15 +244,15 @@ exports._possible_unread_message_ids = function () {
|
|||
return unread.get_msg_ids_for_person(pm_string);
|
||||
}
|
||||
|
||||
if (current_filter.is_exactly('is-private')) {
|
||||
if (current_filter.can_bucket_by('is-private')) {
|
||||
return unread.get_msg_ids_for_private();
|
||||
}
|
||||
|
||||
if (current_filter.is_exactly('is-mentioned')) {
|
||||
if (current_filter.can_bucket_by('is-mentioned')) {
|
||||
return unread.get_msg_ids_for_mentions();
|
||||
}
|
||||
|
||||
if (current_filter.is_exactly('is-starred')) {
|
||||
if (current_filter.can_bucket_by('is-starred')) {
|
||||
return unread.get_msg_ids_for_starred();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue