2026-04-28 20:32:19 +02:00
|
|
|
import { z } from "zod/v4";
|
|
|
|
|
import { chatsChatid } from "~/schemas/public/Chats";
|
|
|
|
|
import { MessagesSchema, messagesMessageid } from "~/schemas/public/Messages";
|
|
|
|
|
import { usersId } from "~/schemas/public/Users";
|
|
|
|
|
|
2026-04-29 13:16:37 +02:00
|
|
|
z.config(z.locales.it());
|
2026-04-28 20:32:19 +02:00
|
|
|
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
|
|
|
|
|
]);
|
2026-04-29 15:12:52 +02:00
|
|
|
|
|
|
|
|
|