Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): open a cross-session search hit on a shared chat id
Yudhi Armyndharisf0f08db8cd86
diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.tsindex d6a2bcd90..1bd91e350 100644--- a/dashboard/src/pages/Chats.test.ts+++ b/dashboard/src/pages/Chats.test.ts@@ -2023,6 +2023,39 @@ test("leaving a search hit's chat before its thread loads does not reopen it", aawait within(container.querySelector('.room-header') as HTMLElement).findByText('Carol');});+// Two sessions listing the same chat id, with the target session's thread still cached.+test('a search hit in another session on the chat open in this one opens it there', async () => {+ const { screen, fireEvent, within, waitFor } = rtl;+ twoSessions = true;+ chatsResponder = sessionId => Promise.resolve(jsonResponse(sessionId === SESSION.id ? [CHAT, CHAT_2] : [CHAT]));+ searchHits = [+ { ...THIRD_SESSION_HIT, sessionId: SESSION_2.id, chatId: CHAT.id, waMessageId: DB_MESSAGE.waMessageId! },+ ];+ try {+ const { container } = renderChats();+ const openAlice = async () => {+ fireEvent.click(await screen.findByText('Alice'));+ await within(container.querySelector('.room-messages') as HTMLElement).findByText('hello from alice');+ };+ await screen.findByText('Carol');+ const select = container.querySelector('select.session-selector') as HTMLSelectElement;+ fireEvent.change(select, { target: { value: SESSION_2.id } });+ await waitFor(() => assert.equal(screen.queryByText('Carol'), null));+ await openAlice();+ fireEvent.change(select, { target: { value: SESSION.id } });+ await screen.findByText('Carol');+ await openAlice();++ await clickSearchHit(container);+ await waitFor(() => assert.equal(select.value, SESSION_2.id));+ await flush();+ await waitFor(() => assert.ok(container.querySelector('.room-header'), "the hit's chat did not open"));+ await within(container.querySelector('.room-header') as HTMLElement).findByText('Alice');+ } finally {+ twoSessions = false;+ }+});+test('a second search hit in the chat already open scrolls to it at once', async () => {const { screen, fireEvent, within, waitFor } = rtl;searchHits = [{ ...THIRD_SESSION_HIT, sessionId: SESSION.id, chatId: CHAT.id, waMessageId: DB_MESSAGE.waMessageId! }];diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsxindex 45af4e1f7..7eaeb1447 100644--- a/dashboard/src/pages/Chats.tsx+++ b/dashboard/src/pages/Chats.tsx@@ -894,10 +894,11 @@ export function Chats() {// Best-effort scroll to the hit message. Runs as a layout effect (after useChatScrollPosition's// own restore on the same commit) so it overrides the bottom/saved jump with no visible flash.// Degrades silently to session+chat selection when the element isn't present — the message is- // still visible in the conversation.+ // still visible in the conversation. Until the hit's session has its list on screen, the open chat+ // still belongs to the session being left, even when it has the hit's chat id.useLayoutEffect(() => {const pending = pendingHitRef.current;- if (!pending || !activeChat || activeChat.id !== pending.chatId) return;+ if (!pending || listedSessionRef.current !== pending.sessionId || activeChat?.id !== pending.chatId) return;if (loadingMessages || messages.length === 0) return;const container = messagesContainerRef.current;if (container) {