search: Display invalid operand suggestion for has operator.

`has` operator uses predefined categories. This commit displays an
invalid operand message if the operand does not fall in to any of
these categories and the `has` operator is not at the last.
e.g. `has:abc sender:abc@zulipchat.com` will have `invalid abc
operand for has operator, sent by abc@zulipchat.com` as a prefix for
all its suggestions.
This commit is contained in:
Shubham Padia
2018-05-18 11:19:00 +05:30
committed by Tim Abbott
parent 2945062b79
commit 1b07b32ec1
2 changed files with 23 additions and 0 deletions

View File

@@ -553,6 +553,7 @@ Filter.operator_to_prefix = function (operator, negated) {
case 'near':
return verb + 'messages around';
// Note: We hack around using this in "describe" below.
case 'has':
return verb + 'messages with one or more';
@@ -623,6 +624,14 @@ function describe_unescaped(operators) {
}
return operand + ' messages';
}
if (canonicalized_operator ==='has') {
// search_suggestion.get_suggestions takes care that this message will
// only be shown if the `has` operator is not at the last.
var valid_has_operands = ['image', 'images', 'link', 'links', 'attachment', 'attachments'];
if (valid_has_operands.indexOf(operand) === -1) {
return 'invalid ' + operand + ' operand for has operator';
}
}
var prefix_for_operator = Filter.operator_to_prefix(canonicalized_operator,
elem.negated);
if (prefix_for_operator !== '') {