filter: Add 'in:*' to sorted_term_types.

This simplifies our handling of in-home and in-all cases in
can_mark_messages_read().
This commit is contained in:
Rohitt Vashishtha 2020-01-16 06:13:22 +05:30 committed by Tim Abbott
parent 316eda071d
commit 8a1299d076
2 changed files with 21 additions and 9 deletions

View File

@ -316,11 +316,28 @@ run_test('can_mark_messages_read', () => {
const in_home = [
{ operator: 'in', operand: 'home' },
];
const in_home_negated = [
{ operator: 'in', operand: 'home', negated: true },
];
filter = new Filter(in_home);
assert(filter.can_mark_messages_read());
assert_not_mark_read_with_is_operands(in_home);
assert_not_mark_read_with_has_operands(in_home);
assert_not_mark_read_when_searching(in_home);
filter = new Filter(in_home_negated);
assert(!filter.can_mark_messages_read());
// Do not mark messages as read when in an unsupported 'in:*' filter.
const in_random = [
{ operator: 'in', operand: 'xxxxxxxxx' },
];
const in_random_negated = [
{ operator: 'in', operand: 'xxxxxxxxx', negated: true },
];
filter = new Filter(in_random);
assert(!filter.can_mark_messages_read());
filter = new Filter(in_random_negated);
assert(!filter.can_mark_messages_read());
});
run_test('show_first_unread', () => {

View File

@ -409,14 +409,8 @@ Filter.prototype = {
return true;
}
if (this._operators.length === 1) {
const elem = this._operators[0];
if (elem.operator === 'in' && !elem.negated) {
if (elem.operand === 'home' || elem.operand === 'all') {
return true;
}
}
if (term_types.length === 1 && _.contains(['in-home', 'in-all'], term_types[0])) {
return true;
}
return false;
@ -605,7 +599,7 @@ Filter.term_type = function (term) {
result += operator;
if (_.contains(['is', 'has'], operator)) {
if (_.contains(['is', 'has', 'in'], operator)) {
result += '-' + operand;
}
@ -614,6 +608,7 @@ Filter.term_type = function (term) {
Filter.sorted_term_types = function (term_types) {
const levels = [
'in',
'streams',
'stream', 'topic',
'pm-with', 'group-pm-with', 'sender',