mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
filter: Extract filter.contains_only_private_messages.
This will be a useful reusable function for determining whether to display other alerts as well.
This commit is contained in:
@@ -69,6 +69,7 @@ run_test('basics', () => {
|
||||
|
||||
assert(!filter.is_search());
|
||||
assert(filter.can_mark_messages_read());
|
||||
assert(!filter.contains_only_private_messages());
|
||||
assert(filter.allow_use_first_unread_when_narrowing());
|
||||
assert(filter.can_apply_locally());
|
||||
|
||||
@@ -81,6 +82,7 @@ run_test('basics', () => {
|
||||
|
||||
assert(filter.is_search());
|
||||
assert(!filter.can_mark_messages_read());
|
||||
assert(!filter.contains_only_private_messages());
|
||||
assert(!filter.allow_use_first_unread_when_narrowing());
|
||||
assert(!filter.can_apply_locally());
|
||||
assert(!filter.is_exactly('stream'));
|
||||
@@ -92,6 +94,7 @@ run_test('basics', () => {
|
||||
{operator: 'stream', operand: 'exclude', negated: true},
|
||||
];
|
||||
filter = new Filter(operators);
|
||||
assert(!filter.contains_only_private_messages());
|
||||
assert(!filter.has_operator('stream'));
|
||||
|
||||
// Negated searches are just like positive searches for our purposes, since
|
||||
@@ -101,6 +104,7 @@ run_test('basics', () => {
|
||||
{operator: 'search', operand: 'stop_word', negated: true},
|
||||
];
|
||||
filter = new Filter(operators);
|
||||
assert(!filter.contains_only_private_messages());
|
||||
assert(filter.has_operator('search'));
|
||||
assert(!filter.can_apply_locally());
|
||||
|
||||
@@ -116,6 +120,7 @@ run_test('basics', () => {
|
||||
{operator: 'streams', operand: 'public', negated: true},
|
||||
];
|
||||
filter = new Filter(operators);
|
||||
assert(!filter.contains_only_private_messages());
|
||||
assert(!filter.has_operator('streams'));
|
||||
assert(filter.has_negated_operand('streams', 'public'));
|
||||
assert(!filter.can_apply_locally());
|
||||
@@ -124,10 +129,34 @@ run_test('basics', () => {
|
||||
{operator: 'streams', operand: 'public'},
|
||||
];
|
||||
filter = new Filter(operators);
|
||||
assert(!filter.contains_only_private_messages());
|
||||
assert(filter.has_operator('streams'));
|
||||
assert(!filter.has_negated_operand('streams', 'public'));
|
||||
assert(!filter.can_apply_locally());
|
||||
|
||||
operators = [
|
||||
{operator: 'is', operand: 'private'},
|
||||
];
|
||||
filter = new Filter(operators);
|
||||
assert(filter.contains_only_private_messages());
|
||||
assert(!filter.has_operator('search'));
|
||||
assert(filter.can_apply_locally());
|
||||
|
||||
operators = [
|
||||
{operator: 'pm-with', operand: 'joe@example.com'},
|
||||
];
|
||||
filter = new Filter(operators);
|
||||
assert(filter.contains_only_private_messages());
|
||||
assert(!filter.has_operator('search'));
|
||||
assert(filter.can_apply_locally());
|
||||
|
||||
operators = [
|
||||
{operator: 'group-pm-with', operand: 'joe@example.com'},
|
||||
];
|
||||
filter = new Filter(operators);
|
||||
assert(filter.contains_only_private_messages());
|
||||
assert(!filter.has_operator('search'));
|
||||
assert(filter.can_apply_locally());
|
||||
});
|
||||
run_test('show_first_unread', () => {
|
||||
var operators = [
|
||||
|
||||
@@ -384,9 +384,16 @@ 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');
|
||||
},
|
||||
|
||||
contains_only_private_messages: function () {
|
||||
return this.has_operator("is") && this.operands("is")[0] === "private" ||
|
||||
this.has_operator("pm-with") || this.has_operator("group-pm-with");
|
||||
},
|
||||
|
||||
can_apply_locally: function () {
|
||||
if (this.is_search()) {
|
||||
// The semantics for matching keywords are implemented
|
||||
|
||||
@@ -275,8 +275,7 @@ exports.activate = function (raw_operators, opts) {
|
||||
});
|
||||
}
|
||||
|
||||
if (filter.has_operator("is") && filter.operands("is")[0] === "private"
|
||||
|| filter.has_operator("pm-with") || filter.has_operator("group-pm-with")) {
|
||||
if (filter.contains_only_private_messages()) {
|
||||
compose.update_closed_compose_buttons_for_private();
|
||||
} else {
|
||||
compose.update_closed_compose_buttons_for_stream();
|
||||
|
||||
Reference in New Issue
Block a user