Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): build the open room's menu from the chat list
Yudhi Armyndharisabd6c8c8b52f
diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.tsindex b56b57a9c..f169e8684 100644--- a/dashboard/src/pages/Chats.features.test.ts+++ b/dashboard/src/pages/Chats.features.test.ts@@ -106,6 +106,8 @@ const DUPLICATE_CONTACT = { ...CONTACT, number: '262813461250071' };let listDuplicateContact = false;// When true, the address book answers 503, as it does while the engine is busy.let failContacts = false;+// What the chat list reports for Alice, which a test changes to stand for the phone changing her chat.+const aliceNow: Partial<Chat> = {};// The number the new-chat tests type, and the id the gateway resolves it to.const TYPED_NUMBER = '+1 555 000 9999';const RESOLVED_ID = '[email protected]';@@ -141,7 +143,7 @@ function installFetchStub(): void {if (method === 'GET' && path.startsWith(`${base}/chats?`)) {return Promise.resolve(jsonResponse([- CHAT,+ { ...CHAT, ...aliceNow },...(listGroup ? [GROUP] : []),...(listExtra ? [PUSH_ONLY_CHAT, LID_CHAT, NUMBER_NAMED_CHAT] : []),]),@@ -272,6 +274,7 @@ afterEach(async () => {listExtra = false;listDuplicateContact = false;failContacts = false;+ for (const key of Object.keys(aliceNow)) delete aliceNow[key as keyof Chat];declineWrites = false;for (const id of Object.keys(pictureFor)) delete pictureFor[id];gates.clear();@@ -1331,6 +1334,39 @@ test('a tab that was hidden but sees no message owes no read when it is visibleassert.deepEqual(readsOf(CHAT.id), []);});+test("the open room's menu offers Mark as unread for a chat that was opened with unread messages", async () => {+ const { screen, fireEvent, waitFor, within } = rtl;+ aliceNow.unreadCount = 2;+ const { container } = renderPage();+ await screen.findByLabelText('2 unread messages');+ fireEvent.click(screen.getByText('Alice'));+ await waitFor(() => assert.ok(container.querySelector('.room-header'), 'the room did not open'));+ await waitFor(() => assert.ok(!screen.queryByLabelText('2 unread messages'), 'opening the chat kept its badge'));++ fireEvent.click(container.querySelector('.room-menu-trigger') as HTMLElement);+ const menu = container.querySelector('.room-menu-popover') as HTMLElement;+ assert.ok(within(menu).getByRole('button', { name: 'Mark as unread' }), 'the room menu lacks Mark as unread');+});++test("the open room's menu follows the chat list when a reload brings a change made elsewhere", async () => {+ const { screen, fireEvent, act, waitFor, within } = rtl;+ const { container } = renderPage();+ fireEvent.click(await screen.findByText('Alice'));+ await waitFor(() => assert.ok(container.querySelector('.room-header'), 'the room did not open'));++ // The phone pins the chat, and a reconnect reloads the list.+ aliceNow.pinned = true;+ const socket = lastSocket();+ assert.ok(socket, 'the page opened no socket');+ act(() => socket.receive('disconnect', 'transport close'));+ act(() => socket.receive('connect'));+ await screen.findByRole('img', { name: 'Pinned' });++ fireEvent.click(container.querySelector('.room-menu-trigger') as HTMLElement);+ const menu = container.querySelector('.room-menu-popover') as HTMLElement;+ assert.ok(within(menu).getByRole('button', { name: 'Unpin chat' }), 'the room menu kept offering Pin chat');+});+test('on Baileys neither the row nor the room menu offers Clear chat or Delete chat (#1891)', async () => {const { screen, fireEvent, waitFor, within } = rtl;const { container } = renderPage();diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsxindex 1f620abb2..8db9f2582 100644--- a/dashboard/src/pages/Chats.tsx+++ b/dashboard/src/pages/Chats.tsx@@ -1666,8 +1666,14 @@ export function Chats() {keys, and the role would promise them. */}{roomMenuOpen && (<div className="room-menu-popover">- {/* The row's actions, then what only an open room needs. */}- <ChatActions chat={activeChat} actions={rowActions} onPicked={closeRoomMenu} />+ {/* The row's actions, then what only an open room needs. The chat comes from the list,+ which opening it, a reload and the page's own actions keep current, not from the+ snapshot taken when its row was clicked. */}+ <ChatActions+ chat={chats.find(c => c.id === activeChat.id) ?? activeChat}+ actions={rowActions}+ onPicked={closeRoomMenu}+ /><hr /><button type="button" onClick={() => void handleCopyChatId()}><Copy size={16} />