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:
@@ -42,6 +42,7 @@ export function useRealtime() {
|
||||
|
||||
ws.onopen = () => {
|
||||
reconnectAttemptsRef.current = 0;
|
||||
void useChatStore.getState().loadChats();
|
||||
};
|
||||
|
||||
ws.onmessage = (messageEvent) => {
|
||||
@@ -60,17 +61,18 @@ export function useRealtime() {
|
||||
if (!Number.isFinite(chatId) || !message?.id) {
|
||||
return;
|
||||
}
|
||||
let wasInserted = false;
|
||||
if (clientMessageId && message.sender_id === authStore.me?.id) {
|
||||
chatStore.confirmMessageByClientId(chatId, clientMessageId, message);
|
||||
} else {
|
||||
chatStore.prependMessage(chatId, message);
|
||||
wasInserted = chatStore.prependMessage(chatId, message);
|
||||
}
|
||||
if (message.sender_id !== authStore.me?.id) {
|
||||
ws.send(JSON.stringify({ event: "message_delivered", payload: { chat_id: chatId, message_id: message.id } }));
|
||||
if (chatId === chatStore.activeChatId) {
|
||||
ws.send(JSON.stringify({ event: "message_read", payload: { chat_id: chatId, message_id: message.id } }));
|
||||
chatStore.clearUnread(chatId);
|
||||
} else {
|
||||
} else if (wasInserted) {
|
||||
chatStore.incrementUnread(chatId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user