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.

widgetize: Fix type of `data` field.

Varun Singhfcb9c7be2644
diff --git a/web/src/submessage.ts b/web/src/submessage.ts
index 74638eaeb6b..10dcf5b1691 100644
--- a/web/src/submessage.ts
+++ b/web/src/submessage.ts
@@ -5,7 +5,9 @@ import * as channel from "./channel";
import type {MessageList} from "./message_lists";
import * as message_store from "./message_store";
import type {Message} from "./message_store";
+import type {PollWidgetOutboundData} from "./poll_widget";
import {todo_widget_extra_data_schema} from "./todo_widget";
+import type {TodoWidgetOutboundData} from "./todo_widget";
import * as widgetize from "./widgetize";
export type Submessage = {
@@ -215,8 +217,14 @@ export function handle_event(submsg: Submessage): void {
export function make_server_callback(
message_id: number,
-): (opts: {msg_type: string; data: string}) => void {
- return function (opts: {msg_type: string; data: string}) {
+): (opts: {
+ msg_type: string;
+ data: string | PollWidgetOutboundData | TodoWidgetOutboundData;
+}) => void {
+ return function (opts: {
+ msg_type: string;
+ data: string | PollWidgetOutboundData | TodoWidgetOutboundData;
+ }) {
const url = "/json/submessage";
void channel.post({
diff --git a/web/src/widgetize.ts b/web/src/widgetize.ts
index ff8dfea2117..f46283e86a8 100644
--- a/web/src/widgetize.ts
+++ b/web/src/widgetize.ts
@@ -3,7 +3,8 @@ import $ from "jquery";
import * as blueslip from "./blueslip";
import * as message_lists from "./message_lists";
import type {Message} from "./message_store";
-import type {Event, PollWidgetExtraData} from "./poll_widget";
+import type {Event, PollWidgetExtraData, PollWidgetOutboundData} from "./poll_widget";
+import type {TodoWidgetOutboundData} from "./todo_widget";
// TODO: This ZFormExtraData type should be moved to web/src/zform.js when it will be migrated
type ZFormExtraData = {
@@ -26,13 +27,16 @@ type WidgetOptions = {
events: Event[];
$row: JQuery;
message: Message;
- post_to_server: (data: {msg_type: string; data: string}) => void;
+ post_to_server: (data: {
+ msg_type: string;
+ data: string | PollWidgetOutboundData | TodoWidgetOutboundData;
+ }) => void;
};
type WidgetValue = Record<string, unknown> & {
activate: (data: {
$elem: JQuery;
- callback: (data: string) => void;
+ callback: (data: string | PollWidgetOutboundData | TodoWidgetOutboundData) => void;
message: Message;
extra_data: WidgetExtraData;
}) => (events: Event[]) => void;
@@ -66,7 +70,9 @@ export function activate(in_opts: WidgetOptions): void {
return;
}
- const callback = function (data: string): void {
+ const callback = function (
+ data: string | PollWidgetOutboundData | TodoWidgetOutboundData,
+ ): void {
post_to_server({
msg_type: "widget",
data,