mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 19:06:09 +00:00
filter: Validate and parse sender:me when turning into a pill.
Fixes #31315. We want to parse sender:me with the email when turning it into a pill, but not before then so that "Sent by me" is still the search string in the suggestions.
This commit is contained in:
@@ -453,7 +453,7 @@ export class Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse a string into a list of terms (see below).
|
// Parse a string into a list of terms (see below).
|
||||||
static parse(str: string): NarrowTerm[] {
|
static parse(str: string, for_pills = false): NarrowTerm[] {
|
||||||
const terms: NarrowTerm[] = [];
|
const terms: NarrowTerm[] = [];
|
||||||
let search_term: string[] = [];
|
let search_term: string[] = [];
|
||||||
let negated;
|
let negated;
|
||||||
@@ -511,6 +511,14 @@ export class Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
for_pills &&
|
||||||
|
operator === "sender" &&
|
||||||
|
operand.toString().toLowerCase() === "me"
|
||||||
|
) {
|
||||||
|
operand = people.my_current_email();
|
||||||
|
}
|
||||||
|
|
||||||
// We use Filter.operator_to_prefix() to check if the
|
// We use Filter.operator_to_prefix() to check if the
|
||||||
// operator is known. If it is not known, then we treat
|
// operator is known. If it is not known, then we treat
|
||||||
// it as a search for the given string (which may contain
|
// it as a search for the given string (which may contain
|
||||||
@@ -575,6 +583,9 @@ export class Filter {
|
|||||||
case "pm-with":
|
case "pm-with":
|
||||||
case "dm-including":
|
case "dm-including":
|
||||||
case "pm-including":
|
case "pm-including":
|
||||||
|
if (term.operand === "me") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return term.operand
|
return term.operand
|
||||||
.split(",")
|
.split(",")
|
||||||
.every((email) => people.get_by_email(email) !== undefined);
|
.every((email) => people.get_by_email(email) !== undefined);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ function full_search_query_in_terms(): NarrowTerm[] {
|
|||||||
assert(search_pill_widget !== null);
|
assert(search_pill_widget !== null);
|
||||||
return [
|
return [
|
||||||
...search_pill.get_current_search_pill_terms(search_pill_widget),
|
...search_pill.get_current_search_pill_terms(search_pill_widget),
|
||||||
...Filter.parse(get_search_bar_text()),
|
...Filter.parse(get_search_bar_text(), true),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1405,8 +1405,8 @@ test("parse", () => {
|
|||||||
let string;
|
let string;
|
||||||
let terms;
|
let terms;
|
||||||
|
|
||||||
function _test() {
|
function _test(for_pills = false) {
|
||||||
const result = Filter.parse(string);
|
const result = Filter.parse(string, for_pills);
|
||||||
assert_same_terms(result, terms);
|
assert_same_terms(result, terms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1444,6 +1444,14 @@ test("parse", () => {
|
|||||||
terms = [{operator: "sender", operand: "leo+test@zulip.com"}];
|
terms = [{operator: "sender", operand: "leo+test@zulip.com"}];
|
||||||
_test();
|
_test();
|
||||||
|
|
||||||
|
string = "sender:me";
|
||||||
|
terms = [{operator: "sender", operand: `${me.email}`}];
|
||||||
|
_test(true);
|
||||||
|
|
||||||
|
string = "-sender:me";
|
||||||
|
terms = [{operator: "sender", operand: `${me.email}`, negated: true}];
|
||||||
|
_test(true);
|
||||||
|
|
||||||
string = "https://www.google.com";
|
string = "https://www.google.com";
|
||||||
terms = [{operator: "search", operand: "https://www.google.com"}];
|
terms = [{operator: "search", operand: "https://www.google.com"}];
|
||||||
_test();
|
_test();
|
||||||
@@ -1964,6 +1972,7 @@ test("is_valid_search_term", () => {
|
|||||||
["topic:GhostTown", true],
|
["topic:GhostTown", true],
|
||||||
["dm-including:alice@example.com", true],
|
["dm-including:alice@example.com", true],
|
||||||
["sender:ghost@zulip.com", false],
|
["sender:ghost@zulip.com", false],
|
||||||
|
["sender:me", true],
|
||||||
["dm:alice@example.com,ghost@example.com", false],
|
["dm:alice@example.com,ghost@example.com", false],
|
||||||
["dm:alice@example.com,joe@example.com", true],
|
["dm:alice@example.com,joe@example.com", true],
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user