mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
Handle negated person-related operators in search suggestions.
(imported from commit e045a0910ff59d9b8569c5ba3b3b644fe2d7dad7)
This commit is contained in:
@@ -96,7 +96,9 @@ function get_private_suggestions(all_people, operators, person_operator_matches)
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var query, matching_operator;
|
var query;
|
||||||
|
var matching_operator;
|
||||||
|
var negated = false;
|
||||||
|
|
||||||
if (operators.length === 0) {
|
if (operators.length === 0) {
|
||||||
query = '';
|
query = '';
|
||||||
@@ -112,6 +114,7 @@ function get_private_suggestions(all_people, operators, person_operator_matches)
|
|||||||
if (operator === item) {
|
if (operator === item) {
|
||||||
query = operators[0].operand;
|
query = operators[0].operand;
|
||||||
matching_operator = item;
|
matching_operator = item;
|
||||||
|
negated = operators[0].negated;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -134,16 +137,21 @@ function get_private_suggestions(all_people, operators, person_operator_matches)
|
|||||||
// Take top 15 people, since they're ordered by pm_recipient_count.
|
// Take top 15 people, since they're ordered by pm_recipient_count.
|
||||||
people = people.slice(0, 15);
|
people = people.slice(0, 15);
|
||||||
|
|
||||||
var prefix = Filter.operator_to_prefix(matching_operator);
|
var prefix = Filter.operator_to_prefix(matching_operator, negated);
|
||||||
|
|
||||||
var suggestions = _.map(people, function (person) {
|
var suggestions = _.map(people, function (person) {
|
||||||
var name = highlight_person(query, person);
|
|
||||||
var description = prefix + ' ' + name;
|
|
||||||
var term = {
|
var term = {
|
||||||
operator: matching_operator,
|
operator: matching_operator,
|
||||||
operand: person.email
|
operand: person.email,
|
||||||
|
negated: negated
|
||||||
};
|
};
|
||||||
var search_string = Filter.unparse([term]);
|
var name = highlight_person(query, person);
|
||||||
|
var description = prefix + ' ' + name;
|
||||||
|
var terms = [term];
|
||||||
|
if (negated) {
|
||||||
|
terms = [{operator: 'is', operand: 'private'}, term];
|
||||||
|
}
|
||||||
|
var search_string = Filter.unparse(terms);
|
||||||
return {description: description, search_string: search_string};
|
return {description: description, search_string: search_string};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,15 @@ set_global('narrow', {});
|
|||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = '-pm-with:t';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
"-pm-with:t",
|
||||||
|
"is:private -pm-with:ted@zulip.com",
|
||||||
|
"is:private"
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'pm-with:ted@zulip.com';
|
query = 'pm-with:ted@zulip.com';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions(query);
|
||||||
expected = [
|
expected = [
|
||||||
@@ -145,6 +154,15 @@ set_global('narrow', {});
|
|||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
|
query = '-sender:te';
|
||||||
|
suggestions = search.get_suggestions(query);
|
||||||
|
expected = [
|
||||||
|
"-sender:te",
|
||||||
|
"is:private -sender:ted@zulip.com",
|
||||||
|
"is:private"
|
||||||
|
];
|
||||||
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sender:ted@zulip.com';
|
query = 'sender:ted@zulip.com';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions(query);
|
||||||
expected = [
|
expected = [
|
||||||
|
|||||||
Reference in New Issue
Block a user