Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): refetch the chat list after a socket reconnect

Yudhi Armyndharis8195337cf659
diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.ts
index 4d435c250..a815a2745 100644
--- a/dashboard/src/pages/Chats.test.ts
+++ b/dashboard/src/pages/Chats.test.ts
@@ -839,6 +839,31 @@ test('a message arriving the moment the chat list commits updates the listed row
}
});
+test('a socket reconnect refetches the chat list so the sidebar shows what arrived during the gap', async () => {
+ const { screen, act } = rtl;
+ resetFetchCalls();
+ renderChats();
+ await screen.findByText('Alice');
+ const chatsPath = `/api/sessions/${SESSION.id}/chats`;
+ assert.equal(countFetchCalls('GET', chatsPath), 1);
+
+ // While the socket was down, Alice wrote again and a new chat started.
+ const DAVE: Chat = { ...CHAT_2, id: '[email protected]', name: 'Dave', timestamp: 1_700_000_900 };
+ chatsResponder = () =>
+ Promise.resolve(
+ jsonResponse([{ ...CHAT, unreadCount: 4, lastMessage: 'sent during the gap', timestamp: 1_700_000_800 }, DAVE]),
+ );
+ const socket = lastSocket();
+ assert.ok(socket, 'expected the page to have opened a socket');
+ act(() => socket.receive('disconnect', 'transport close'));
+ act(() => socket.receive('connect'));
+
+ await screen.findByText('Dave');
+ await screen.findByText('sent during the gap');
+ assert.ok(screen.queryByLabelText('4 unread messages'), 'the unread count missed during the gap is not shown');
+ assert.equal(countFetchCalls('GET', chatsPath), 2);
+});
+
test('a read-only key opening a chat sends no mark-as-read', async () => {
const { screen, fireEvent, within, waitFor } = rtl;
resetFetchCalls();
diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsx
index 337158f47..48ec38047 100644
--- a/dashboard/src/pages/Chats.tsx
+++ b/dashboard/src/pages/Chats.tsx
@@ -608,8 +608,11 @@ export function Chats() {
// Statuses are live now (status.received): a story posted during the socket gap would
// otherwise stay invisible until a focus refetch.
queryClient.invalidateQueries({ queryKey: ['contact-statuses', selectedSessionId] });
+ // The sidebar list is local state, so previews, unread counts and chats started during the gap
+ // only show after a refetch. Background mode keeps the current list on screen meanwhile.
+ void loadChats(selectedSessionId, { background: true });
}
- }, [isConnected, connectionFailed, selectedSessionId, queryClient]);
+ }, [isConnected, connectionFailed, selectedSessionId, queryClient, loadChats]);
useEffect(() => {
if (selectedSessionId && isConnected) {