Add narrow_state.get_first_unread_id().

This commit is contained in:
Steve Howell 2018-05-02 19:24:38 +00:00 committed by Tim Abbott
parent a072b2a153
commit 66cd2edee4
2 changed files with 18 additions and 0 deletions

View File

@ -47,6 +47,7 @@ function set_filter(terms) {
set_filter(terms);
unread_ids = narrow_state.get_unread_ids();
assert.equal(unread_ids, undefined);
assert.equal(narrow_state.get_first_unread_id(), undefined);
terms = [
{operator: 'stream', operand: 'bogus'},
@ -61,6 +62,7 @@ function set_filter(terms) {
set_filter(terms);
unread_ids = narrow_state.get_unread_ids();
assert.deepEqual(unread_ids, []);
assert.equal(narrow_state.get_first_unread_id(), undefined);
msg = {
id: 101,
@ -74,6 +76,7 @@ function set_filter(terms) {
unread_ids = narrow_state.get_unread_ids();
assert.deepEqual(unread_ids, [msg.id]);
assert.equal(narrow_state.get_first_unread_id(), msg.id);
terms = [
{operator: 'stream', operand: 'bogus'},

View File

@ -169,6 +169,21 @@ exports.pm_string = function () {
return user_ids_string;
};
exports.get_first_unread_id = function () {
// This function may return undefined for two different
// reasons: we have no unread messages, or we don't have
// an easy, inexpensive way to calculate them. See the
// comment in get_unread_ids() for more details.
var unread_ids = exports.get_unread_ids();
if (unread_ids === undefined) {
return;
}
return unread_ids[0];
};
exports.get_unread_ids = function () {
// This function currently only returns valid results for
// certain types of narrows, mostly left sidebar narrows.