rows: Convert module to typescript.

This commit is contained in:
evykassirer 2023-12-26 18:46:37 -08:00 committed by Anders Kaseorg
parent e3e0125092
commit 4e66e8742f
4 changed files with 33 additions and 24 deletions

View File

@ -184,7 +184,7 @@ EXEMPT_FILES = make_set(
"web/src/reminder.js",
"web/src/resize.js",
"web/src/resize_handler.js",
"web/src/rows.js",
"web/src/rows.ts",
"web/src/scheduled_messages.js",
"web/src/scheduled_messages_feed_ui.js",
"web/src/scheduled_messages_overlay_ui.js",

View File

@ -989,7 +989,7 @@ export class MessageListView {
const get_element = (message_group) => {
// We don't have a MessageGroup class, but we can at least hide the messy details
// of rows.js from compose_fade. We provide a callback function to be lazy--
// of rows.ts from compose_fade. We provide a callback function to be lazy--
// compose_fade may not actually need the elements depending on its internal
// state.
const $message_row = this.get_row(message_group.message_containers[0].msg.id);

View File

@ -14,6 +14,7 @@ type MessageListView = {
update_recipient_bar_background_color: () => void;
_render_win_start: number;
_render_win_end: number;
sticky_recipient_message_id: number | undefined;
};
export type MessageList = {

View File

@ -1,12 +1,15 @@
import $ from "jquery";
import assert from "minimalistic-assert";
import * as blueslip from "./blueslip";
import * as message_lists from "./message_lists";
import * as message_store from "./message_store";
import type {Message} from "./message_store";
// We don't need an andSelf() here because we already know
// that our next element is *not* a message_row, so this
// isn't going to end up empty unless we're at the bottom or top.
export function next_visible($message_row) {
export function next_visible($message_row: JQuery): JQuery {
if ($message_row === undefined || $message_row.length === 0) {
return $();
}
@ -22,7 +25,7 @@ export function next_visible($message_row) {
return $(".selectable_row", $next_recipient_rows[0]).first();
}
export function prev_visible($message_row) {
export function prev_visible($message_row: JQuery): JQuery {
if ($message_row === undefined || $message_row.length === 0) {
return $();
}
@ -38,15 +41,15 @@ export function prev_visible($message_row) {
return $(".selectable_row", $prev_recipient_rows[0]).last();
}
export function first_visible() {
export function first_visible(): JQuery {
return $(".focused-message-list .selectable_row").first();
}
export function last_visible() {
export function last_visible(): JQuery {
return $(".focused-message-list .selectable_row").last();
}
export function visible_range(start_id, end_id) {
export function visible_range(start_id: number, end_id: number): JQuery[] {
/*
Get all visible rows between start_id
and end_in, being inclusive on both ends.
@ -54,10 +57,11 @@ export function visible_range(start_id, end_id) {
const rows = [];
assert(message_lists.current);
let $row = message_lists.current.get_row(start_id);
let msg_id = id($row);
while (msg_id <= end_id) {
while (msg_id !== undefined && msg_id <= end_id) {
rows.push($row);
if (msg_id >= end_id) {
@ -70,11 +74,11 @@ export function visible_range(start_id, end_id) {
return rows;
}
export function is_overlay_row($row) {
export function is_overlay_row($row: JQuery): boolean {
return $row.closest(".overlay-message-row").length >= 1;
}
export function id($message_row) {
export function id($message_row: JQuery): number | undefined {
if (is_overlay_row($message_row)) {
blueslip.error("Drafts and scheduled messages have no zid");
return undefined;
@ -93,7 +97,7 @@ export function id($message_row) {
return Number.parseFloat(zid);
}
export function local_echo_id($message_row) {
export function local_echo_id($message_row: JQuery): string | undefined {
const zid = $message_row.attr("zid");
if (zid === undefined) {
@ -110,7 +114,7 @@ export function local_echo_id($message_row) {
const valid_table_names = new Set(["zhome", "zfilt"]);
export function get_table(table_name) {
export function get_table(table_name: string): JQuery {
if (!valid_table_names.has(table_name)) {
return $();
}
@ -118,7 +122,7 @@ export function get_table(table_name) {
return $(`#${CSS.escape(table_name)}`);
}
export function get_message_id(elem) {
export function get_message_id(elem: string): number | undefined {
// Gets the message_id for elem, where elem is a DOM
// element inside a message. This is typically used
// in click handlers for things like the reaction button.
@ -127,40 +131,44 @@ export function get_message_id(elem) {
return message_id;
}
export function get_closest_group(element) {
export function get_closest_group(element: string): JQuery {
// This gets the closest message row to an element, whether it's
// a recipient bar or message. With our current markup,
// this is the most reliable way to do it.
return $(element).closest("div.recipient_row");
}
export function get_closest_row(element) {
export function get_closest_row(element: string): JQuery {
return $(element).closest("div.message_row");
}
export function first_message_in_group(message_group) {
return $("div.message_row", message_group).first();
export function first_message_in_group($message_group: JQuery): JQuery {
return $("div.message_row", $message_group).first();
}
export function get_message_recipient_row($message_row) {
export function get_message_recipient_row($message_row: JQuery): JQuery {
return $message_row.parent(".recipient_row").expectOne();
}
export function get_message_recipient_header($message_row) {
export function get_message_recipient_header($message_row: JQuery): JQuery {
return $message_row.parent(".recipient_row").find(".message_header").expectOne();
}
export function recipient_from_group(message_group) {
return message_store.get(id($(message_group).children(".message_row").first().expectOne()));
export function recipient_from_group(message_group: string): Message | undefined {
const message_id = id($(message_group).children(".message_row").first().expectOne());
if (message_id === undefined) {
return undefined;
}
return message_store.get(message_id);
}
export function is_header_of_row_sticky($recipient_row) {
export function is_header_of_row_sticky($recipient_row: JQuery): boolean {
return $recipient_row.find(".message_header").hasClass("sticky_header");
}
export function id_for_recipient_row($recipient_row) {
export function id_for_recipient_row($recipient_row: JQuery): number | undefined {
if (is_header_of_row_sticky($recipient_row)) {
const msg_id = message_lists.current.view.sticky_recipient_message_id;
const msg_id = message_lists.current?.view.sticky_recipient_message_id;
if (msg_id !== undefined) {
return msg_id;
}