client/packages/cache/src/schemas.ts
Alois ab577283f9
All checks were successful
/ build-web (push) Successful in 8m1s
/ build-desktop (linux) (push) Successful in 12m44s
/ build-mobile (push) Successful in 19m57s
/ release (push) Successful in 3m26s
(feat): add draft caching
2026-08-02 01:25:39 +02:00

33 lines
1.2 KiB
TypeScript

import { mtp } from "@tensamin/shared/data";
import { z } from "zod";
export const accountIdSchema = z.string().min(1);
export const contactSchema = z.object({
LastMessageAt: z.number(),
UserId: z.number(),
LastMessage: z
.object({ Content: z.base64(), SenderId: z.number() })
.optional(),
Messages: z.array(mtp.MessageGet.response),
});
export const contactsSchema = z.array(contactSchema);
export const userProfileSchema = mtp.GetUserData.response;
// Content remains the protocol base64 ciphertext. This package never decrypts messages.
export const cachedMessageSchema = mtp.MessageGet.response;
export const conversationWindowSchema = z.object({
UserId: z.number(),
LastMessageAt: z.number(),
Messages: z.array(cachedMessageSchema),
});
// Unlike cached messages, draft content is plaintext and must use a secure codec.
export const chatDraftSchema = z.object({
Content: z.string(),
ReplyId: z.number().optional(),
});
export type Contact = z.infer<typeof contactSchema>;
export type UserProfile = z.infer<typeof userProfileSchema>;
export type CachedMessage = z.infer<typeof cachedMessageSchema>;
export type ConversationWindow = z.infer<typeof conversationWindowSchema>;
export type ChatDraft = z.infer<typeof chatDraftSchema>;