Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(dashboard): offer clear and delete chat on Baileys sessions
Yudhi Armyndharis4526680920aa
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6db09921c..9e7f50170 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Show a dashboard chat message's time and delivery ticks inside its last line of text, with the delivery status still named for screen readers. Thanks @rjsebening.- Show dashboard chat list times as the clock today, Yesterday, the weekday within the last week and a short date before that. Thanks @rjsebening.- Move the dashboard sidebar's collapse button from the sidebar edge into its header, beside the logo or under it when collapsed, with a panel icon mirrored for right-to-left languages. Thanks @rjsebening.+- Offer Clear chat and Delete chat in the dashboard on Baileys sessions too, now that the phone applies both (#1891).### Fixeddiff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.tsindex 66141d6c1..e2e033882 100644--- a/dashboard/src/pages/Chats.features.test.ts+++ b/dashboard/src/pages/Chats.features.test.ts@@ -2303,28 +2303,31 @@ test("a dismissed mute's late answer leaves the mute dialog that is out busy", aawait settle();});-test('a clear or delete the engine declines keeps the chat and its dialog, and says it failed', async () => {- const { screen, fireEvent, within } = rtl;- declineWrites = true;- window.sessionStorage.setItem('openwa_engine_type', 'whatsapp-web.js');- renderPage();- await screen.findByText('Alice');-- pickRowAction('Alice', 'Clear chat');- let dialog = await screen.findByRole('dialog');- fireEvent.click(within(dialog).getByRole('button', { name: 'Clear chat' }));- await screen.findByText('Could not clear the chat');- assert.ok(screen.getByRole('dialog'), 'the dialog closed on a declined clear');- assert.ok(screen.getAllByText('hello from alice').length > 0, 'the preview was cleared although nothing was');- fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));+// Baileys declines a clear or delete with no message to key it to (a chat whose history the gateway never saw).+for (const engine of ['whatsapp-web.js', 'baileys']) {+ test(`a clear or delete the engine declines keeps the chat and its dialog, and says it failed (${engine})`, async () => {+ const { screen, fireEvent, within } = rtl;+ declineWrites = true;+ window.sessionStorage.setItem('openwa_engine_type', engine);+ renderPage();+ await screen.findByText('Alice');- pickRowAction('Alice', 'Delete chat');- dialog = await screen.findByRole('dialog');- fireEvent.click(within(dialog).getByRole('button', { name: 'Delete chat' }));- await screen.findByText('Could not delete the chat');- assert.ok(screen.getByRole('dialog'), 'the dialog closed on a declined delete');- assert.ok(screen.getAllByText('Alice').length > 0, 'the row was removed although the chat was not');-});+ pickRowAction('Alice', 'Clear chat');+ let dialog = await screen.findByRole('dialog');+ fireEvent.click(within(dialog).getByRole('button', { name: 'Clear chat' }));+ await screen.findByText('Could not clear the chat');+ assert.ok(screen.getByRole('dialog'), 'the dialog closed on a declined clear');+ assert.ok(screen.getAllByText('hello from alice').length > 0, 'the preview was cleared although nothing was');+ fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));++ pickRowAction('Alice', 'Delete chat');+ dialog = await screen.findByRole('dialog');+ fireEvent.click(within(dialog).getByRole('button', { name: 'Delete chat' }));+ await screen.findByText('Could not delete the chat');+ assert.ok(screen.getByRole('dialog'), 'the dialog closed on a declined delete');+ assert.ok(screen.getAllByText('Alice').length > 0, 'the row was removed although the chat was not');+ });+}test('a mark-as-unread the engine declines leaves the row read', async () => {const { screen } = rtl;@@ -3773,21 +3776,19 @@ test('a message that reaches the open chat while Mark as unread is out is not reassert.deepEqual(readsOf(CHAT.id), [], 'the message was read automatically and undid the mark');});-test('on Baileys neither the row nor the room menu offers Clear chat or Delete chat (#1891)', async () => {+test('on Baileys the row and the room menu offer Clear chat and Delete chat, as on whatsapp-web.js (#1891)', async () => {const { screen, fireEvent, 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'));fireEvent.click(screen.getByRole('button', { name: 'Actions for Alice' }));- assert.ok(screen.getByRole('button', { name: 'Archive chat' }), 'the row menu did not open');- assert.ok(!screen.queryByRole('button', { name: 'Clear chat' }), 'the row menu offered Clear chat');- assert.ok(!screen.queryByRole('button', { name: 'Delete chat' }), 'the row menu offered Delete chat');+ assert.ok(screen.getByRole('button', { name: 'Clear chat' }), 'the row menu offered no Clear chat');+ assert.ok(screen.getByRole('button', { name: 'Delete chat' }), 'the row menu offered no Delete chat');fireEvent.keyDown(document, { key: 'Escape' });fireEvent.click(container.querySelector('.room-menu > button') as HTMLElement);const menu = container.querySelector('.room-menu-popover') as HTMLElement;- assert.ok(within(menu).getByRole('button', { name: 'Copy chat ID' }), 'the room menu did not open');- assert.ok(!within(menu).queryByRole('button', { name: 'Clear chat' }), 'the room menu offered Clear chat');- assert.ok(!within(menu).queryByRole('button', { name: 'Delete chat' }), 'the room menu offered Delete chat');+ assert.ok(within(menu).getByRole('button', { name: 'Clear chat' }), 'the room menu offered no Clear chat');+ assert.ok(within(menu).getByRole('button', { name: 'Delete chat' }), 'the room menu offered no Delete chat');});diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsxindex 60144b9dc..c4aa0892d 100644--- a/dashboard/src/pages/Chats.tsx+++ b/dashboard/src/pages/Chats.tsx@@ -270,9 +270,6 @@ export function Chats() {// both, so the query is gated off entirely (never fired) rather than left to fail per-request.// The engine comes from the sign-in validate response, which every role can read.const channelsSupported = engineType === 'whatsapp-web.js';- // On Baileys the phone can ignore a clear or delete the gateway reports as done, and the gateway then drops- // its stored copy of the messages (#1891). Until that is fixed both are offered on whatsapp-web.js only.- const canClearOrDelete = canWrite && engineType === 'whatsapp-web.js';const channelsQuery = useQuery({queryKey: ['channels', selectedSessionId],queryFn: () => sessionApi.getSubscribedChannels(selectedSessionId!),@@ -1676,8 +1673,8 @@ export function Chats() {onToggleBlock: canWrite? chat => (isBlocked(chat) ? void handleUnblock(chat) : setConfirmAction({ kind: 'block', chat })): undefined,- onClear: canClearOrDelete ? chat => setConfirmAction({ kind: 'clear', chat }) : undefined,- onDelete: canClearOrDelete ? chat => setConfirmAction({ kind: 'delete', chat }) : undefined,+ onClear: canWrite ? chat => setConfirmAction({ kind: 'clear', chat }) : undefined,+ onDelete: canWrite ? chat => setConfirmAction({ kind: 'delete', chat }) : undefined,isBlocked,};diff --git a/docs/17-dashboard-design.md b/docs/17-dashboard-design.mdindex 5546061f2..a800b6206 100644--- a/docs/17-dashboard-design.md+++ b/docs/17-dashboard-design.md@@ -113,7 +113,7 @@ mounted for any admin key.Chats / Channels / Status tabs, quick filters and an Archived view on Chats;chat list + message thread live via WebSocket; thread pages older history inon scroll-up; per-chat menu (pin, mute, archive, mark unread, block, leave- group; clear and delete on whatsapp-web.js only) [operator]; contact info+ group, clear, delete) [operator]; contact infopanel and group info dialog; new chat / new group [operator]; read-onlychannel feed on whatsapp-web.js)/number-checker → Number Checker (single and bulk check of whether numbers are on WhatsApp) [operator]