Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_actions_popover: Convert module to TypeScript.
Anders Kaseorg9f4b4a0c8a59
diff --git a/tools/test-js-with-node b/tools/test-js-with-nodeindex 6fe2ca8a1c8..68a03511565 100755--- a/tools/test-js-with-node+++ b/tools/test-js-with-node@@ -133,7 +133,7 @@ EXEMPT_FILES = make_set("web/src/loading.ts","web/src/local_message.ts","web/src/localstorage.ts",- "web/src/message_actions_popover.js",+ "web/src/message_actions_popover.ts","web/src/message_edit.ts","web/src/message_edit_history.ts","web/src/message_events.js",diff --git a/web/src/compose_reply.ts b/web/src/compose_reply.tsindex 441049c4573..6a2810a7e88 100644--- a/web/src/compose_reply.ts+++ b/web/src/compose_reply.ts@@ -192,7 +192,7 @@ export function rewire_selection_within_message_id(selection_within_message_id = value;}-function get_quote_target(opts: {message_id?: number; quote_content?: string}): {+function get_quote_target(opts: {message_id?: number; quote_content?: string | undefined}): {message_id: number;message: Message;quote_content: string | undefined;@@ -229,7 +229,7 @@ function get_quote_target(opts: {message_id?: number; quote_content?: string}):export function quote_and_reply(opts: {message_id: number;- quote_content?: string;+ quote_content?: string | undefined;keep_composebox_empty?: boolean;reply_type?: "personal";trigger?: string;diff --git a/web/src/hotkey.js b/web/src/hotkey.jsindex 9247e461d1e..d42f1ef6d9e 100644--- a/web/src/hotkey.js+++ b/web/src/hotkey.js@@ -27,7 +27,7 @@ import * as hashchange from "./hashchange.js";import * as inbox_ui from "./inbox_ui.ts";import * as lightbox from "./lightbox.ts";import * as list_util from "./list_util.ts";-import * as message_actions_popover from "./message_actions_popover.js";+import * as message_actions_popover from "./message_actions_popover.ts";import * as message_edit from "./message_edit.ts";import * as message_edit_history from "./message_edit_history.ts";import * as message_lists from "./message_lists.ts";diff --git a/web/src/message_actions_popover.js b/web/src/message_actions_popover.tssimilarity index 90%rename from web/src/message_actions_popover.jsrename to web/src/message_actions_popover.tsindex eb10a8b632d..71a44da9717 100644--- a/web/src/message_actions_popover.js+++ b/web/src/message_actions_popover.ts@@ -4,13 +4,13 @@ import assert from "minimalistic-assert";import render_message_actions_popover from "../templates/popovers/message_actions_popover.hbs";-import * as blueslip from "./blueslip.ts";import * as compose_reply from "./compose_reply.ts";import * as condense from "./condense.ts";import {show_copied_confirmation} from "./copied_tooltip.ts";import * as emoji_picker from "./emoji_picker.ts";import * as message_edit from "./message_edit.ts";import * as message_lists from "./message_lists.ts";+import type {Message} from "./message_store.ts";import * as message_viewport from "./message_viewport.ts";import * as popover_menus from "./popover_menus.ts";import * as popover_menus_data from "./popover_menus_data.ts";@@ -20,27 +20,22 @@ import * as rows from "./rows.ts";import * as stream_popover from "./stream_popover.ts";import {parse_html} from "./ui_util.ts";import * as unread_ops from "./unread_ops.ts";+import {the} from "./util.ts";let message_actions_popover_keyboard_toggle = false;-function get_action_menu_menu_items() {- const $current_actions_popover_elem = $("[data-tippy-root] #message-actions-menu-dropdown");- if (!$current_actions_popover_elem) {- blueslip.error("Trying to get menu items when action popover is closed.");- return undefined;- }-- return $current_actions_popover_elem.find("li:not(.divider):visible a");+function get_action_menu_menu_items(): JQuery {+ return $("[data-tippy-root] #message-actions-menu-dropdown li:not(.divider):visible a");}-function focus_first_action_popover_item() {+function focus_first_action_popover_item(): void {// For now I recommend only calling this when the user opens the menu with a hotkey.// Our popup menus act kind of funny when you mix keyboard and mouse.const $items = get_action_menu_menu_items();popover_menus.focus_first_popover_item($items);}-export function toggle_message_actions_menu(message) {+export function toggle_message_actions_menu(message: Message): boolean {if (popover_menus.is_message_actions_popover_displayed()) {popovers.hide_all();return true;@@ -69,7 +64,7 @@ export function toggle_message_actions_menu(message) {return true;}-export function initialize() {+export function initialize(): void {popover_menus.register_popover_menu(".actions_hover .message-actions-menu-button", {theme: "popover-menu",placement: "bottom",@@ -96,7 +91,7 @@ export function initialize() {onMount(instance) {const $row = $(instance.reference).closest(".message_row");const message_id = rows.id($row);- let quote_content;+ let quote_content: string | undefined;if (compose_reply.selection_within_message_id() === message_id) {// If the user has selected text within this message, quote only that.// We track the selection right now, before the popover option for Quote@@ -139,7 +134,8 @@ export function initialize() {assert(message_lists.current !== undefined);message_lists.current.select_id(message_id);const message = message_lists.current.get(message_id);- stream_popover.build_move_topic_to_stream_popover(+ assert(message?.type === "stream");+ void stream_popover.build_move_topic_to_stream_popover(message.stream_id,message.topic,false,@@ -178,9 +174,11 @@ export function initialize() {assert(message_lists.current !== undefined);const $row = message_lists.current.get_row(message_id);const message = message_lists.current.get(rows.id($row));+ assert(message !== undefined);const message_container = message_lists.current.view.message_containers.get(message.id,);+ assert(message_container !== undefined);if ($row && !message_container.is_hidden) {message_lists.current.view.hide_revealed_message(message_id);}@@ -211,14 +209,15 @@ export function initialize() {// emoji_picker which we don't want to hide after actions popover is hidden.e.stopPropagation();e.preventDefault();+ assert(instance.reference.parentElement !== null);emoji_picker.toggle_emoji_popover(instance.reference.parentElement, message_id, {placement: "bottom",});popover_menus.hide_current_popover_if_visible(instance);});- new ClipboardJS($popper.find(".copy_link")[0]).on("success", () => {- show_copied_confirmation($(instance.reference).closest(".message_controls")[0]);+ new ClipboardJS(the($popper.find(".copy_link"))).on("success", () => {+ show_copied_confirmation(the($(instance.reference).closest(".message_controls")));setTimeout(() => {// The Clipboard library works by focusing to a hidden textarea.// We unfocus this so keyboard shortcuts, etc., will work again.@@ -231,7 +230,7 @@ export function initialize() {const $row = $(instance.reference).closest(".message_row");$row.removeClass("has_actions_popover");instance.destroy();- popover_menus.popover_instances.message_actions = undefined;+ popover_menus.popover_instances.message_actions = null;message_actions_popover_keyboard_toggle = false;},});diff --git a/web/src/message_edit.ts b/web/src/message_edit.tsindex 342aa7f5e2e..26785ba26cb 100644--- a/web/src/message_edit.ts+++ b/web/src/message_edit.ts@@ -632,7 +632,7 @@ function start_edit_maintaining_scroll($row: JQuery, content: string): void {function start_edit_with_content($row: JQuery,content: string,- edit_box_open_callback: () => void,+ edit_box_open_callback?: () => void,): void {start_edit_maintaining_scroll($row, content);if (edit_box_open_callback) {@@ -642,7 +642,7 @@ function start_edit_with_content(upload.setup_upload(upload.edit_config(row_id));}-export function start($row: JQuery, edit_box_open_callback: () => void): void {+export function start($row: JQuery, edit_box_open_callback?: () => void): void {assert(message_lists.current !== undefined);const message = message_lists.current.get(rows.id($row));if (message === undefined) {diff --git a/web/src/ui_init.js b/web/src/ui_init.jsindex c0ba1fae0e0..0c0706731b0 100644--- a/web/src/ui_init.js+++ b/web/src/ui_init.js@@ -59,7 +59,7 @@ import * as linkifiers from "./linkifiers.ts";import * as local_message from "./local_message.ts";import * as markdown from "./markdown.ts";import * as markdown_config from "./markdown_config.ts";-import * as message_actions_popover from "./message_actions_popover.js";+import * as message_actions_popover from "./message_actions_popover.ts";import * as message_edit_history from "./message_edit_history.ts";import * as message_fetch from "./message_fetch.ts";import * as message_list_hover from "./message_list_hover.ts";