filter: Add new is_non_huddle_pm method.

We want to exclude 1:1 PMs from muted users everywhere
except in `pm-with/<muted_user>`.
This method will help us determine whether we are in such
a narrow.
This commit is contained in:
Abhijeet Prasad Bodas 2021-05-05 16:03:27 +05:30 committed by Tim Abbott
parent 9f6ad779e4
commit e4d5114c3c
2 changed files with 11 additions and 0 deletions

View File

@ -185,13 +185,20 @@ test("basics", () => {
operators = [{operator: "pm-with", operand: "joe@example.com"}];
filter = new Filter(operators);
assert(filter.is_non_huddle_pm());
assert(filter.contains_only_private_messages());
assert(!filter.has_operator("search"));
assert(filter.can_apply_locally());
assert(!filter.is_personal_filter());
operators = [{operator: "pm-with", operand: "joe@example.com,jack@example.com"}];
filter = new Filter(operators);
assert(!filter.is_non_huddle_pm());
assert(filter.contains_only_private_messages());
operators = [{operator: "group-pm-with", operand: "joe@example.com"}];
filter = new Filter(operators);
assert(!filter.is_non_huddle_pm());
assert(filter.contains_only_private_messages());
assert(!filter.has_operator("search"));
assert(filter.can_apply_locally());

View File

@ -412,6 +412,10 @@ export class Filter {
return this.has_operator("search");
}
is_non_huddle_pm() {
return this.has_operator("pm-with") && this.operands("pm-with")[0].split(",").length === 1;
}
calc_can_mark_messages_read() {
const term_types = this.sorted_term_types();