mirror of https://github.com/zulip/zulip.git
condense: Modify height offset to collapse messages.
Fixes #31501 Collapse all unread messages that are over min(150 em, 2*viewport_height). Collapse all bot messages and human messages marked as read that are over max(35 em, 0.65*viewport_height).
This commit is contained in:
parent
ce284a6e89
commit
abf1183abc
|
@ -8,6 +8,7 @@ import * as message_lists from "./message_lists.ts";
|
||||||
import type {Message} from "./message_store.ts";
|
import type {Message} from "./message_store.ts";
|
||||||
import * as message_viewport from "./message_viewport.ts";
|
import * as message_viewport from "./message_viewport.ts";
|
||||||
import * as rows from "./rows.ts";
|
import * as rows from "./rows.ts";
|
||||||
|
import {user_settings} from "./user_settings.ts";
|
||||||
import * as util from "./util.ts";
|
import * as util from "./util.ts";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -169,9 +170,16 @@ export function condense_and_collapse(elems: JQuery): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const height_cutoff = message_viewport.max_message_height();
|
const height_cutoff_unread = Math.min(
|
||||||
const rows_to_resize = [];
|
150 * user_settings.web_font_size_px,
|
||||||
|
message_viewport.height() * 2,
|
||||||
|
);
|
||||||
|
const height_cutoff_read = Math.max(
|
||||||
|
35 * user_settings.web_font_size_px,
|
||||||
|
0.65 * message_viewport.height(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const rows_to_resize = [];
|
||||||
for (const elem of elems) {
|
for (const elem of elems) {
|
||||||
const $content = $(elem).find(".message_content");
|
const $content = $(elem).find(".message_content");
|
||||||
|
|
||||||
|
@ -207,6 +215,7 @@ export function condense_and_collapse(elems: JQuery): void {
|
||||||
// changing the layout of the page, which is more performanant.
|
// changing the layout of the page, which is more performanant.
|
||||||
// More information here: https://web.dev/avoid-large-complex-layouts-and-layout-thrashing/#avoid-layout-thrashing
|
// More information here: https://web.dev/avoid-large-complex-layouts-and-layout-thrashing/#avoid-layout-thrashing
|
||||||
for (const {elem, $content, message, message_height} of rows_to_resize) {
|
for (const {elem, $content, message, message_height} of rows_to_resize) {
|
||||||
|
const height_cutoff = message.unread ? height_cutoff_unread : height_cutoff_read;
|
||||||
const long_message = message_height > height_cutoff;
|
const long_message = message_height > height_cutoff;
|
||||||
if (long_message) {
|
if (long_message) {
|
||||||
// All long messages are flagged as such.
|
// All long messages are flagged as such.
|
||||||
|
|
|
@ -23,13 +23,6 @@ const cached_height = new util.CachedValue({compute_value: () => $scroll_contain
|
||||||
export const width = cached_width.get.bind(cached_width);
|
export const width = cached_width.get.bind(cached_width);
|
||||||
export const height = cached_height.get.bind(cached_height);
|
export const height = cached_height.get.bind(cached_height);
|
||||||
|
|
||||||
// TODO: This function lets us use the DOM API instead of jquery
|
|
||||||
// (<10x faster) for condense.js, but we want to eventually do a
|
|
||||||
// bigger of refactor `height` and `width` above to do the same.
|
|
||||||
export function max_message_height(): number {
|
|
||||||
return document.querySelector("html")!.offsetHeight * 0.65;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Includes both scroll and arrow events. Negative means scroll up,
|
// Includes both scroll and arrow events. Negative means scroll up,
|
||||||
// positive means scroll down.
|
// positive means scroll down.
|
||||||
export let last_movement_direction = 1;
|
export let last_movement_direction = 1;
|
||||||
|
|
Loading…
Reference in New Issue