Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): find chats and recipients by native digits

Yudhi Armyndharis581aff56d55e
diff --git a/dashboard/src/components/chats/StatusComposeModal.test.ts b/dashboard/src/components/chats/StatusComposeModal.test.ts
index 4e097310b..35142b5e9 100644
--- a/dashboard/src/components/chats/StatusComposeModal.test.ts
+++ b/dashboard/src/components/chats/StatusComposeModal.test.ts
@@ -201,3 +201,29 @@ test('status text and caption are bounded by Post, not truncated by UTF-16 units
assert.equal(post.disabled, true, 'a caption over 1024 characters can be posted');
assert.ok(regions.includes(screen.getByText('Limited to 1024 characters (1025 now).')));
});
+
+// The recipient search matches a number against the ASCII digits of a contact, whatever script it is typed in.
+test('a number typed in native digits finds a recipient by its number', async () => {
+ const { screen, fireEvent, waitFor } = rtl;
+ const stubbed = globalThis.fetch;
+ globalThis.fetch = (() =>
+ Promise.resolve(
+ new Response(
+ JSON.stringify([
+ { id: '[email protected]', name: 'Ben', number: '628123456789', isMyContact: true, isBlocked: false },
+ { id: '[email protected]', name: 'Anna', number: '491701234567', isMyContact: true, isBlocked: false },
+ ]),
+ { headers: { 'Content-Type': 'application/json' } },
+ ),
+ )) as typeof fetch;
+ try {
+ render('baileys');
+ await screen.findByText('Anna');
+ const search = document.getElementById('scm-6') as HTMLInputElement;
+ fireEvent.change(search, { target: { value: '٦٢٨١٢٣' } });
+ await waitFor(() => assert.equal(screen.queryByText('Anna'), null));
+ assert.ok(screen.getByText('Ben'));
+ } finally {
+ globalThis.fetch = stubbed;
+ }
+});
diff --git a/dashboard/src/components/chats/StatusComposeModal.tsx b/dashboard/src/components/chats/StatusComposeModal.tsx
index 243557d24..8844a1737 100644
--- a/dashboard/src/components/chats/StatusComposeModal.tsx
+++ b/dashboard/src/components/chats/StatusComposeModal.tsx
@@ -8,6 +8,7 @@ import { useToast } from '../../hooks/useToast';
import { Modal } from '../Modal';
import { MEDIA_UPLOAD_MAX_BYTES } from '../../utils/mediaUpload';
import { captionLength } from '../../utils/bulkMedia';
+import { matches } from '../../utils/chatFilters';
// 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.
@@ -64,10 +65,9 @@ function StatusComposeModal({ sessionId, onClose, onPosted }: Props) {
retry: false,
});
const composeContacts = composeContactsQuery.data ?? [];
- const composeRecipientSearchLower = composeRecipientSearch.toLowerCase();
const filteredComposeContacts = composeContacts.filter(c =>
// Match against every identity field — a named contact must still be findable by number/JID.
- [c.name, c.pushName, c.number, c.id].some(v => v?.toLowerCase().includes(composeRecipientSearchLower)),
+ matches(composeRecipientSearch, c.name, c.pushName, c.number, c.id),
);
const resetComposeForm = useCallback(() => {
diff --git a/dashboard/src/utils/chatFilters.test.ts b/dashboard/src/utils/chatFilters.test.ts
index 76d55d0f1..816149ee9 100644
--- a/dashboard/src/utils/chatFilters.test.ts
+++ b/dashboard/src/utils/chatFilters.test.ts
@@ -7,6 +7,7 @@ import {
filterChannels,
groupStatusesByContact,
isUnsavedContact,
+ matches,
phoneContactId,
savedContactKeySet,
} from './chatFilters.ts';
@@ -178,3 +179,43 @@ test('status search matches name, pushName or id', () => {
);
});
+
+// The search box matches a number against the ASCII digits of an id, so a number typed in the digits of another
+// script (Arabic-Indic, Persian, Devanagari, full-width) has to find the same chat.
+const native = (ascii: string, zero: number) => [...ascii].map(d => String.fromCharCode(zero + Number(d))).join('');
+
+for (const [script, zero] of [
+ ['ASCII', 0x30],
+ ['Arabic-Indic', 0x0660],
+ ['Persian', 0x06f0],
+ ['Devanagari', 0x0966],
+ ['full-width', 0xff10],
+] as const) {
+ test(`a number typed in ${script} digits finds the chat and the channel by its id`, () => {
+ const query = native('628123', zero);
+ assert.deepEqual(
+ filterChats([chat('[email protected]', 'Ben'), chat('[email protected]', 'Anna')], query).map(c => c.id),
+ );
+ assert.deepEqual(
+ filterChannels(
+ [
+ { id: '628123456789@newsletter', name: 'News' },
+ { id: '491701234567@newsletter', name: 'Other' },
+ ],
+ query,
+ ).map(c => c.id),
+ ['628123456789@newsletter'],
+ );
+ assert.ok(matches(query, 'Ben', undefined, '628123456789'));
+ assert.ok(!matches(query, 'Anna', '491701234567'));
+ });
+}
+
+test('a name typed with letters still matches as typed', () => {
+ assert.deepEqual(
+ filterChats([chat('[email protected]', 'Ben'), chat('[email protected]', 'Anna')], 'ANN').map(c => c.id),
+ );
+ assert.ok(!matches('xyz', 'Ben', '628123456789'));
+});
diff --git a/dashboard/src/utils/chatFilters.ts b/dashboard/src/utils/chatFilters.ts
index 258c92907..8b681b6ed 100644
--- a/dashboard/src/utils/chatFilters.ts
+++ b/dashboard/src/utils/chatFilters.ts
@@ -6,11 +6,17 @@
* As inline consts inside the page these were three unrelated rules reading one piece of state; as
* functions they take the query as an argument and can be tested.
*/
+import { normalizePhoneText } from './phone.ts';
/** Case-insensitive "does any of these fields contain the query". Absent fields never match. */
-const matches = (query: string, ...fields: (string | undefined)[]): boolean => {
+export const matches = (query: string, ...fields: (string | undefined)[]): boolean => {
const needle = query.toLowerCase();
- return fields.some(f => (f ?? '').toLowerCase().includes(needle));
+ // A number typed in the digits of another script matches the ASCII digits of an id.
+ const folded = normalizePhoneText(needle);
+ return fields.some(f => {
+ const field = (f ?? '').toLowerCase();
+ return field.includes(needle) || (folded !== needle && field.includes(folded));
+ });
};
interface ChatLike {