Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
desktop_integration: Convert module to TypeScript.
Anders Kaseorgc1cd21d8d17c
diff --git a/tools/test-js-with-node b/tools/test-js-with-nodeindex 57436e460e0..b5f019b2fec 100755--- a/tools/test-js-with-node+++ b/tools/test-js-with-node@@ -93,7 +93,7 @@ EXEMPT_FILES = make_set("web/src/debug.ts","web/src/demo_organizations_ui.ts","web/src/deprecated_feature_notice.ts",- "web/src/desktop_integration.js",+ "web/src/desktop_integration.ts","web/src/desktop_notifications.ts","web/src/dialog_widget.ts","web/src/drafts.ts",diff --git a/web/src/desktop_integration.js b/web/src/desktop_integration.tssimilarity index 71%rename from web/src/desktop_integration.jsrename to web/src/desktop_integration.tsindex c9b1a03e28a..c67758f48f3 100644--- a/web/src/desktop_integration.js+++ b/web/src/desktop_integration.ts@@ -1,4 +1,6 @@import $ from "jquery";+import assert from "minimalistic-assert";+import {z} from "zod";import * as browser_history from "./browser_history.ts";import * as channel from "./channel.ts";@@ -9,7 +11,7 @@ import * as message_store from "./message_store.ts";import * as message_view from "./message_view.ts";import * as stream_data from "./stream_data.ts";-export function initialize() {+export function initialize(): void {if (electron_bridge === undefined) {return;}@@ -33,18 +35,21 @@ export function initialize() {electron_bridge.set_send_notification_reply_message_supported?.(true);electron_bridge.on_event("send_notification_reply_message", (message_id, reply) => {const message = message_store.get(message_id);+ assert(message !== undefined);const data = {type: message.type,content: reply,- topic: message.topic,+ ...(message.type === "private"+ ? {+ to: message.reply_to,+ }+ : {+ to: stream_data.get_stream_name_from_id(message.stream_id),+ topic: message.topic,+ }),};- if (message.type === "private") {- data.to = message.reply_to;- } else {- data.to = stream_data.get_stream_name_from_id(message.stream_id);- }- function success() {+ const success = (): void => {if (message.type === "stream") {message_view.narrow_by_topic(message_id, {trigger: "desktop_notification_reply"});} else {@@ -52,15 +57,16 @@ export function initialize() {trigger: "desktop_notification_reply",});}- }+ };- function error(error) {+ const error = (error: JQuery.jqXHR): void => {+ assert(electron_bridge !== undefined);electron_bridge.send_event("send_notification_reply_message_failed", {data,message_id,error,});- }+ };channel.post({url: "/json/messages",@@ -77,14 +83,20 @@ export function initialize() {channel.get({url,- success(data) {+ success(raw_data) {+ const data = z+ .object({result: z.literal("success"), billing_access_url: z.string()})+ .parse(raw_data);window.open(data.billing_access_url, "_blank", "noopener,noreferrer");},error(xhr) {- if (xhr.responseJSON?.msg) {+ const parsed = z+ .object({result: z.literal("error"), msg: z.string()})+ .safeParse(xhr.responseJSON);+ if (parsed.success) {feedback_widget.show({populate($container) {- $container.text(xhr.responseJSON.msg);+ $container.text(parsed.data.msg);},title_text: $t({defaultMessage: "Error"}),});diff --git a/web/src/electron_bridge.ts b/web/src/electron_bridge.tsindex 6c4c056fbcd..897b534493a 100644--- a/web/src/electron_bridge.ts+++ b/web/src/electron_bridge.ts@@ -23,7 +23,7 @@ export type ElectronBridge = {) => void) &((eventName: "send_notification_reply_message",- listener: (message_id: unknown, reply: unknown) => void,+ listener: (message_id: number, reply: string) => void,) => void);new_notification?: (title: string,diff --git a/web/src/ui_init.js b/web/src/ui_init.jsindex eb70bd83644..816e5fd387f 100644--- a/web/src/ui_init.js+++ b/web/src/ui_init.js@@ -35,7 +35,7 @@ import * as compose_tooltips from "./compose_tooltips.ts";import * as composebox_typeahead from "./composebox_typeahead.ts";import * as condense from "./condense.ts";import * as copy_and_paste from "./copy_and_paste.ts";-import * as desktop_integration from "./desktop_integration.js";+import * as desktop_integration from "./desktop_integration.ts";import * as desktop_notifications from "./desktop_notifications.ts";import * as drafts from "./drafts.ts";import * as drafts_overlay_ui from "./drafts_overlay_ui.js";