fix(web-core): stabilize unread sync and realtime dedup behavior
Some checks failed
CI / test (push) Failing after 22s
Some checks failed
CI / test (push) Failing after 22s
- make prependMessage return insertion status for dedup-safe unread increments - increment unread only on newly inserted incoming messages - trigger chat list refresh on websocket reconnect to resync unread counters
This commit is contained in:
@@ -12,7 +12,7 @@ interface ChatState {
|
||||
loadChats: (query?: string) => Promise<void>;
|
||||
setActiveChatId: (chatId: number | null) => void;
|
||||
loadMessages: (chatId: number) => Promise<void>;
|
||||
prependMessage: (chatId: number, message: Message) => void;
|
||||
prependMessage: (chatId: number, message: Message) => boolean;
|
||||
addOptimisticMessage: (params: {
|
||||
chatId: number;
|
||||
senderId: number;
|
||||
@@ -70,11 +70,12 @@ export const useChatStore = create<ChatState>((set, get) => ({
|
||||
prependMessage: (chatId, message) => {
|
||||
const old = get().messagesByChat[chatId] ?? [];
|
||||
if (old.some((m) => m.id === message.id || (message.client_message_id && m.client_message_id === message.client_message_id))) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
set((state) => ({
|
||||
messagesByChat: { ...state.messagesByChat, [chatId]: [...old, message] }
|
||||
}));
|
||||
return true;
|
||||
},
|
||||
addOptimisticMessage: ({ chatId, senderId, type, text, clientMessageId }) => {
|
||||
const old = get().messagesByChat[chatId] ?? [];
|
||||
|
||||
Reference in New Issue
Block a user