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.

popovers: Exclude clicked date from "Scroll to" suggestions.

Shubham Padiaa68780a9059b
diff --git a/web/src/click_handlers.ts b/web/src/click_handlers.ts
index bd20b488ee9..b7047df994e 100644
--- a/web/src/click_handlers.ts
+++ b/web/src/click_handlers.ts
@@ -479,7 +479,11 @@ export function initialize(): void {
popover_menus.on_show_prep(instance);
assert(message_lists.current !== undefined);
const messages = message_lists.current.all_messages();
- const suggested_dates = popover_menus_data.get_scroll_to_date_suggestions(messages);
+ const clicked_message = message_lists.current.get(message_id)!;
+ const suggested_dates = popover_menus_data.get_scroll_to_date_suggestions(
+ messages,
+ clicked_message.timestamp,
+ );
instance.setContent(parse_html(render_scroll_to_time_popover({suggested_dates})));
},
onMount(instance) {
diff --git a/web/src/popover_menus_data.ts b/web/src/popover_menus_data.ts
index ac4de30548a..5d1b5020661 100644
--- a/web/src/popover_menus_data.ts
+++ b/web/src/popover_menus_data.ts
@@ -579,16 +579,24 @@ function closest_index(cumulative: number[], target: number): number {
// Algorithm: divide the message volume into equal slices, then
// for each slice boundary, prefer a nearby date with a long
// silence before it (the start of a new conversation burst).
-export function get_scroll_to_date_suggestions(messages: Message[]): ScrollToDateSuggestion[] {
+export function get_scroll_to_date_suggestions(
+ messages: Message[],
+ clicked_timestamp?: number,
+): ScrollToDateSuggestion[] {
if (messages.length === 0) {
return [];
}
const date_groups = build_date_groups(messages);
- // Exclude today — the user is likely already there.
+ // Exclude today (the user is likely already there) and the
+ // clicked date if any (the user just signaled it isn't useful).
const today_key = get_date_key(Date.now() / 1000);
- const filtered_groups = date_groups.filter((group) => group.date_string !== today_key);
+ const clicked_key =
+ clicked_timestamp === undefined ? undefined : get_date_key(clicked_timestamp);
+ const filtered_groups = date_groups.filter(
+ (group) => group.date_string !== today_key && group.date_string !== clicked_key,
+ );
if (filtered_groups.length === 0) {
return [];
diff --git a/web/tests/popover_menus_data.test.cjs b/web/tests/popover_menus_data.test.cjs
index 4046dace551..33a3bf2216d 100644
--- a/web/tests/popover_menus_data.test.cjs
+++ b/web/tests/popover_menus_data.test.cjs
@@ -431,3 +431,37 @@ run_test("get_scroll_to_date_suggestions - single date in the past", () => {
const result = popover_menus_data.get_scroll_to_date_suggestions(messages);
assert.equal(result.length, 1);
});
+
+run_test("get_scroll_to_date_suggestions - excludes the clicked date", () => {
+ const messages = [
+ make_message(1, date_timestamp("2025-01-10")),
+ make_message(2, date_timestamp("2025-02-15")),
+ make_message(3, date_timestamp("2025-03-20")),
+ ];
+ const result = popover_menus_data.get_scroll_to_date_suggestions(
+ messages,
+ date_timestamp("2025-02-15"),
+ );
+ assert.equal(result.length, 2);
+ const dates = result.map((date) => date.iso_date_string.slice(0, 10));
+ assert.ok(!dates.includes("2025-02-15"));
+});
+
+run_test("get_scroll_to_date_suggestions - clicked slot is replaced not dropped", () => {
+ const messages = make_messages_from_date_counts(FOUR_MESSAGE_BURSTS);
+ const clicked_date = "2025-02-12";
+
+ const baseline = popover_menus_data.get_scroll_to_date_suggestions(messages);
+ const baseline_dates = baseline.map((s) => s.iso_date_string.slice(0, 10));
+ // The clicked date must be one the slicer would otherwise
+ // pick, or this test proves nothing.
+ assert.ok(baseline_dates.includes(clicked_date));
+
+ const filtered = popover_menus_data.get_scroll_to_date_suggestions(
+ messages,
+ date_timestamp(clicked_date),
+ );
+ const filtered_dates = filtered.map((date) => date.iso_date_string.slice(0, 10));
+ assert.equal(filtered.length, baseline.length);
+ assert.ok(!filtered_dates.includes(clicked_date));
+});