condense: Convert module to Typescript.

This commit is contained in:
Temidayo32 2024-03-07 20:46:14 +00:00 committed by Tim Abbott
parent e00641b0c4
commit 42dd55df42
3 changed files with 24 additions and 20 deletions

View File

@ -81,7 +81,7 @@ EXEMPT_FILES = make_set(
"web/src/compose_ui.ts",
"web/src/compose_validate.js",
"web/src/composebox_typeahead.js",
"web/src/condense.js",
"web/src/condense.ts",
"web/src/confirm_dialog.ts",
"web/src/copied_tooltip.ts",
"web/src/copy_and_paste.js",

View File

@ -3,6 +3,7 @@ import assert from "minimalistic-assert";
import * as message_flags from "./message_flags";
import * as message_lists from "./message_lists";
import type {Message} from "./message_store";
import * as message_viewport from "./message_viewport";
import * as rows from "./rows";
@ -18,35 +19,35 @@ This library implements two related, similar concepts:
*/
function show_more_link($row) {
function show_more_link($row: JQuery): void {
$row.find(".message_condenser").hide();
$row.find(".message_expander").show();
}
function show_condense_link($row) {
function show_condense_link($row: JQuery): void {
$row.find(".message_expander").hide();
$row.find(".message_condenser").show();
}
function condense_row($row) {
function condense_row($row: JQuery): void {
const $content = $row.find(".message_content");
$content.addClass("condensed");
show_more_link($row);
}
function uncondense_row($row) {
function uncondense_row($row: JQuery): void {
const $content = $row.find(".message_content");
$content.removeClass("condensed");
show_condense_link($row);
}
export function uncollapse(message) {
export function uncollapse(message: Message): void {
// Uncollapse a message, restoring the condensed message "Show more" or
// "Show less" button if necessary.
message.collapsed = false;
message_flags.save_uncollapsed(message);
const process_row = function process_row($row) {
const process_row = function process_row($row: JQuery): void {
const $content = $row.find(".message_content");
$content.removeClass("collapsed");
@ -75,7 +76,7 @@ export function uncollapse(message) {
}
}
export function collapse(message) {
export function collapse(message: Message): void {
message.collapsed = true;
if (message.locally_echoed) {
@ -88,7 +89,7 @@ export function collapse(message) {
message_flags.save_collapsed(message);
const process_row = function process_row($row) {
const process_row = function process_row($row: JQuery): void {
$row.find(".message_content").addClass("collapsed");
show_more_link($row);
};
@ -101,7 +102,7 @@ export function collapse(message) {
}
}
export function toggle_collapse(message) {
export function toggle_collapse(message: Message): void {
if (message.is_me_message) {
// Disabled temporarily because /me messages don't have a
// styling for collapsing /me messages (they only recently
@ -146,38 +147,38 @@ export function toggle_collapse(message) {
}
}
function get_message_height(elem) {
function get_message_height(elem: HTMLElement): number {
// This needs to be very fast. This function runs hundreds of times
// when displaying a message feed view that has hundreds of message
// history, which ideally should render in <100ms.
return $(elem).find(".message_content")[0].scrollHeight;
}
export function hide_message_expander($row) {
export function hide_message_expander($row: JQuery): void {
if ($row.find(".could-be-condensed").length !== 0) {
$row.find(".message_expander").hide();
}
}
export function hide_message_condenser($row) {
export function hide_message_condenser($row: JQuery): void {
if ($row.find(".could-be-condensed").length !== 0) {
$row.find(".message_condenser").hide();
}
}
export function show_message_expander($row) {
export function show_message_expander($row: JQuery): void {
if ($row.find(".could-be-condensed").length !== 0) {
$row.find(".message_expander").show();
}
}
export function show_message_condenser($row) {
export function show_message_condenser($row: JQuery): void {
if ($row.find(".could-be-condensed").length !== 0) {
$row.find(".message_condenser").show();
}
}
export function condense_and_collapse(elems) {
export function condense_and_collapse(elems: JQuery): void {
if (message_lists.current === undefined) {
return;
}
@ -205,7 +206,7 @@ export function condense_and_collapse(elems) {
continue;
}
const message_height = get_message_height(elem, message.id);
const message_height = get_message_height(elem);
rows_to_resize.push({
elem,
@ -257,7 +258,7 @@ export function condense_and_collapse(elems) {
}
}
export function initialize() {
export function initialize(): void {
$("#message_feed_container").on("click", ".message_expander", function (e) {
// Expanding a message can mean either uncollapsing or
// uncondensing it.
@ -265,6 +266,7 @@ export function initialize() {
const id = rows.id($row);
assert(message_lists.current !== undefined);
const message = message_lists.current.get(id);
assert(message !== undefined);
// Focus on the expanded message.
message_lists.current.select_id(id);
const $content = $row.find(".message_content");
@ -288,8 +290,9 @@ export function initialize() {
// Focus on the condensed message.
assert(message_lists.current !== undefined);
message_lists.current.select_id(id);
message_lists.current.get(id).condensed = true;
condense_row($row);
const message = message_lists.current.get(id);
assert(message !== undefined);
message.condensed = true;
e.stopPropagation();
e.preventDefault();
});

View File

@ -86,6 +86,7 @@ export type MessageWithBooleans = (
stream_wildcard_mentioned: boolean;
topic_wildcard_mentioned: boolean;
collapsed: boolean;
condensed?: boolean;
alerted: boolean;
};