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.

message_viewport: Add message_feed_visible_top.

Shubham Padia0436c196292c
diff --git a/web/src/message_list_view.ts b/web/src/message_list_view.ts
index ffda71d7974..1cc964b1c23 100644
--- a/web/src/message_list_view.ts
+++ b/web/src/message_list_view.ts
@@ -2258,10 +2258,10 @@ export class MessageListView {
});
}
- const navbar_bottom = $("#navbar-fixed-container").outerHeight()!;
+ const message_feed_visible_top = message_viewport.message_feed_visible_top();
/* We need date to be properly visible on the header, so partially visible headers
who are about to be scrolled out of view are not acceptable. */
- const partially_hidden_header_position = navbar_bottom - 1;
+ const partially_hidden_header_position = message_feed_visible_top - 1;
function is_sticky(header: Element): number {
// header has a box-shadow of `1px` at top but since it doesn't impact
@@ -2270,7 +2270,7 @@ export class MessageListView {
// This value is dependent upon space between two `recipient_row` message groups.
const margin_between_recipient_rows = 10;
const sticky_or_about_to_be_sticky_header_position =
- navbar_bottom + header_props.height + margin_between_recipient_rows;
+ message_feed_visible_top + header_props.height + margin_between_recipient_rows;
if (header_props.top < partially_hidden_header_position) {
return -1;
}
diff --git a/web/src/message_view.ts b/web/src/message_view.ts
index 5dcf1c9ee99..3145f058b25 100644
--- a/web/src/message_view.ts
+++ b/web/src/message_view.ts
@@ -344,9 +344,8 @@ function handle_post_message_list_change(
}
function get_selected_message_top_offset(is_first_message_in_narrow = false): number {
- const navbar_height = $("#navbar-fixed-container").height()!;
let final_offset =
- navbar_height +
+ message_viewport.message_feed_visible_top() +
// Falls back to 30px height + 10px top margin if no sticky header is present.
($(".message_header").outerHeight(true) ?? 40);
diff --git a/web/src/message_viewport.ts b/web/src/message_viewport.ts
index 0eb373b8a7c..38dc52f29ee 100644
--- a/web/src/message_viewport.ts
+++ b/web/src/message_viewport.ts
@@ -51,6 +51,10 @@ export function at_rendered_top(): boolean {
return scrollTop() <= 0;
}
+export function message_feed_visible_top(): number {
+ return util.the($("#navbar-fixed-container")).getBoundingClientRect().bottom;
+}
+
export function message_viewport_info(): MessageViewportInfo {
// Return a structure that tells us details of the viewport
// accounting for fixed elements like the top navbar.
@@ -59,14 +63,13 @@ export function message_viewport_info(): MessageViewportInfo {
// message pane, which should make sense for callers, who will
// generally be concerned about whether actual message content is
// visible.
- const $element_just_above_us = $("#navbar-fixed-container");
const $element_just_below_us = $("#compose");
- let visible_top = $element_just_above_us.outerHeight() ?? 0;
+ let visible_top = message_feed_visible_top();
const $sticky_header = $(".sticky_header");
if ($sticky_header.length > 0) {
- visible_top += $sticky_header.outerHeight() ?? 0;
+ visible_top += util.the($sticky_header).getBoundingClientRect().height;
}
const visible_bottom = $element_just_below_us.position().top;
@@ -280,12 +283,11 @@ function add_to_visible<T>(
const top_of_feed = new util.CachedValue({
compute_value() {
- const $header = $("#navbar-fixed-container");
- let visible_top = $header.outerHeight() ?? 0;
+ let visible_top = message_feed_visible_top();
const $sticky_header = $(".sticky_header");
if ($sticky_header.length > 0) {
- visible_top += $sticky_header.outerHeight() ?? 0;
+ visible_top += util.the($sticky_header).getBoundingClientRect().height;
}
return visible_top;
},
diff --git a/web/tests/message_view.test.cjs b/web/tests/message_view.test.cjs
index 2a3b246c4f8..2b9d5f35d9e 100644
--- a/web/tests/message_view.test.cjs
+++ b/web/tests/message_view.test.cjs
@@ -56,6 +56,7 @@ mock_esm("../src/compose_banner", {
clear_search_view_banner() {},
});
const compose_pm_pill = mock_esm("../src/compose_pm_pill");
+const message_viewport = mock_esm("../src/message_viewport");
const settings_data = mock_esm("../src/settings_data");
mock_esm("../src/spectators", {
login_to_access() {},
@@ -1124,7 +1125,7 @@ run_test("fast_track_current_msg_list_to_anchor date", ({override}) => {
selected = {id, opts};
};
message_lists.current = list;
- $("#navbar-fixed-container").set_height(50);
+ override(message_viewport, "message_feed_visible_top", () => 50);
$(".message_header").set_height(30);
// Date jumps should place the selected message below the sticky
// message header, increasing the target scroll offset by the