mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 11:52:01 +00:00
rows: Convert module to typescript.
This commit is contained in:
committed by
Anders Kaseorg
parent
e3e0125092
commit
4e66e8742f
@@ -184,7 +184,7 @@ EXEMPT_FILES = make_set(
|
|||||||
"web/src/reminder.js",
|
"web/src/reminder.js",
|
||||||
"web/src/resize.js",
|
"web/src/resize.js",
|
||||||
"web/src/resize_handler.js",
|
"web/src/resize_handler.js",
|
||||||
"web/src/rows.js",
|
"web/src/rows.ts",
|
||||||
"web/src/scheduled_messages.js",
|
"web/src/scheduled_messages.js",
|
||||||
"web/src/scheduled_messages_feed_ui.js",
|
"web/src/scheduled_messages_feed_ui.js",
|
||||||
"web/src/scheduled_messages_overlay_ui.js",
|
"web/src/scheduled_messages_overlay_ui.js",
|
||||||
|
|||||||
@@ -989,7 +989,7 @@ export class MessageListView {
|
|||||||
|
|
||||||
const get_element = (message_group) => {
|
const get_element = (message_group) => {
|
||||||
// We don't have a MessageGroup class, but we can at least hide the messy details
|
// 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
|
// compose_fade may not actually need the elements depending on its internal
|
||||||
// state.
|
// state.
|
||||||
const $message_row = this.get_row(message_group.message_containers[0].msg.id);
|
const $message_row = this.get_row(message_group.message_containers[0].msg.id);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ type MessageListView = {
|
|||||||
update_recipient_bar_background_color: () => void;
|
update_recipient_bar_background_color: () => void;
|
||||||
_render_win_start: number;
|
_render_win_start: number;
|
||||||
_render_win_end: number;
|
_render_win_end: number;
|
||||||
|
sticky_recipient_message_id: number | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MessageList = {
|
export type MessageList = {
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
import assert from "minimalistic-assert";
|
||||||
|
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import * as message_lists from "./message_lists";
|
import * as message_lists from "./message_lists";
|
||||||
import * as message_store from "./message_store";
|
import * as message_store from "./message_store";
|
||||||
|
import type {Message} from "./message_store";
|
||||||
|
|
||||||
// We don't need an andSelf() here because we already know
|
// We don't need an andSelf() here because we already know
|
||||||
// that our next element is *not* a message_row, so this
|
// 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.
|
// 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) {
|
if ($message_row === undefined || $message_row.length === 0) {
|
||||||
return $();
|
return $();
|
||||||
}
|
}
|
||||||
@@ -22,7 +25,7 @@ export function next_visible($message_row) {
|
|||||||
return $(".selectable_row", $next_recipient_rows[0]).first();
|
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) {
|
if ($message_row === undefined || $message_row.length === 0) {
|
||||||
return $();
|
return $();
|
||||||
}
|
}
|
||||||
@@ -38,15 +41,15 @@ export function prev_visible($message_row) {
|
|||||||
return $(".selectable_row", $prev_recipient_rows[0]).last();
|
return $(".selectable_row", $prev_recipient_rows[0]).last();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function first_visible() {
|
export function first_visible(): JQuery {
|
||||||
return $(".focused-message-list .selectable_row").first();
|
return $(".focused-message-list .selectable_row").first();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function last_visible() {
|
export function last_visible(): JQuery {
|
||||||
return $(".focused-message-list .selectable_row").last();
|
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
|
Get all visible rows between start_id
|
||||||
and end_in, being inclusive on both ends.
|
and end_in, being inclusive on both ends.
|
||||||
@@ -54,10 +57,11 @@ export function visible_range(start_id, end_id) {
|
|||||||
|
|
||||||
const rows = [];
|
const rows = [];
|
||||||
|
|
||||||
|
assert(message_lists.current);
|
||||||
let $row = message_lists.current.get_row(start_id);
|
let $row = message_lists.current.get_row(start_id);
|
||||||
let msg_id = id($row);
|
let msg_id = id($row);
|
||||||
|
|
||||||
while (msg_id <= end_id) {
|
while (msg_id !== undefined && msg_id <= end_id) {
|
||||||
rows.push($row);
|
rows.push($row);
|
||||||
|
|
||||||
if (msg_id >= end_id) {
|
if (msg_id >= end_id) {
|
||||||
@@ -70,11 +74,11 @@ export function visible_range(start_id, end_id) {
|
|||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function is_overlay_row($row) {
|
export function is_overlay_row($row: JQuery): boolean {
|
||||||
return $row.closest(".overlay-message-row").length >= 1;
|
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)) {
|
if (is_overlay_row($message_row)) {
|
||||||
blueslip.error("Drafts and scheduled messages have no zid");
|
blueslip.error("Drafts and scheduled messages have no zid");
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -93,7 +97,7 @@ export function id($message_row) {
|
|||||||
return Number.parseFloat(zid);
|
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");
|
const zid = $message_row.attr("zid");
|
||||||
|
|
||||||
if (zid === undefined) {
|
if (zid === undefined) {
|
||||||
@@ -110,7 +114,7 @@ export function local_echo_id($message_row) {
|
|||||||
|
|
||||||
const valid_table_names = new Set(["zhome", "zfilt"]);
|
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)) {
|
if (!valid_table_names.has(table_name)) {
|
||||||
return $();
|
return $();
|
||||||
}
|
}
|
||||||
@@ -118,7 +122,7 @@ export function get_table(table_name) {
|
|||||||
return $(`#${CSS.escape(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
|
// Gets the message_id for elem, where elem is a DOM
|
||||||
// element inside a message. This is typically used
|
// element inside a message. This is typically used
|
||||||
// in click handlers for things like the reaction button.
|
// in click handlers for things like the reaction button.
|
||||||
@@ -127,40 +131,44 @@ export function get_message_id(elem) {
|
|||||||
return message_id;
|
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
|
// This gets the closest message row to an element, whether it's
|
||||||
// a recipient bar or message. With our current markup,
|
// a recipient bar or message. With our current markup,
|
||||||
// this is the most reliable way to do it.
|
// this is the most reliable way to do it.
|
||||||
return $(element).closest("div.recipient_row");
|
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");
|
return $(element).closest("div.message_row");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function first_message_in_group(message_group) {
|
export function first_message_in_group($message_group: JQuery): JQuery {
|
||||||
return $("div.message_row", message_group).first();
|
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();
|
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();
|
return $message_row.parent(".recipient_row").find(".message_header").expectOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function recipient_from_group(message_group) {
|
export function recipient_from_group(message_group: string): Message | undefined {
|
||||||
return message_store.get(id($(message_group).children(".message_row").first().expectOne()));
|
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");
|
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)) {
|
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) {
|
if (msg_id !== undefined) {
|
||||||
return msg_id;
|
return msg_id;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user