feat: add message reliability foundation
All checks were successful
CI / test (push) Successful in 23s
All checks were successful
CI / test (push) Successful in 23s
- implement idempotent message creation via client_message_id - add persistent delivered/read receipts - expose /messages/status and wire websocket receipt events - update web client to send client ids and auto-ack delivered/read
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { create } from "zustand";
|
||||
import { getChats, getMessages } from "../api/chats";
|
||||
import { getChats, getMessages, updateMessageStatus } from "../api/chats";
|
||||
import type { Chat, Message } from "../chat/types";
|
||||
|
||||
interface ChatState {
|
||||
@@ -26,12 +26,17 @@ export const useChatStore = create<ChatState>((set, get) => ({
|
||||
setActiveChatId: (chatId) => set({ activeChatId: chatId }),
|
||||
loadMessages: async (chatId) => {
|
||||
const messages = await getMessages(chatId);
|
||||
const sorted = [...messages].reverse();
|
||||
set((state) => ({
|
||||
messagesByChat: {
|
||||
...state.messagesByChat,
|
||||
[chatId]: [...messages].reverse()
|
||||
[chatId]: sorted
|
||||
}
|
||||
}));
|
||||
const lastMessage = sorted[sorted.length - 1];
|
||||
if (lastMessage) {
|
||||
void updateMessageStatus(chatId, lastMessage.id, "message_read");
|
||||
}
|
||||
},
|
||||
prependMessage: (chatId, message) => {
|
||||
const old = get().messagesByChat[chatId] ?? [];
|
||||
|
||||
Reference in New Issue
Block a user