import { z } from "zod/v4"; import { chatsChatid } from "~/schemas/public/Chats"; import { MessagesSchema, messagesMessageid } from "~/schemas/public/Messages"; import { usersId } from "~/schemas/public/Users"; z.config(z.locales.it()); export const MessageDataSchema = MessagesSchema.omit({ time: true, }).extend({ time: z.string(), sender_nome: z.string(), sender_isAdmin: z.boolean(), color_str: z.string(), has_attachments: z.boolean(), reply_source: MessagesSchema.pick({ messageid: true, message: true, sender: true, }) .extend({ nome: z.string(), color_str: z.string(), }) .nullable(), }); export const TypingDataSchema = z.array( z.object({ userId: usersId, username: z.string(), }), ); export const SidebarUpdateSchema = z.object({ chatId: chatsChatid, lastMessage: z.string(), senderName: z.string(), }); export const MessageUpdateEventSchema = z.discriminatedUnion("eventType", [ z.object({ eventType: z.literal("edit"), data: z.object({ messageId: messagesMessageid, message: z.string() }), }), z.object({ eventType: z.literal("delete"), data: messagesMessageid, }), z.object({ eventType: z.literal("read_receipt"), data: z.null() }), // all unread messages in this chat are now read ]);