Expand get_unread_ids() to all local narrows.

This commit makes it so that any query for
which we do a local filter leads to us
examining the full list of unread message
ids in our cache to find a potentially
unread message that passes the filter.  This
can often allow us to more immediately
jump to a new narrow with an appropriately
selected message.

Fixes #9319
This commit is contained in:
Steve Howell 2018-05-31 14:46:39 +00:00 committed by Tim Abbott
parent 4c235bfe65
commit 7642ed66cf
2 changed files with 37 additions and 1 deletions

View File

@ -71,13 +71,21 @@ run_test('get_unread_ids', () => {
assert.equal(unread_ids, undefined);
terms = [
{operator: 'bogus_operator', operand: 'me@example.com'},
{operator: 'search', operand: 'whatever'},
];
set_filter(terms);
unread_ids = candidate_ids();
assert.equal(unread_ids, undefined);
assert_unread_info({flavor: 'cannot_compute'});
terms = [
{operator: 'bogus_operator', operand: 'me@example.com'},
];
set_filter(terms);
unread_ids = candidate_ids();
assert.deepEqual(unread_ids, []);
assert_unread_info({flavor: 'not_found'});
terms = [
{operator: 'stream', operand: 'bogus'},
];
@ -169,6 +177,15 @@ run_test('get_unread_ids', () => {
unread_ids = candidate_ids();
assert.deepEqual(unread_ids, [private_msg.id]);
// For a negated search, our candidate ids will be all
// unread messages, even ones that don't pass the filter.
terms = [
{operator: 'is', operand: 'private', negated: true},
];
set_filter(terms);
unread_ids = candidate_ids();
assert.deepEqual(unread_ids, [stream_msg.id, private_msg.id]);
terms = [
{operator: 'pm-with', operand: 'bob@example.com'},
];
@ -200,3 +217,18 @@ run_test('get_unread_ids', () => {
flavor: 'cannot_compute',
});
});
run_test('defensive code', () => {
// Test defensive code. We actually avoid calling
// _possible_unread_message_ids for any case where we
// couldn't compute the unread message ids, but that
// invariant is hard to future-proof.
narrow_state._possible_unread_message_ids = () => undefined;
var terms = [
{operator: 'some-unhandled-case', operand: 'whatever'},
];
set_filter(terms);
assert_unread_info({
flavor: 'cannot_compute',
});
});

View File

@ -273,6 +273,10 @@ exports._possible_unread_message_ids = function () {
return unread.get_all_msg_ids();
}
if (current_filter.can_apply_locally()) {
return unread.get_all_msg_ids();
}
return;
};