Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing_events: Extract typing_user_schema and typing_event_schema.
Anders Kaseorgb1be32b1ee02
diff --git a/web/src/typing_events.ts b/web/src/typing_events.tsindex ca840498a8f..ae871a72863 100644--- a/web/src/typing_events.ts+++ b/web/src/typing_events.ts@@ -1,5 +1,6 @@import $ from "jquery";import assert from "minimalistic-assert";+import {z} from "zod";import render_typing_notifications from "../templates/typing_notifications.hbs";@@ -23,28 +24,33 @@ const MAX_USERS_TO_DISPLAY_NAME = 3;// Note!: There are also timing constants in typing_status.ts// that make typing indicators work.-type UserInfo = {- email: string;- user_id: number;-};--type TypingEvent = {- id: number;- op: "start" | "stop";- type: "typing";-} & (- | {- message_type: "stream";- sender: UserInfo;- stream_id: number;- topic: string;- }- | {- message_type: "direct";- recipients: UserInfo[];- sender: UserInfo;- }-);+export const typing_user_schema = z.object({+ email: z.string(),+ user_id: z.number(),+});++export const typing_event_schema = z+ .object({+ id: z.number(),+ op: z.enum(["start", "stop"]),+ type: z.literal("typing"),+ })+ .and(+ z.discriminatedUnion("message_type", [+ z.object({+ message_type: z.literal("stream"),+ sender: typing_user_schema,+ stream_id: z.number(),+ topic: z.string(),+ }),+ z.object({+ message_type: z.literal("direct"),+ recipients: z.array(typing_user_schema),+ sender: typing_user_schema,+ }),+ ]),+ );+type TypingEvent = z.output<typeof typing_event_schema>;function get_users_typing_for_narrow(): number[] {if (narrow_state.narrowed_by_topic_reply()) {