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.

topic_list: Add is:followed filter to left sidebar.

Nithyaraj Mudhaliyar7cd7e3dc24fc
diff --git a/tools/lib/capitalization.py b/tools/lib/capitalization.py
index 1b77517c50f..259e117a140 100644
--- a/tools/lib/capitalization.py
+++ b/tools/lib/capitalization.py
@@ -183,6 +183,10 @@ IGNORED_PHRASES = [
r"resolved",
# Used in pills for unresolved topics.
r"unresolved",
+ # Used in pills for followed topics.
+ r"followed",
+ # Used in pills for unfollowed topics.
+ r"unfollowed",
# This is a reference to a setting/secret and should be lowercase.
r"zulip_org_id",
# These are custom time unit options for modal dropdowns
diff --git a/web/src/stream_list_sort.ts b/web/src/stream_list_sort.ts
index 4aa3ba8e722..355d8342af7 100644
--- a/web/src/stream_list_sort.ts
+++ b/web/src/stream_list_sort.ts
@@ -175,7 +175,11 @@ export function sort_groups(
// term, or a muted topic matches the current topic, we include
// the channel in the list of matches.
const topics = topic_list_data.get_filtered_topic_names(current_channel_id, (topic_names) =>
- topic_list_data.filter_topics_by_search_term(topic_names, search_term),
+ topic_list_data.filter_topics_by_search_term(
+ current_channel_id,
+ topic_names,
+ search_term,
+ ),
);
if (
topics.some(
diff --git a/web/src/topic_filter_pill.ts b/web/src/topic_filter_pill.ts
index 146b2f70b7d..06c4a5ebcbe 100644
--- a/web/src/topic_filter_pill.ts
+++ b/web/src/topic_filter_pill.ts
@@ -8,6 +8,7 @@ export type TopicFilterPill = {
type: "topic_filter";
label: string;
syntax: string;
+ match_prefix_required?: string;
};
export type TopicFilterPillWidget = InputPillContainer<TopicFilterPill>;
@@ -23,6 +24,17 @@ export const filter_options: TopicFilterPill[] = [
label: $t({defaultMessage: "resolved"}),
syntax: "is:resolved",
},
+ {
+ type: "topic_filter",
+ label: $t({defaultMessage: "followed"}),
+ syntax: "is:followed",
+ },
+ {
+ type: "topic_filter",
+ label: $t({defaultMessage: "unfollowed"}),
+ syntax: "-is:followed",
+ match_prefix_required: "-is",
+ },
];
export function create_item_from_syntax(
diff --git a/web/src/topic_list.ts b/web/src/topic_list.ts
index 5b078877840..cd781f07b53 100644
--- a/web/src/topic_list.ts
+++ b/web/src/topic_list.ts
@@ -374,7 +374,12 @@ export class TopicListWidget {
function filter_topics_left_sidebar(topic_names: string[]): string[] {
const search_term = get_left_sidebar_topic_search_term();
+ const stream_id = active_stream_id();
+ if (stream_id === undefined) {
+ return topic_names;
+ }
return topic_list_data.filter_topics_by_search_term(
+ stream_id,
topic_names,
search_term,
get_typeahead_search_pills_syntax(),
@@ -574,14 +579,21 @@ export function setup_topic_search_typeahead(): void {
const stream_id = active_stream_id();
assert(stream_id !== undefined);
- if (!stream_topic_history.stream_has_locally_available_resolved_topics(stream_id)) {
- return [];
- }
- const $pills = $("#left-sidebar-filter-topic-input .pill");
- if ($pills.length > 0) {
- return [];
- }
- return [...topic_filter_pill.filter_options];
+ const pills = topic_filter_pill_widget!.items();
+ const current_syntaxes = new Set(pills.map((pill) => pill.syntax));
+ const query = $("#topic_filter_query").text().trim();
+ return topic_filter_pill.filter_options.filter((option) => {
+ if (current_syntaxes.has(option.syntax)) {
+ return false;
+ }
+ if (
+ option.match_prefix_required &&
+ !query.startsWith(option.match_prefix_required)
+ ) {
+ return false;
+ }
+ return true;
+ });
},
item_html(item: TopicFilterPill) {
return typeahead_helper.render_topic_state(item.label);
diff --git a/web/src/topic_list_data.ts b/web/src/topic_list_data.ts
index 11e6a7b83cf..3e2980d79cf 100644
--- a/web/src/topic_list_data.ts
+++ b/web/src/topic_list_data.ts
@@ -156,6 +156,7 @@ type TopicListInfo = {
};
export function filter_topics_by_search_term(
+ stream_id: number,
topic_names: string[],
search_term: string,
topics_state = "",
@@ -175,10 +176,23 @@ export function filter_topics_by_search_term(
return typeahead.query_matches_string_in_any_order(normalized_query, normalized_topic, " ");
});
- if (topics_state === "is:resolved") {
- topic_names = topic_names.filter((name) => resolved_topic.is_resolved(name));
- } else if (topics_state === "-is:resolved") {
- topic_names = topic_names.filter((name) => !resolved_topic.is_resolved(name));
+ switch (topics_state) {
+ case "is:resolved":
+ topic_names = topic_names.filter((name) => resolved_topic.is_resolved(name));
+ break;
+ case "-is:resolved":
+ topic_names = topic_names.filter((name) => !resolved_topic.is_resolved(name));
+ break;
+ case "is:followed":
+ topic_names = topic_names.filter((name) =>
+ user_topics.is_topic_followed(stream_id, name),
+ );
+ break;
+ case "-is:followed":
+ topic_names = topic_names.filter(
+ (name) => !user_topics.is_topic_followed(stream_id, name),
+ );
+ break;
}
return topic_names;
diff --git a/web/tests/topic_list_data.test.cjs b/web/tests/topic_list_data.test.cjs
index e9c66f3f5de..56b397dfc7f 100644
--- a/web/tests/topic_list_data.test.cjs
+++ b/web/tests/topic_list_data.test.cjs
@@ -54,7 +54,7 @@ function get_list_info(zoom, search) {
const zoomed = zoom === undefined ? false : zoom;
const search_term = search === undefined ? "" : search;
return topic_list_data.get_list_info(stream_id, zoomed, (topics) =>
- topic_list_data.filter_topics_by_search_term(topics, search_term),
+ topic_list_data.filter_topics_by_search_term(stream_id, topics, search_term),
);
}
@@ -66,6 +66,7 @@ test("filter_topics_by_search_term with resolved topics_state", () => {
let topics_state = "is:resolved";
let result = topic_list_data.filter_topics_by_search_term(
+ general.stream_id,
topic_names,
search_term,
topics_state,
@@ -75,11 +76,44 @@ test("filter_topics_by_search_term with resolved topics_state", () => {
// Filter for unresolved topics.
topics_state = "-is:resolved";
- result = topic_list_data.filter_topics_by_search_term(topic_names, search_term, topics_state);
+ result = topic_list_data.filter_topics_by_search_term(
+ general.stream_id,
+ topic_names,
+ search_term,
+ topics_state,
+ );
assert.deepEqual(result, ["topic 1", "topic 2"]);
});
+test("filter_topics_is_followed", ({override}) => {
+ const stream_id = general.stream_id;
+ const topics = ["followed_topic", "unfollowed_topic", "other"];
+
+ override(user_topics, "is_topic_followed", (id, topic_name) => {
+ assert.equal(id, stream_id);
+ return topic_name === "followed_topic";
+ });
+
+ // filter for is:followed
+ const results_followed = topic_list_data.filter_topics_by_search_term(
+ stream_id,
+ topics,
+ "",
+ "is:followed",
+ );
+ assert.deepEqual(results_followed, ["followed_topic"]);
+
+ // filter for -is:followed
+ const results_unfollowed = topic_list_data.filter_topics_by_search_term(
+ stream_id,
+ topics,
+ "",
+ "-is:followed",
+ );
+ assert.deepEqual(results_unfollowed, ["unfollowed_topic", "other"]);
+});
+
function test(label, f) {
run_test(label, (helpers) => {
stream_topic_history.reset();