Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

widgets: Introduce WidgetOutboundData type.

Steve Howell044ecfe3e5a1
diff --git a/web/src/submessage.ts b/web/src/submessage.ts
index 636e3d1a243..e1dde8b540d 100644
--- a/web/src/submessage.ts
+++ b/web/src/submessage.ts
@@ -12,6 +12,8 @@ import * as widgetize from "./widgetize.ts";
export type Submessage = z.infer<typeof message_store.submessage_schema>;
+type WidgetOutboundData = PollWidgetOutboundData | TodoWidgetOutboundData;
+
export const zform_widget_extra_data_schema = z.object({
choices: z.array(
z.object({
@@ -202,14 +204,8 @@ export function handle_event(submsg: Submessage): void {
export function make_server_callback(
message_id: number,
-): (opts: {
- msg_type: string;
- data: string | PollWidgetOutboundData | TodoWidgetOutboundData;
-}) => void {
- return function (opts: {
- msg_type: string;
- data: string | PollWidgetOutboundData | TodoWidgetOutboundData;
- }) {
+): (opts: {msg_type: string; data: WidgetOutboundData}) => void {
+ return function (opts: {msg_type: string; data: WidgetOutboundData}) {
const url = "/json/submessage";
void channel.post({
diff --git a/web/src/widgetize.ts b/web/src/widgetize.ts
index fcade3b7895..bd244c02eb6 100644
--- a/web/src/widgetize.ts
+++ b/web/src/widgetize.ts
@@ -9,22 +9,21 @@ import type {ZFormExtraData} from "./zform.ts";
export type WidgetExtraData = PollWidgetExtraData | TodoWidgetExtraData | ZFormExtraData | null;
+type WidgetOutboundData = PollWidgetOutboundData | TodoWidgetOutboundData;
+
type WidgetOptions = {
widget_type: string;
extra_data: WidgetExtraData;
events: Event[];
$row: JQuery;
message: Message;
- post_to_server: (data: {
- msg_type: string;
- data: string | PollWidgetOutboundData | TodoWidgetOutboundData;
- }) => void;
+ post_to_server: (data: {msg_type: string; data: WidgetOutboundData}) => void;
};
export type WidgetValue = Record<string, unknown> & {
activate: (data: {
$elem: JQuery;
- callback: (data: string | PollWidgetOutboundData | TodoWidgetOutboundData) => void;
+ callback: (data: WidgetOutboundData) => void;
message: Message;
extra_data: WidgetExtraData;
}) => (events: Event[]) => void;
@@ -58,9 +57,7 @@ export function activate(in_opts: WidgetOptions): void {
return;
}
- const callback = function (
- data: string | PollWidgetOutboundData | TodoWidgetOutboundData,
- ): void {
+ const callback = function (data: WidgetOutboundData): void {
post_to_server({
msg_type: "widget",
data,