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.

Revert "compose_recipient: Use sort_streams function in channel picker."

Tim Abbott764d70bc5b59
diff --git a/web/src/compose_recipient.ts b/web/src/compose_recipient.ts
index 2367d1cdd62..8fb6b41cc51 100644
--- a/web/src/compose_recipient.ts
+++ b/web/src/compose_recipient.ts
@@ -22,8 +22,6 @@ import * as narrow_state from "./narrow_state.ts";
import {realm} from "./state_data.ts";
import * as stream_color from "./stream_color.ts";
import * as stream_data from "./stream_data.ts";
-import type {StreamSubscription} from "./sub_store.ts";
-import * as typeahead_helper from "./typeahead_helper.ts";
import * as ui_util from "./ui_util.ts";
import * as user_groups from "./user_groups.ts";
import * as util from "./util.ts";
@@ -279,7 +277,9 @@ function item_click_callback(event: JQuery.ClickEvent, dropdown: tippy.Instance)
event.stopPropagation();
}
-function add_direct_messages_option(options: Option[]): Option[] {
+function get_options_for_recipient_widget(): Option[] {
+ const options: Option[] = stream_data.get_options_for_dropdown_widget();
+
const direct_messages_option = {
is_direct_message: true,
unique_id: compose_state.DIRECT_MESSAGE_ID,
@@ -292,14 +292,9 @@ function add_direct_messages_option(options: Option[]): Option[] {
} else {
options.push(direct_messages_option);
}
-
return options;
}
-function get_options_for_recipient_widget(): Option[] {
- return add_direct_messages_option(stream_data.get_options_for_dropdown_widget());
-}
-
export function toggle_compose_recipient_dropdown(): void {
$("#compose_select_recipient_widget").trigger("click");
}
@@ -366,33 +361,6 @@ export function initialize(): void {
}
return "#private_message_recipient";
},
- sort_list_by_filter_value(items: Option[], filter_value: string): Option[] {
- const non_stream_items = [];
- const stream_items_by_stream_id = new Map<
- number,
- Option & {stream: StreamSubscription}
- >();
- for (const item of items) {
- if (item.stream === undefined) {
- non_stream_items.push(item);
- } else {
- stream_items_by_stream_id.set(item.stream.stream_id, {
- ...item,
- // Needed for typescript to recognize stream is defined
- stream: item.stream,
- });
- }
- }
- const stream_items = [...stream_items_by_stream_id.values()].map((item) => item.stream);
- const sorted_streams = typeahead_helper.sort_streams(stream_items, filter_value);
- const sorted_stream_items = sorted_streams.map(
- (stream) => stream_items_by_stream_id.get(stream.stream_id)!,
- );
-
- assert(non_stream_items.length === 1);
- assert(util.the(non_stream_items).is_direct_message === true);
- return add_direct_messages_option(sorted_stream_items);
- },
});
compose_select_recipient_dropdown_widget.setup();
diff --git a/web/src/dropdown_widget.ts b/web/src/dropdown_widget.ts
index ed4b475cb59..aa18b851616 100644
--- a/web/src/dropdown_widget.ts
+++ b/web/src/dropdown_widget.ts
@@ -91,7 +91,6 @@ export type DropdownWidgetOptions = {
// When this is set, pressing tab will move focus to the target element.
tab_moves_focus_to_target?: string | (() => string);
search_placeholder_text?: string;
- sort_list_by_filter_value?: (items: Option[], filter_value: string) => Option[];
};
export class DropdownWidget {
@@ -140,7 +139,6 @@ export class DropdownWidget {
// here, so should be generalized or reworked.
item_clicked = false;
search_placeholder_text: string;
- sort_list_by_filter_value: ((items: Option[], filter_value: string) => Option[]) | undefined;
constructor(options: DropdownWidgetOptions) {
this.widget_name = options.widget_name;
@@ -182,7 +180,6 @@ export class DropdownWidget {
this.tab_moves_focus_to_target = options.tab_moves_focus_to_target;
this.current_hover_index = 0;
this.search_placeholder_text = options.search_placeholder_text ?? "";
- this.sort_list_by_filter_value = options.sort_list_by_filter_value;
}
init(): void {
@@ -401,7 +398,6 @@ export class DropdownWidget {
},
},
$simplebar_container: $popper.find(".dropdown-list-wrapper"),
- sort_by_filter_value: this.sort_list_by_filter_value,
},
);
diff --git a/web/src/list_widget.ts b/web/src/list_widget.ts
index e30c884dd98..a257c803e68 100644
--- a/web/src/list_widget.ts
+++ b/web/src/list_widget.ts
@@ -13,7 +13,6 @@ type ListWidgetMeta<Key, Item = Key> = {
sorting_function: SortingFunction<Item> | null;
applied_sorting_functions: [SortingFunction<Item>, boolean][]; // This is used to keep track of the sorting functions applied.
sorting_functions: Map<string, SortingFunction<Item>>;
- sort_by_filter_value?: (items: Item[], filter_value: string) => Item[];
filter_value: string;
has_active_filters: boolean;
offset: number;
@@ -58,7 +57,6 @@ type ListWidgetOpts<Key, Item = Key> = {
sort_fields?: Record<string, SortingFunction<Item>>;
$simplebar_container: JQuery;
$parent_container?: JQuery;
- sort_by_filter_value?: ((items: Item[], filter_value: string) => Item[]) | undefined;
};
type BaseListWidget = {
@@ -297,10 +295,6 @@ export function create<Key, Item = Key>(
$scroll_listening_element,
};
- if (opts.sort_by_filter_value) {
- meta.sort_by_filter_value = opts.sort_by_filter_value;
- }
-
const widget: ListWidget<Key, Item> = {
get_current_list() {
return meta.filtered_list;
@@ -313,15 +307,6 @@ export function create<Key, Item = Key>(
filter_and_sort() {
meta.filtered_list = get_filtered_items(meta.filter_value, meta.list, opts);
- if (meta.sort_by_filter_value) {
- assert(meta.sorting_function === null);
- meta.filtered_list = meta.sort_by_filter_value(
- meta.filtered_list,
- meta.filter_value,
- );
- return;
- }
-
if (meta.sorting_function) {
// If the sorting function is already applied, remove it to avoid duplicate sorting.
const existing_sorting_function_index = meta.applied_sorting_functions.findIndex(
diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.ts
index f130217088d..f0ff65e7108 100644
--- a/web/src/typeahead_helper.ts
+++ b/web/src/typeahead_helper.ts
@@ -1039,7 +1039,7 @@ function compare_by_user_group_name(group_a: UserGroup, group_b: UserGroup): num
return util.strcmp(group_a.name, group_b.name);
}
-export let sort_streams = <T extends StreamSubscription>(matches: T[], query: string): T[] => {
+export let sort_streams = (matches: StreamPillData[], query: string): StreamPillData[] => {
const name_results = typeahead.triage(query, matches, (x) => x.name, compare_by_activity);
const desc_results = typeahead.triage(
query,