Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): load every contact for the status recipient picker

Yudhi Armyndharis4a9776ffe119
diff --git a/dashboard/src/services/api.test.ts b/dashboard/src/services/api.test.ts
index 93f0c46b2..9bf8f1245 100644
--- a/dashboard/src/services/api.test.ts
+++ b/dashboard/src/services/api.test.ts
@@ -89,3 +89,17 @@ test('the contact list walks past the 1000 contacts one response carries', async
'/sessions/s1/contacts?limit=1000&offset=1000',
]);
});
+
+test('the contact list is not cut off at 10,000 contacts', async () => {
+ const { contactApi } = await import('./api.ts');
+ globalThis.fetch = ((input: RequestInfo | URL) => {
+ const offset = Number(new URL(String(input), 'http://x').searchParams.get('offset'));
+ const count = offset < 11_000 ? 1000 : 5;
+ const contacts = Array.from({ length: count }, (_, i) => ({ id: `${offset + i}@c.us`, name: null }));
+ return Promise.resolve(
+ new Response(JSON.stringify(contacts), { status: 200, headers: { 'Content-Type': 'application/json' } }),
+ );
+ }) as typeof fetch;
+
+ assert.equal((await contactApi.list('s1')).length, 11_005);
+});
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index 8f2959978..0522dc573 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -972,6 +972,7 @@ export interface ProfilePictureResponse {
export const contactApi = {
// The route caps a response at 1000 contacts; walk the pages so an address book past that is complete.
+ // No item cap: the status recipient picker needs every contact, and the server's short page ends the walk.
list: async (sessionId: string) =>
(
await fetchAllPages(
@@ -980,7 +981,7 @@ export const contactApi = {
// The route answers a bare array with no total: a short page is the last one.
return { data, total: data.length < limit ? offset + data.length : Infinity };
},
- { pageSize: 1000 },
+ { pageSize: 1000, maxItems: Infinity },
)
).items,
checkNumber: (sessionId: string, number: string) =>