Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): word the optimistic reply quote like the reply banner
Yudhi Armyndharis67f2485d4889
diff --git a/dashboard/src/components/chats/ChatComposer.tsx b/dashboard/src/components/chats/ChatComposer.tsxindex 93c132a5e..4aa4236fc 100644--- a/dashboard/src/components/chats/ChatComposer.tsx+++ b/dashboard/src/components/chats/ChatComposer.tsx@@ -217,7 +217,7 @@ function ChatComposer({direction: 'outgoing',status: 'pending',createdAt: new Date().toISOString(),- metadata: buildOptimisticMetadata(attachment, replyingTo),+ metadata: buildOptimisticMetadata(attachment, replyingTo, typeLabel),};appendMessage(selectedSessionId, activeChat.id, tempMessage);diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.tsindex 45401726a..63e3059e9 100644--- a/dashboard/src/pages/Chats.test.ts+++ b/dashboard/src/pages/Chats.test.ts@@ -819,7 +819,16 @@ test('the reply banner and the sent snippet name a media type in words, not as aawait waitFor(() =>assert.equal(container.querySelector('.replying-to-body')?.textContent ?? null, '[Image]', 'reply banner'),);- fireEvent.click(container.querySelector('.btn-close-reply') as HTMLElement);++ // Sending the reply: the optimistic bubble's quote box names the type the same way.+ fireEvent.change(screen.getByPlaceholderText('Type a message...'), { target: { value: 'nice shot' } });+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));+ await within(thread).findByText('nice shot');+ assert.equal(+ thread.querySelector('.message-quote-box .quote-body')?.textContent ?? null,+ '[Image]',+ 'optimistic quote box',+ );// A PDF goes out as a document, and the sidebar says so rather than "[application]".await stageAttachment(container, 'contract.pdf');diff --git a/dashboard/src/utils/composerSend.test.ts b/dashboard/src/utils/composerSend.test.tsindex 994ff0ade..0fc55f86b 100644--- a/dashboard/src/utils/composerSend.test.ts+++ b/dashboard/src/utils/composerSend.test.ts@@ -19,6 +19,8 @@ import { quotedIdOf, buildMediaSendPayload, buildOptimisticMetadata } from './coconst REPLY = { id: 'local-1', waMessageId: '[email protected]_3EB0', type: 'text', body: 'the original' };const ATTACHMENT = { base64: 'AAAA', mimetype: 'image/png', filename: 'a.png' };+// Stands in for the composer's localized labeler.+const label = (type: string) => `[${type === 'image' ? 'Image' : type}]`;test('quotedIdOf prefers the WhatsApp id over the local one', () => {assert.equal(quotedIdOf(REPLY), '[email protected]_3EB0');@@ -52,7 +54,7 @@ test('a media send that is not a reply carries no quote key at all', () => {});test('the optimistic bubble shows BOTH the media and the quote', () => {- const metadata = buildOptimisticMetadata(ATTACHMENT, REPLY);+ const metadata = buildOptimisticMetadata(ATTACHMENT, REPLY, label);assert.equal(metadata?.media?.data, 'AAAA');assert.equal(metadata?.quotedMessage?.id, '[email protected]_3EB0');@@ -61,12 +63,12 @@ test('the optimistic bubble shows BOTH the media and the quote', () => {// A non-text quoted message has no useful body to preview, so the type stands in for it — the// behaviour the composer already had for text-only replies, preserved now that media can coexist.-test('a quoted non-text message previews as its type', () => {- const metadata = buildOptimisticMetadata(null, { ...REPLY, type: 'image', body: '' });+test('a quoted non-text message previews as its labelled type', () => {+ const metadata = buildOptimisticMetadata(null, { ...REPLY, type: 'image', body: '' }, label);- assert.equal(metadata?.quotedMessage?.body, '[image]');+ assert.equal(metadata?.quotedMessage?.body, '[Image]');});test('no attachment and no reply produces no metadata', () => {- assert.equal(buildOptimisticMetadata(null, null), undefined);+ assert.equal(buildOptimisticMetadata(null, null, label), undefined);});diff --git a/dashboard/src/utils/composerSend.ts b/dashboard/src/utils/composerSend.tsindex 93c298b88..bc47f0361 100644--- a/dashboard/src/utils/composerSend.ts+++ b/dashboard/src/utils/composerSend.ts@@ -40,10 +40,10 @@ export function quotedIdOf(replyingTo: QuotableMessage | null | undefined): stri/*** Body text for the quoted-message preview. A non-text message has no meaningful body to show, so- * its type stands in — matching what the composer already displayed for text-only replies.+ * its type stands in, worded by `typeLabel` so it matches the composer's own reply banner.*/-function quotedPreviewBody(replyingTo: QuotableMessage): string {- return replyingTo.type && replyingTo.type !== 'text' ? `[${replyingTo.type}]` : (replyingTo.body ?? '');+function quotedPreviewBody(replyingTo: QuotableMessage, typeLabel: (type: string) => string): string {+ return replyingTo.type && replyingTo.type !== 'text' ? typeLabel(replyingTo.type) : (replyingTo.body ?? '');}/**@@ -73,12 +73,15 @@ export function buildMediaSendPayload(export function buildOptimisticMetadata(attachment: ComposerAttachment | null | undefined,replyingTo: QuotableMessage | null | undefined,+ typeLabel: (type: string) => string,): OptimisticMetadata | undefined {if (!attachment && !replyingTo) return undefined;return {...(attachment? { media: { mimetype: attachment.mimetype, filename: attachment.filename, data: attachment.base64 } }: {}),- ...(replyingTo ? { quotedMessage: { id: quotedIdOf(replyingTo)!, body: quotedPreviewBody(replyingTo) } } : {}),+ ...(replyingTo+ ? { quotedMessage: { id: quotedIdOf(replyingTo)!, body: quotedPreviewBody(replyingTo, typeLabel) } }+ : {}),};}