mirror of https://github.com/zulip/zulip.git
narrow: Add condition whether to show unread message first in narrow.
All narrows that have is: query or can mark unread message as read will show unread message first.
This commit is contained in:
parent
6ec40cf9a0
commit
648a60baf6
|
@ -69,6 +69,7 @@ run_test('basics', () => {
|
|||
|
||||
assert(!filter.is_search());
|
||||
assert(filter.can_mark_messages_read());
|
||||
assert(filter.allow_use_first_unread_when_narrowing());
|
||||
assert(filter.can_apply_locally());
|
||||
|
||||
operators = [
|
||||
|
@ -80,6 +81,7 @@ run_test('basics', () => {
|
|||
|
||||
assert(filter.is_search());
|
||||
assert(!filter.can_mark_messages_read());
|
||||
assert(!filter.allow_use_first_unread_when_narrowing());
|
||||
assert(!filter.can_apply_locally());
|
||||
assert(!filter.is_exactly('stream'));
|
||||
|
||||
|
@ -110,7 +112,32 @@ run_test('basics', () => {
|
|||
assert(filter.has_operator('has'));
|
||||
assert(!filter.can_apply_locally());
|
||||
});
|
||||
run_test('show_first_unread', () => {
|
||||
var operators = [
|
||||
{operator: 'is', operand: 'any'},
|
||||
];
|
||||
var filter = new Filter(operators);
|
||||
assert(filter.allow_use_first_unread_when_narrowing());
|
||||
|
||||
operators = [
|
||||
{operator: 'search', operand: 'query to search'},
|
||||
];
|
||||
filter = new Filter(operators);
|
||||
assert(!filter.allow_use_first_unread_when_narrowing());
|
||||
|
||||
filter = new Filter();
|
||||
filter.can_mark_messages_read = () => true;
|
||||
assert(filter.allow_use_first_unread_when_narrowing());
|
||||
|
||||
// Side case
|
||||
operators = [
|
||||
{operator: 'is', operand: 'any'},
|
||||
];
|
||||
filter = new Filter(operators);
|
||||
filter.can_mark_messages_read = () => false;
|
||||
assert(filter.allow_use_first_unread_when_narrowing());
|
||||
|
||||
});
|
||||
run_test('topic_stuff', () => {
|
||||
var operators = [
|
||||
{operator: 'stream', operand: 'foo'},
|
||||
|
|
|
@ -378,7 +378,9 @@ Filter.prototype = {
|
|||
can_mark_messages_read: function () {
|
||||
return !this.has_operator('search');
|
||||
},
|
||||
|
||||
allow_use_first_unread_when_narrowing: function () {
|
||||
return this.can_mark_messages_read() || this.has_operator('is');
|
||||
},
|
||||
can_apply_locally: function () {
|
||||
if (this.is_search()) {
|
||||
// The semantics for matching keywords are implemented
|
||||
|
|
|
@ -226,9 +226,12 @@ exports.activate = function (raw_operators, opts) {
|
|||
if (id_info.final_select_id !== undefined) {
|
||||
anchor = id_info.final_select_id;
|
||||
use_first_unread = false;
|
||||
} else {
|
||||
} else if (narrow_state.filter().allow_use_first_unread_when_narrowing()) {
|
||||
anchor = -1;
|
||||
use_first_unread = true;
|
||||
} else {
|
||||
anchor = 10000000000000000;
|
||||
use_first_unread = false;
|
||||
}
|
||||
|
||||
message_fetch.load_messages_for_narrow({
|
||||
|
|
Loading…
Reference in New Issue