mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
refactor: Clean up can_mark_messages_read.
We now explicitly enumerate various cases, which should make it easier to change this code.
This commit is contained in:
@@ -275,11 +275,17 @@ run_test('can_mark_messages_read', () => {
|
||||
{ operator: 'pm-with', operand: 'joe@example.com,' },
|
||||
];
|
||||
|
||||
const pm_with_negated = [
|
||||
{ operator: 'pm-with', operand: 'joe@example.com,', negated: true},
|
||||
];
|
||||
|
||||
const group_pm = [
|
||||
{ operator: 'pm-with', operand: 'joe@example.com,STEVE@foo.com' },
|
||||
];
|
||||
filter = new Filter(pm_with);
|
||||
assert(filter.can_mark_messages_read());
|
||||
filter = new Filter(pm_with_negated);
|
||||
assert(!filter.can_mark_messages_read());
|
||||
filter = new Filter(group_pm);
|
||||
assert(filter.can_mark_messages_read());
|
||||
assert_not_mark_read_with_is_operands(group_pm);
|
||||
|
||||
@@ -382,13 +382,44 @@ Filter.prototype = {
|
||||
},
|
||||
|
||||
can_mark_messages_read: function () {
|
||||
return _.every(this._operators, function (elem) {
|
||||
return (_.contains(['stream', 'topic', 'pm-with'], elem.operator)
|
||||
|| elem.operator === 'is' && elem.operand === 'private'
|
||||
|| elem.operator === 'in' && elem.operand === 'all'
|
||||
|| elem.operator === 'in' && elem.operand === 'home')
|
||||
&& !elem.negated;
|
||||
});
|
||||
const term_types = this.sorted_term_types();
|
||||
|
||||
if (_.isEqual(term_types, ['stream', 'topic'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_.isEqual(term_types, ['pm-with'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Some users really hate it when Zulip marks messages as read
|
||||
// in interleaved views, so we will eventually have a setting
|
||||
// that early-exits before the subsequent checks.
|
||||
|
||||
if (_.isEqual(term_types, ['stream'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_.isEqual(term_types, ['is-private'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_.isEqual(term_types, [])) {
|
||||
// All view
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
allow_use_first_unread_when_narrowing: function () {
|
||||
|
||||
Reference in New Issue
Block a user