mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	message_actions_popover: Convert module to TypeScript.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							1aee0ef98b
						
					
				
				
					commit
					9f4b4a0c8a
				
			@@ -133,7 +133,7 @@ EXEMPT_FILES = make_set(
 | 
				
			|||||||
        "web/src/loading.ts",
 | 
					        "web/src/loading.ts",
 | 
				
			||||||
        "web/src/local_message.ts",
 | 
					        "web/src/local_message.ts",
 | 
				
			||||||
        "web/src/localstorage.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.ts",
 | 
				
			||||||
        "web/src/message_edit_history.ts",
 | 
					        "web/src/message_edit_history.ts",
 | 
				
			||||||
        "web/src/message_events.js",
 | 
					        "web/src/message_events.js",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -192,7 +192,7 @@ export function rewire_selection_within_message_id(
 | 
				
			|||||||
    selection_within_message_id = value;
 | 
					    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_id: number;
 | 
				
			||||||
    message: Message;
 | 
					    message: Message;
 | 
				
			||||||
    quote_content: string | undefined;
 | 
					    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: {
 | 
					export function quote_and_reply(opts: {
 | 
				
			||||||
    message_id: number;
 | 
					    message_id: number;
 | 
				
			||||||
    quote_content?: string;
 | 
					    quote_content?: string | undefined;
 | 
				
			||||||
    keep_composebox_empty?: boolean;
 | 
					    keep_composebox_empty?: boolean;
 | 
				
			||||||
    reply_type?: "personal";
 | 
					    reply_type?: "personal";
 | 
				
			||||||
    trigger?: string;
 | 
					    trigger?: string;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,7 @@ import * as hashchange from "./hashchange.js";
 | 
				
			|||||||
import * as inbox_ui from "./inbox_ui.ts";
 | 
					import * as inbox_ui from "./inbox_ui.ts";
 | 
				
			||||||
import * as lightbox from "./lightbox.ts";
 | 
					import * as lightbox from "./lightbox.ts";
 | 
				
			||||||
import * as list_util from "./list_util.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 from "./message_edit.ts";
 | 
				
			||||||
import * as message_edit_history from "./message_edit_history.ts";
 | 
					import * as message_edit_history from "./message_edit_history.ts";
 | 
				
			||||||
import * as message_lists from "./message_lists.ts";
 | 
					import * as message_lists from "./message_lists.ts";
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,13 +4,13 @@ import assert from "minimalistic-assert";
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import render_message_actions_popover from "../templates/popovers/message_actions_popover.hbs";
 | 
					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 compose_reply from "./compose_reply.ts";
 | 
				
			||||||
import * as condense from "./condense.ts";
 | 
					import * as condense from "./condense.ts";
 | 
				
			||||||
import {show_copied_confirmation} from "./copied_tooltip.ts";
 | 
					import {show_copied_confirmation} from "./copied_tooltip.ts";
 | 
				
			||||||
import * as emoji_picker from "./emoji_picker.ts";
 | 
					import * as emoji_picker from "./emoji_picker.ts";
 | 
				
			||||||
import * as message_edit from "./message_edit.ts";
 | 
					import * as message_edit from "./message_edit.ts";
 | 
				
			||||||
import * as message_lists from "./message_lists.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 message_viewport from "./message_viewport.ts";
 | 
				
			||||||
import * as popover_menus from "./popover_menus.ts";
 | 
					import * as popover_menus from "./popover_menus.ts";
 | 
				
			||||||
import * as popover_menus_data from "./popover_menus_data.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 * as stream_popover from "./stream_popover.ts";
 | 
				
			||||||
import {parse_html} from "./ui_util.ts";
 | 
					import {parse_html} from "./ui_util.ts";
 | 
				
			||||||
import * as unread_ops from "./unread_ops.ts";
 | 
					import * as unread_ops from "./unread_ops.ts";
 | 
				
			||||||
 | 
					import {the} from "./util.ts";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let message_actions_popover_keyboard_toggle = false;
 | 
					let message_actions_popover_keyboard_toggle = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function get_action_menu_menu_items() {
 | 
					function get_action_menu_menu_items(): JQuery {
 | 
				
			||||||
    const $current_actions_popover_elem = $("[data-tippy-root] #message-actions-menu-dropdown");
 | 
					    return $("[data-tippy-root] #message-actions-menu-dropdown li:not(.divider):visible a");
 | 
				
			||||||
    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 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.
 | 
					    // 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.
 | 
					    // Our popup menus act kind of funny when you mix keyboard and mouse.
 | 
				
			||||||
    const $items = get_action_menu_menu_items();
 | 
					    const $items = get_action_menu_menu_items();
 | 
				
			||||||
    popover_menus.focus_first_popover_item($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()) {
 | 
					    if (popover_menus.is_message_actions_popover_displayed()) {
 | 
				
			||||||
        popovers.hide_all();
 | 
					        popovers.hide_all();
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
@@ -69,7 +64,7 @@ export function toggle_message_actions_menu(message) {
 | 
				
			|||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function initialize() {
 | 
					export function initialize(): void {
 | 
				
			||||||
    popover_menus.register_popover_menu(".actions_hover .message-actions-menu-button", {
 | 
					    popover_menus.register_popover_menu(".actions_hover .message-actions-menu-button", {
 | 
				
			||||||
        theme: "popover-menu",
 | 
					        theme: "popover-menu",
 | 
				
			||||||
        placement: "bottom",
 | 
					        placement: "bottom",
 | 
				
			||||||
@@ -96,7 +91,7 @@ export function initialize() {
 | 
				
			|||||||
        onMount(instance) {
 | 
					        onMount(instance) {
 | 
				
			||||||
            const $row = $(instance.reference).closest(".message_row");
 | 
					            const $row = $(instance.reference).closest(".message_row");
 | 
				
			||||||
            const message_id = rows.id($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 (compose_reply.selection_within_message_id() === message_id) {
 | 
				
			||||||
                // If the user has selected text within this message, quote only that.
 | 
					                // If the user has selected text within this message, quote only that.
 | 
				
			||||||
                // We track the selection right now, before the popover option for Quote
 | 
					                // We track the selection right now, before the popover option for Quote
 | 
				
			||||||
@@ -139,7 +134,8 @@ export function initialize() {
 | 
				
			|||||||
                assert(message_lists.current !== undefined);
 | 
					                assert(message_lists.current !== undefined);
 | 
				
			||||||
                message_lists.current.select_id(message_id);
 | 
					                message_lists.current.select_id(message_id);
 | 
				
			||||||
                const message = message_lists.current.get(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.stream_id,
 | 
				
			||||||
                    message.topic,
 | 
					                    message.topic,
 | 
				
			||||||
                    false,
 | 
					                    false,
 | 
				
			||||||
@@ -178,9 +174,11 @@ export function initialize() {
 | 
				
			|||||||
                assert(message_lists.current !== undefined);
 | 
					                assert(message_lists.current !== undefined);
 | 
				
			||||||
                const $row = message_lists.current.get_row(message_id);
 | 
					                const $row = message_lists.current.get_row(message_id);
 | 
				
			||||||
                const message = message_lists.current.get(rows.id($row));
 | 
					                const message = message_lists.current.get(rows.id($row));
 | 
				
			||||||
 | 
					                assert(message !== undefined);
 | 
				
			||||||
                const message_container = message_lists.current.view.message_containers.get(
 | 
					                const message_container = message_lists.current.view.message_containers.get(
 | 
				
			||||||
                    message.id,
 | 
					                    message.id,
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
 | 
					                assert(message_container !== undefined);
 | 
				
			||||||
                if ($row && !message_container.is_hidden) {
 | 
					                if ($row && !message_container.is_hidden) {
 | 
				
			||||||
                    message_lists.current.view.hide_revealed_message(message_id);
 | 
					                    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.
 | 
					                // emoji_picker which we don't want to hide after actions popover is hidden.
 | 
				
			||||||
                e.stopPropagation();
 | 
					                e.stopPropagation();
 | 
				
			||||||
                e.preventDefault();
 | 
					                e.preventDefault();
 | 
				
			||||||
 | 
					                assert(instance.reference.parentElement !== null);
 | 
				
			||||||
                emoji_picker.toggle_emoji_popover(instance.reference.parentElement, message_id, {
 | 
					                emoji_picker.toggle_emoji_popover(instance.reference.parentElement, message_id, {
 | 
				
			||||||
                    placement: "bottom",
 | 
					                    placement: "bottom",
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
                popover_menus.hide_current_popover_if_visible(instance);
 | 
					                popover_menus.hide_current_popover_if_visible(instance);
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            new ClipboardJS($popper.find(".copy_link")[0]).on("success", () => {
 | 
					            new ClipboardJS(the($popper.find(".copy_link"))).on("success", () => {
 | 
				
			||||||
                show_copied_confirmation($(instance.reference).closest(".message_controls")[0]);
 | 
					                show_copied_confirmation(the($(instance.reference).closest(".message_controls")));
 | 
				
			||||||
                setTimeout(() => {
 | 
					                setTimeout(() => {
 | 
				
			||||||
                    // The Clipboard library works by focusing to a hidden textarea.
 | 
					                    // The Clipboard library works by focusing to a hidden textarea.
 | 
				
			||||||
                    // We unfocus this so keyboard shortcuts, etc., will work again.
 | 
					                    // We unfocus this so keyboard shortcuts, etc., will work again.
 | 
				
			||||||
@@ -231,7 +230,7 @@ export function initialize() {
 | 
				
			|||||||
            const $row = $(instance.reference).closest(".message_row");
 | 
					            const $row = $(instance.reference).closest(".message_row");
 | 
				
			||||||
            $row.removeClass("has_actions_popover");
 | 
					            $row.removeClass("has_actions_popover");
 | 
				
			||||||
            instance.destroy();
 | 
					            instance.destroy();
 | 
				
			||||||
            popover_menus.popover_instances.message_actions = undefined;
 | 
					            popover_menus.popover_instances.message_actions = null;
 | 
				
			||||||
            message_actions_popover_keyboard_toggle = false;
 | 
					            message_actions_popover_keyboard_toggle = false;
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
@@ -632,7 +632,7 @@ function start_edit_maintaining_scroll($row: JQuery, content: string): void {
 | 
				
			|||||||
function start_edit_with_content(
 | 
					function start_edit_with_content(
 | 
				
			||||||
    $row: JQuery,
 | 
					    $row: JQuery,
 | 
				
			||||||
    content: string,
 | 
					    content: string,
 | 
				
			||||||
    edit_box_open_callback: () => void,
 | 
					    edit_box_open_callback?: () => void,
 | 
				
			||||||
): void {
 | 
					): void {
 | 
				
			||||||
    start_edit_maintaining_scroll($row, content);
 | 
					    start_edit_maintaining_scroll($row, content);
 | 
				
			||||||
    if (edit_box_open_callback) {
 | 
					    if (edit_box_open_callback) {
 | 
				
			||||||
@@ -642,7 +642,7 @@ function start_edit_with_content(
 | 
				
			|||||||
    upload.setup_upload(upload.edit_config(row_id));
 | 
					    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);
 | 
					    assert(message_lists.current !== undefined);
 | 
				
			||||||
    const message = message_lists.current.get(rows.id($row));
 | 
					    const message = message_lists.current.get(rows.id($row));
 | 
				
			||||||
    if (message === undefined) {
 | 
					    if (message === undefined) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,7 +59,7 @@ import * as linkifiers from "./linkifiers.ts";
 | 
				
			|||||||
import * as local_message from "./local_message.ts";
 | 
					import * as local_message from "./local_message.ts";
 | 
				
			||||||
import * as markdown from "./markdown.ts";
 | 
					import * as markdown from "./markdown.ts";
 | 
				
			||||||
import * as markdown_config from "./markdown_config.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_edit_history from "./message_edit_history.ts";
 | 
				
			||||||
import * as message_fetch from "./message_fetch.ts";
 | 
					import * as message_fetch from "./message_fetch.ts";
 | 
				
			||||||
import * as message_list_hover from "./message_list_hover.ts";
 | 
					import * as message_list_hover from "./message_list_hover.ts";
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user