From f57185cd5031996141881c4e7e7702455b5542f9 Mon Sep 17 00:00:00 2001 From: Arthur Belleville Date: Wed, 15 Apr 2026 17:06:27 +0200 Subject: [PATCH] feat(expo): add chat message and WebSocket event types --- xtablo-expo/types/chat.types.ts | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 xtablo-expo/types/chat.types.ts diff --git a/xtablo-expo/types/chat.types.ts b/xtablo-expo/types/chat.types.ts new file mode 100644 index 0000000..964a856 --- /dev/null +++ b/xtablo-expo/types/chat.types.ts @@ -0,0 +1,39 @@ +export interface ChatMessage { + id: string; + userId: string; + text: string; + createdAt: string; + clientId: string; + /** True while the message is only local (not yet echoed by server). */ + optimistic?: boolean; +} + +/** Raw shape returned by the REST API (snake_case from Postgres). */ +export interface RawApiMessage { + id: string; + user_id: string; + text: string; + created_at: string; + client_id?: string; +} + +export type ServerMessage = + | { type: "message.new"; id: string; userId: string; text: string; createdAt: string; clientId: string } + | { type: "typing"; userId: string; isTyping: boolean } + | { type: "presence.update"; userId: string; status: "online" | "offline" } + | { type: "error"; code: string; message: string }; + +export interface UnreadCount { + channel_id: string; + unread_count: number; +} + +export function normalizeMessage(raw: RawApiMessage): ChatMessage { + return { + id: raw.id, + userId: raw.user_id, + text: raw.text, + createdAt: raw.created_at, + clientId: raw.client_id ?? "", + }; +}