mirror of https://github.com/zulip/zulip.git
submessage: Convert module to TypeScript.
This commit is contained in:
parent
a101e161dc
commit
f1db30418b
|
@ -243,7 +243,7 @@ EXEMPT_FILES = make_set(
|
|||
"web/src/stream_settings_containers.ts",
|
||||
"web/src/stream_settings_ui.js",
|
||||
"web/src/stream_ui_updates.js",
|
||||
"web/src/submessage.js",
|
||||
"web/src/submessage.ts",
|
||||
"web/src/subscriber_api.ts",
|
||||
"web/src/timerender.ts",
|
||||
"web/src/tippyjs.ts",
|
||||
|
|
|
@ -3,6 +3,8 @@ import z from "zod";
|
|||
import * as blueslip from "./blueslip";
|
||||
import * as channel from "./channel";
|
||||
import * as message_store from "./message_store";
|
||||
import type {Message} from "./message_store";
|
||||
import type {Submessage} from "./types";
|
||||
import * as widgetize from "./widgetize";
|
||||
|
||||
export const zform_widget_extra_data_schema = z.object({
|
||||
|
@ -47,7 +49,9 @@ const submessages_event_schema = z
|
|||
.tuple([widget_data_event_schema])
|
||||
.rest(inbound_data_event_schema);
|
||||
|
||||
export function get_message_events(message) {
|
||||
type SubmessageEvents = z.infer<typeof submessages_event_schema>;
|
||||
|
||||
export function get_message_events(message: Message): SubmessageEvents | undefined {
|
||||
if (message.locally_echoed) {
|
||||
return undefined;
|
||||
}
|
||||
|
@ -70,18 +74,19 @@ export function get_message_events(message) {
|
|||
return clean_events;
|
||||
}
|
||||
|
||||
export function process_submessages(in_opts) {
|
||||
export function process_submessages(in_opts: {$row: JQuery; message_id: number}): void {
|
||||
// This happens in our rendering path, so we try to limit any
|
||||
// damage that may be triggered by one rogue message.
|
||||
try {
|
||||
return do_process_submessages(in_opts);
|
||||
do_process_submessages(in_opts);
|
||||
return;
|
||||
} catch (error) {
|
||||
blueslip.error("Failed to do_process_submessages", undefined, error);
|
||||
return undefined;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export function do_process_submessages(in_opts) {
|
||||
export function do_process_submessages(in_opts: {$row: JQuery; message_id: number}): void {
|
||||
const message_id = in_opts.message_id;
|
||||
const message = message_store.get(message_id);
|
||||
|
||||
|
@ -129,7 +134,7 @@ export function do_process_submessages(in_opts) {
|
|||
});
|
||||
}
|
||||
|
||||
export function update_message(submsg) {
|
||||
export function update_message(submsg: Submessage): void {
|
||||
const message = message_store.get(submsg.message_id);
|
||||
|
||||
if (message === undefined) {
|
||||
|
@ -154,7 +159,7 @@ export function update_message(submsg) {
|
|||
message.submessages.push(submsg);
|
||||
}
|
||||
|
||||
export function handle_event(submsg) {
|
||||
export function handle_event(submsg: Submessage): void {
|
||||
// Update message.submessages in case we haven't actually
|
||||
// activated the widget yet, so that when the message does
|
||||
// come in view, the data will be complete.
|
||||
|
@ -184,11 +189,13 @@ export function handle_event(submsg) {
|
|||
});
|
||||
}
|
||||
|
||||
export function make_server_callback(message_id) {
|
||||
return function (opts) {
|
||||
export function make_server_callback(
|
||||
message_id: number,
|
||||
): (opts: {msg_type: string; data: string}) => void {
|
||||
return function (opts: {msg_type: string; data: string}) {
|
||||
const url = "/json/submessage";
|
||||
|
||||
channel.post({
|
||||
void channel.post({
|
||||
url,
|
||||
data: {
|
||||
message_id,
|
Loading…
Reference in New Issue