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.

search_suggestions: Ignore resolved prefix (`✔ `) while sorting.

apoorvapendse15b477cc7b0e
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts
index 522e856a4d3..8a96282fddf 100644
--- a/web/src/search_suggestion.ts
+++ b/web/src/search_suggestion.ts
@@ -9,6 +9,7 @@ import * as narrow_state from "./narrow_state.ts";
import {page_params} from "./page_params.ts";
import * as people from "./people.ts";
import type {User} from "./people.ts";
+import {RESOLVED_TOPIC_PREFIX} from "./resolved_topic.ts";
import {type NarrowTerm} from "./state_data.ts";
import * as stream_data from "./stream_data.ts";
import * as stream_topic_history from "./stream_topic_history.ts";
@@ -482,6 +483,13 @@ export function get_topic_suggestions_from_candidates({
return topics;
}
+function ignore_resolved_topic_prefix(topic_name: string): string {
+ if (topic_name.startsWith(RESOLVED_TOPIC_PREFIX)) {
+ return topic_name.slice(2);
+ }
+ return topic_name;
+}
+
function get_topic_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestion[] {
if (
!check_validity(last, terms, ["channel", "topic", "search"], incompatible_patterns.topic!)
@@ -561,8 +569,10 @@ function get_topic_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestio
// Just use alphabetical order. While recency and read/unreadness of
// topics do matter in some contexts, you can get that from the left sidebar,
// and I'm leaning toward high scannability for autocompletion. I also don't
- // care about case.
- topics.sort();
+ // care about case. Also ignore the resolved icon (✔ ) while sorting.
+ topics.sort((a, b) =>
+ ignore_resolved_topic_prefix(a).localeCompare(ignore_resolved_topic_prefix(b)),
+ );
return topics.map((topic) => {
const topic_term: NarrowTerm = {operator: "topic", operand: topic, negated};
diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjs
index 972a0afa71c..3a08f815cc7 100644
--- a/web/tests/search_suggestion.test.cjs
+++ b/web/tests/search_suggestion.test.cjs
@@ -666,7 +666,7 @@ test("topic_suggestions", ({override, mock_template}) => {
topic_name: "REXX",
});
- for (const topic_name of ["team", "ignore", "test"]) {
+ for (const topic_name of ["team", "ignore", "✔ ice cream", "✔ team work", "test"]) {
stream_topic_history.add_message({
stream_id: office_id,
topic_name,
@@ -680,6 +680,7 @@ test("topic_suggestions", ({override, mock_template}) => {
"dm-including:[email protected]",
`channel:${office_id} topic:team`,
+ `channel:${office_id} topic:✔+team+work`,
`channel:${office_id} topic:test`,
];
assert.deepEqual(suggestions.strings, expected);
@@ -706,6 +707,7 @@ test("topic_suggestions", ({override, mock_template}) => {
expected = [
"-topic:te",
`channel:${office_id} -topic:team`,
+ `channel:${office_id} -topic:✔+team+work`,
`channel:${office_id} -topic:test`,
];
assert.deepEqual(suggestions.strings, expected);