user_status: Fix parsing of partial user_status events.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-01-11 16:33:33 -05:00 committed by Tim Abbott
parent e0bd169c77
commit 43e53d9b9d
1 changed files with 26 additions and 26 deletions

View File

@ -10,33 +10,33 @@ export type UserStatusEmojiInfo = EmojiRenderingDetails & {
emoji_alt_code?: boolean; emoji_alt_code?: boolean;
}; };
export type UserStatusEvent = z.infer<typeof user_status_event_schema>; const user_status_schema = z.intersection(
const user_status_event_schema = z.object({
id: z.number(),
type: z.literal("user_status"),
user_id: z.number(),
away: z.boolean().optional(),
status_text: z.string(),
emoji_name: z.string(),
emoji_code: z.string(),
reaction_type: z.string(),
});
const user_status_schema = z.union([
z.object({ z.object({
status_text: z.string().optional(), status_text: z.string().optional(),
away: z.boolean().optional(),
}),
z.union([
z.object({
emoji_name: z.string(), emoji_name: z.string(),
emoji_code: z.string(), emoji_code: z.string(),
reaction_type: z.string(), reaction_type: z.string(),
away: z.boolean().optional(),
}), }),
z.object({ z.object({
emoji_name: z.undefined(), emoji_name: z.undefined(),
status_text: z.string().optional(),
away: z.boolean().optional(),
}), }),
]); ]),
);
const user_status_event_schema = z.intersection(
z.object({
id: z.number(),
type: z.literal("user_status"),
user_id: z.number(),
}),
user_status_schema,
);
export type UserStatusEvent = z.infer<typeof user_status_event_schema>;
const user_status_param_schema = z.record(z.string(), user_status_schema); const user_status_param_schema = z.record(z.string(), user_status_schema);