Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

unresolved: Add support for searching for unresolved topics.

Maneesh Shuklad8f609d0880b
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 46a7c6f10f0..5ce33334a6a 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -750,6 +750,20 @@ export class Filter {
const operand = term.operand;
const canonicalized_operator = Filter.canonicalize_operator(term.operator);
if (canonicalized_operator === "is") {
+ // Some operands have their own negative words, like
+ // unresolved, rather than the default "exclude " prefix.
+ const custom_negated_operand_phrases: Record<string, string> = {
+ resolved: "unresolved",
+ };
+ const negated_phrase = custom_negated_operand_phrases[operand];
+ if (term.negated && negated_phrase !== undefined) {
+ return {
+ type: "is_operator",
+ verb: "",
+ operand: negated_phrase,
+ };
+ }
+
const verb = term.negated ? "exclude " : "";
return {
type: "is_operator",
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts
index c7c3c6812dc..6450adde19d 100644
--- a/web/src/search_suggestion.ts
+++ b/web/src/search_suggestion.ts
@@ -589,12 +589,29 @@ function get_special_filter_suggestions(
// Negating suggestions on is_search_operand_negated is required for
// suggesting negated terms.
if (last.negated === true || is_search_operand_negated) {
- suggestions = suggestions.map((suggestion) => ({
- search_string: "-" + suggestion.search_string,
- description_html: "exclude " + suggestion.description_html,
- incompatible_patterns: suggestion.incompatible_patterns,
- is_people: false,
- }));
+ suggestions = suggestions
+ .map((suggestion) => {
+ // If the search_string is "is:resolved", we want to suggest "Unresolved topics"
+ // instead of "Exclude resolved topics".
+ if (suggestion.search_string === "is:resolved") {
+ return {
+ ...suggestion,
+ search_string: "-" + suggestion.search_string,
+ description_html: "unresolved topics",
+ };
+ } else if (suggestion.search_string === "-is:resolved") {
+ return null;
+ }
+ return {
+ ...suggestion,
+ search_string: "-" + suggestion.search_string,
+ description_html: "exclude " + suggestion.description_html,
+ };
+ })
+ .filter(
+ (suggestion): suggestion is SuggestionAndIncompatiblePatterns =>
+ suggestion !== null,
+ );
}
const last_string = Filter.unparse([last]).toLowerCase();
@@ -713,6 +730,17 @@ function get_is_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Sugge
{operator: "dm-including"},
],
},
+ {
+ search_string: "-is:resolved",
+ description_html: "unresolved topics",
+ is_people: false,
+ incompatible_patterns: [
+ {operator: "is", operand: "resolved"},
+ {operator: "is", operand: "dm"},
+ {operator: "dm"},
+ {operator: "dm-including"},
+ ],
+ },
];
const special_filtered_suggestions = get_special_filter_suggestions(last, terms, suggestions);
// Suggest "is:dm" to anyone with "is:private" in their muscle memory
diff --git a/web/templates/search_description.hbs b/web/templates/search_description.hbs
index 725fc5651f9..ab2a09bf9ec 100644
--- a/web/templates/search_description.hbs
+++ b/web/templates/search_description.hbs
@@ -50,6 +50,10 @@
{{~!-- squash whitespace --~}}
{{this.verb}}followed topics
{{~!-- squash whitespace --~}}
+ {{else if (eq this.operand "unresolved")}}
+ {{~!-- squash whitespace --~}}
+ {{this.verb}}unresolved topics
+ {{~!-- squash whitespace --~}}
{{else}}
{{~!-- squash whitespace --~}}
invalid {{this.operand}} operand for is operator
diff --git a/web/templates/search_operators.hbs b/web/templates/search_operators.hbs
index 5008366e023..3cab7e02ff9 100644
--- a/web/templates/search_operators.hbs
+++ b/web/templates/search_operators.hbs
@@ -133,6 +133,12 @@
{{t 'Narrow to messages in resolved topics.'}}
</td>
</tr>
+ <tr>
+ <td class="operator">-is:resolved</td>
+ <td class="definition">
+ {{t 'Narrow to messages in unresolved topics.'}}
+ </td>
+ </tr>
<tr>
<td class="operator">is:followed</td>
<td class="definition">
diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs
index 6e2448f5b09..cbd57ba14f8 100644
--- a/web/tests/filter.test.cjs
+++ b/web/tests/filter.test.cjs
@@ -1563,13 +1563,18 @@ test("describe", ({mock_template, override}) => {
assert.equal(Filter.search_description_as_html(narrow, false), string);
narrow = [{operator: "is", operand: "resolved"}];
- string = "topics marked as resolved";
+ string = "resolved topics";
assert.equal(Filter.search_description_as_html(narrow, false), string);
narrow = [{operator: "is", operand: "followed"}];
string = "followed topics";
assert.equal(Filter.search_description_as_html(narrow, false), string);
+ // operands with their own negative words, like resolved.
+ narrow = [{operator: "is", operand: "resolved", negated: true}];
+ string = "unresolved topics";
+ assert.equal(Filter.search_description_as_html(narrow, false), string);
+
narrow = [{operator: "is", operand: "something_we_do_not_support"}];
string = "invalid something_we_do_not_support operand for is operator";
assert.equal(Filter.search_description_as_html(narrow, false), string);
diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjs
index cb65405a8eb..6c37a3b5f46 100644
--- a/web/tests/search_suggestion.test.cjs
+++ b/web/tests/search_suggestion.test.cjs
@@ -377,6 +377,7 @@ test("empty_query_suggestions", () => {
"is:alerted",
"is:unread",
"is:resolved",
+ "-is:resolved",
`channel:${devel_id}`,
`channel:${office_id}`,
@@ -518,7 +519,7 @@ test("check_is_suggestions", ({override, mock_template}) => {
assert.equal(describe("-is:mentioned"), "Exclude @-mentions");
assert.equal(describe("-is:alerted"), "Exclude alerted messages");
assert.equal(describe("-is:unread"), "Exclude unread messages");
- assert.equal(describe("-is:resolved"), "Exclude topics marked as resolved");
+ assert.equal(describe("-is:resolved"), "Unresolved topics");
assert.equal(describe("-is:followed"), "Exclude followed topics");
// operand suggestions follow.