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
parent 787d64e327
commit dd3a8ce3b5
1 changed files with 26 additions and 26 deletions

View File

@ -10,34 +10,34 @@ export type UserStatusEmojiInfo = EmojiRenderingDetails & {
emoji_alt_code?: boolean;
};
const user_status_schema = z.intersection(
z.object({
status_text: z.string().optional(),
away: z.boolean().optional(),
}),
z.union([
z.object({
emoji_name: z.string(),
emoji_code: z.string(),
reaction_type: z.string(),
}),
z.object({
emoji_name: z.undefined(),
}),
]),
);
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_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({
status_text: z.string().optional(),
emoji_name: z.string(),
emoji_code: z.string(),
reaction_type: z.string(),
away: z.boolean().optional(),
}),
z.object({
emoji_name: z.undefined(),
status_text: z.string().optional(),
away: z.boolean().optional(),
}),
]);
const user_status_param_schema = z.record(z.string(), user_status_schema);
const user_info = new Map<number, string>();