Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): stop status compose truncating emoji-heavy text
Yudhi Armyndharis71f9d166ec41
diff --git a/dashboard/src/components/chats/StatusComposeModal.test.ts b/dashboard/src/components/chats/StatusComposeModal.test.tsindex 8d1dc5cfb..903bd377a 100644--- a/dashboard/src/components/chats/StatusComposeModal.test.ts+++ b/dashboard/src/components/chats/StatusComposeModal.test.ts@@ -169,3 +169,29 @@ test('a contact list that stays throttled reads as a failure, not an empty addreassert.equal(screen.queryByText('No contacts found') === null, true);assert.equal(contactReads, 3);});++// A native maxlength counts a surrogate pair as two and cuts pasted text the gateway would accept, so+// Post alone holds an over-limit field, counting characters the way the gateway does.+test('status text and caption are bounded by Post, not truncated by UTF-16 units', async () => {+ const { screen, fireEvent, waitFor } = rtl;+ render();+ const post = screen.getByRole('button', { name: 'Post' }) as HTMLButtonElement;+ const text = document.getElementById('scm-1') as HTMLTextAreaElement;+ assert.equal(text.hasAttribute('maxlength'), false);+ fireEvent.change(text, { target: { value: '\u{1F600}'.repeat(4096) } });+ assert.equal(post.disabled, false, 'text the gateway accepts is held');+ fireEvent.change(text, { target: { value: '\u{1F600}'.repeat(4097) } });+ assert.equal(post.disabled, true, 'text over 4096 characters can be posted');++ fireEvent.click(screen.getByRole('button', { name: 'Image' }));+ fireEvent.change(screen.getByLabelText('Status image'), {+ target: { files: [new window.File(['x'], 'a.jpg', { type: 'image/jpeg' })] },+ });+ await waitFor(() => assert.equal(post.disabled, false));+ const caption = document.getElementById('scm-5') as HTMLInputElement;+ assert.equal(caption.hasAttribute('maxlength'), false);+ fireEvent.change(caption, { target: { value: '\u{1F600}'.repeat(1024) } });+ assert.equal(post.disabled, false, 'a caption the gateway accepts is held');+ fireEvent.change(caption, { target: { value: '\u{1F600}'.repeat(1025) } });+ assert.equal(post.disabled, true, 'a caption over 1024 characters can be posted');+});diff --git a/dashboard/src/components/chats/StatusComposeModal.tsx b/dashboard/src/components/chats/StatusComposeModal.tsxindex 03806b8f3..bee61133e 100644--- a/dashboard/src/components/chats/StatusComposeModal.tsx+++ b/dashboard/src/components/chats/StatusComposeModal.tsx@@ -7,6 +7,7 @@ import { useRole } from '../../hooks/useRole';import { useToast } from '../../hooks/useToast';import { Modal } from '../Modal';import { MEDIA_UPLOAD_MAX_BYTES } from './ChatComposer';+import { captionLength } from '../../utils/bulkMedia';// Mirrors @ArrayMaxSize(256) on the send-status DTOs — the picker caps selection client-side so the// user can't build a list the backend is guaranteed to reject.@@ -138,6 +139,11 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {// it's still unknown, a Baileys submit would go out with no recipients and 400.Boolean(engineType) &&(composeType === 'text' ? composeText.trim().length > 0 : Boolean(composeImageBase64 || composeImageUrl.trim())) &&+ // Bounded here rather than by a native maxLength, which counts UTF-16 units and would cut pasted+ // emoji the gateway accepts: it counts an astral character as one.+ (composeType === 'text'+ ? captionLength(composeText.trim()) <= 4096+ : captionLength(composeCaption.trim()) <= 1024) &&(!isBaileysEngine || composeRecipients.length > 0);const handleComposeSubmit = async () => {@@ -210,7 +216,6 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {id="scm-1"value={composeText}onChange={e => setComposeText(e.target.value)}- maxLength={4096}placeholder={t('chats.status.composeText')}/></div>@@ -269,7 +274,6 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {placeholder={t('chats.captionPlaceholder')}value={composeCaption}onChange={e => setComposeCaption(e.target.value)}- maxLength={1024}/></div></>