Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(wwebjs): walk the chat list in the page with yields

Yudhi Armyndharis1ac3c4122345
diff --git a/docs/12-troubleshooting-faq.md b/docs/12-troubleshooting-faq.md
index 9dad484d8..6875b02b1 100644
--- a/docs/12-troubleshooting-faq.md
+++ b/docs/12-troubleshooting-faq.md
@@ -785,18 +785,18 @@ quoting the message it printed.
**Symptoms:**
-- `GET /api/sessions/{id}/chats` (or another read that walks the whole store) fails on an account
- with thousands of chats, while smaller accounts on the same deployment are fine
-- The chat and contact lists answer `503` with `WhatsApp Web did not answer the chat list read in time`
+- `GET /api/sessions/{id}/chats`, `GET /api/sessions/{id}/groups` (or another read that walks the
+ whole store) fails on an account with thousands of chats, while smaller accounts on the same deployment are fine
+- The chat, group and contact lists answer `503` with `WhatsApp Web did not answer the chat list read in time`
(or `the contact list read`); another read may answer `500` with the raw error, which names a CDP
method and the setting: `Runtime.callFunctionOn timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.`
- The session stays `ready` and the next request works, so the page did not die
**Cause:** Puppeteer gives every browser command a time budget, 180 000 ms by default, and one
-`getChats()` over a very large store can run past it. The renderer is still working; only the
+read of the whole chat list over a very large store can run past it. The renderer is still working; only the
command is dropped. That is also why this is **not** treated as a dead page — a transport death
-takes the session down with it, while this is just a slow command on a live page. The chat and contact
-lists answer it with a `503` as well, but the session stays `ready`.
+takes the session down with it, while this is just a slow command on a live page. The chat, group and
+contact lists answer it with a `503` as well, but the session stays `ready`.
**Solution:** raise the budget for that deployment.
diff --git a/docs/29-engine-capability-matrix.md b/docs/29-engine-capability-matrix.md
index 17c74c53b..71aaead95 100644
--- a/docs/29-engine-capability-matrix.md
+++ b/docs/29-engine-capability-matrix.md
@@ -682,7 +682,7 @@ with zero OpenWA surface. Baileys-only; whatsapp-web.js has no community API at
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `archiveChat` | ✅ `archiveChat` |
| `getChatById` | ✅ `muteChannel`, `sendSeen`, `clearChatMessages`, `markUnread`, `deleteChat`, `sendChatState`, `getGroupInfo`, `addParticipants`, `leaveGroup`, `setGroupSubject`, `setGroupDescription`, `getGroupInviteCode`, `revokeGroupInviteCode`, `getChatLabels`, `replyToMessage`, `forwardMessage`, `reactToMessage`, `getMessageReactions`, `getChatHistory`, `deleteMessage`, `editMessage` |
-| `getChats` | ✅ `getChats`, `getGroups` |
+| `getChats` | ⚙️ read via a direct page walk, not `Client.getChats`, for `getChats` and `getGroups` |
| `markChatUnread` | ❌ **not exposed** |
| `muteChat` | ✅ `muteChat` |
| `pinChat` | ✅ `pinChat` |
@@ -1006,8 +1006,8 @@ adapter sources — re-derive the same way when anything changes:
**9** wwjs-only; `sendCatalog` (unavailable on both engines) is not exposed.
- Full engine inventory (29.5), split by the exposure legend rather than lumped: Baileys **152**
socket methods — 48 wired into interface methods, 5 internal wiring, 29 plumbing, **70 ❌ not
- exposed** (incl. the whole 23-method community cluster); wwjs **81** Client methods — 42 wired,
- 3 internal wiring, 1 class plumbing, **35 ❌ not exposed** (27 real capabilities + 8
+ exposed** (incl. the whole 23-method community cluster); wwjs **81** Client methods — 41 wired,
+ 4 internal wiring, 1 class plumbing, **35 ❌ not exposed** (27 real capabilities + 8
session/transport settings that are not WhatsApp capabilities). The backlog is the ❌ rows minus
those 8 settings; 🔩 plumbing is correctly never exposed.
- Events: Baileys **34** (17 consumed / 17 dropped), wwjs **31** (16 consumed / 15 dropped).
diff --git a/src/config/configuration.ts b/src/config/configuration.ts
index 4e7db60fa..f854eeac8 100644
--- a/src/config/configuration.ts
+++ b/src/config/configuration.ts
@@ -236,7 +236,7 @@ export default () => ({
// is missing or incompatible (Alpine, ARM, custom base images).
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || undefined,
// How long one CDP command may take. An account with thousands of chats can push a single
- // `client.getChats()` past Puppeteer's own budget; raising this is the escape hatch. Left
+ // chat-list read past Puppeteer's own budget; raising this is the escape hatch. Left
// UNDEFINED rather than defaulted to Puppeteer's number, so an unset or out-of-range value
// means "whatever puppeteer-core's `timeout ?? 180_000` says" instead of pinning today's
// figure here and silently outliving it. Out of range is not clamped either: see
diff --git a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
index 2f9cc972d..9d253f8d4 100644
--- a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
+++ b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
@@ -5793,20 +5793,21 @@ describe('WhatsAppWebJsAdapter navigation re-inject grace (#1081)', () => {
});
it('answers engine operations with a retryable 409 while the page is re-injecting', async () => {
- const getChats = jest.fn();
- const { adapter, client } = wireAdapter({ getChats });
+ const { adapter, client } = wireAdapter();
+ const evaluate = jest.fn().mockResolvedValue([]);
+ (client.pupPage as unknown as { evaluate: jest.Mock }).evaluate = evaluate;
client.pupPage.emit('framenavigated', navFrame());
await expect(adapter.getChats()).rejects.toBeInstanceOf(EngineNotReadyError);
await expect(adapter.getChats()).rejects.toThrow(/reload/i);
- expect(getChats).not.toHaveBeenCalled();
+ expect(evaluate).not.toHaveBeenCalled();
});
it('lets engine operations through again once the window has expired', async () => {
jest.useFakeTimers();
- const getChats = jest.fn().mockResolvedValue([]);
- const { adapter, client } = wireAdapter({ getChats });
+ const { adapter, client } = wireAdapter();
+ (client.pupPage as unknown as { evaluate: jest.Mock }).evaluate = jest.fn().mockResolvedValue([]);
client.pupPage.emit('framenavigated', navFrame());
jest.setSystemTime(Date.now() + NAVIGATION_REINJECT_GRACE_MS);
@@ -8223,7 +8224,9 @@ describe('WhatsAppWebJsAdapter transport death is not a not-found', () => {
// while the status still said READY, and the early-death signal never fired (#1081).
it('getChats answers 503 for a dead page and feeds the death signal', async () => {
const adapter = readyAdapter({
- getChats: jest.fn().mockRejectedValue(new Error('Protocol error (Runtime.callFunctionOn): Target closed')),
+ pupPage: {
+ evaluate: jest.fn().mockRejectedValue(new Error('Protocol error (Runtime.callFunctionOn): Target closed')),
+ },
});
await expect(adapter.getChats()).rejects.toBeInstanceOf(EngineTransportError);
@@ -8232,7 +8235,7 @@ describe('WhatsAppWebJsAdapter transport death is not a not-found', () => {
it('getChats rethrows a non-transport failure untouched', async () => {
const boom = new TypeError("Cannot read properties of undefined (reading 'getChats')");
- const adapter = readyAdapter({ getChats: jest.fn().mockRejectedValue(boom) });
+ const adapter = readyAdapter({ pupPage: { evaluate: jest.fn().mockRejectedValue(boom) } });
await expect(adapter.getChats()).rejects.toBe(boom);
});
diff --git a/src/engine/adapters/wwebjs-chat-state.spec.ts b/src/engine/adapters/wwebjs-chat-state.spec.ts
index 7d26a0f0a..02f1d11ea 100644
--- a/src/engine/adapters/wwebjs-chat-state.spec.ts
+++ b/src/engine/adapters/wwebjs-chat-state.spec.ts
@@ -40,9 +40,18 @@ const RAW = {
timestamp: 1_700_000_000,
};
+/** The page model a listed chat is rehydrated from: Chat._patch reads formattedTitle, t, archive and pin. */
+const toPageModel = ({ name, timestamp, archived, pinned, ...rest }: Record<string, unknown>) => ({
+ ...rest,
+ formattedTitle: name,
+ t: timestamp,
+ archive: archived,
+ pin: pinned,
+});
+
describe('WwebjsChats.getChats chat state', () => {
const listWith = async (over: Record<string, unknown>) => {
- const client = { getChats: jest.fn().mockResolvedValue([{ ...RAW, ...over }]) };
+ const client = { pupPage: { evaluate: jest.fn().mockResolvedValue([toPageModel({ ...RAW, ...over })]) } };
const chats = new WwebjsChats(makeHost(client), {} as unknown as WwebjsMessaging);
return (await chats.getChats())[0];
};
diff --git a/src/engine/adapters/wwebjs-chats-read.spec.ts b/src/engine/adapters/wwebjs-chats-read.spec.ts
new file mode 100644
index 000000000..79f6ecbc1
--- /dev/null
+++ b/src/engine/adapters/wwebjs-chats-read.spec.ts
@@ -0,0 +1,145 @@
+import type { Client } from 'whatsapp-web.js';
+import { WwebjsChats, readChatModels } from './wwebjs-chats';
+import { WwebjsGroups } from './wwebjs-groups';
+import { createLogger } from '../../common/services/logger.service';
+import { type WwebjsEngineHost } from './wwebjs-host';
+import { type WwebjsMessaging } from './wwebjs-messaging';
+
+/**
+ * The chat list is read with a direct page walk instead of whatsapp-web.js's `client.getChats()`,
+ * whose map over every chat runs as one synchronous stretch that starves the liveness probe on a
+ * large account. readChatModels runs inside the WhatsApp Web page, so it is driven here against a
+ * stand-in `window`; the delegates are driven with the evaluate mocked to return page models.
+ */
+describe('readChatModels (in-page chat walk)', () => {
+ const g = globalThis as unknown as { window?: unknown };
+
+ afterEach(() => {
+ delete g.window;
+ jest.restoreAllMocks();
+ });
+
+ function withChats(chats: string[], getChatModel: (c: string) => Promise<unknown>): void {
+ g.window = {
+ require: () => ({ Chat: { getModelsArray: () => chats } }),
+ WWebJS: { getChatModel },
+ };
+ }
+
+ it('returns every model in store order and yields every 256 chats', async () => {
+ const chats = Array.from({ length: 600 }, (_, i) => String(i));
+ withChats(chats, c => Promise.resolve({ id: c }));
+ const timers = jest.spyOn(globalThis, 'setTimeout');
+
+ const models = await readChatModels();
+
+ expect(models).toEqual(chats.map(id => ({ id })));
+ // i = 255 and i = 511: the queued getState() probe runs in between.
+ expect(timers).toHaveBeenCalledTimes(2);
+ });
+
+ it('walks the chat list as it stood at the start, even if the store re-sorts during a yield', async () => {
+ const chats = Array.from({ length: 300 }, (_, i) => String(i));
+ const original = [...chats];
+ const read: string[] = [];
+ withChats(chats, c => {
+ read.push(c);
+ return Promise.resolve({ id: c });
+ });
+ // A new message moves its chat to the front of WhatsApp Web's live array while the walk yields.
+ const realSetTimeout = globalThis.setTimeout;
+ jest.spyOn(globalThis, 'setTimeout').mockImplementationOnce((cb: () => void) => {
+ chats.unshift('new');
+ return realSetTimeout(cb);
+ });
+
+ const models = await readChatModels();
+
+ expect(read).toEqual(original);
+ expect(models).toEqual(original.map(id => ({ id })));
+ });
+
+ it('rejects the whole read when one chat model rejects, as whatsapp-web.js does', async () => {
+ const chats = Array.from({ length: 300 }, (_, i) => String(i));
+ withChats(chats, c => (c === '10' ? Promise.reject(new Error('unreadable')) : Promise.resolve({ id: c })));
+
+ await expect(readChatModels()).rejects.toThrow('unreadable');
+ });
+});
+
+describe('the chat and group lists read the page walk', () => {
+ const logger = createLogger('wwebjs-chats-read.spec');
+
+ function makeHost(models: unknown[]): { host: WwebjsEngineHost; evaluate: jest.Mock; getChats: jest.Mock } {
+ const evaluate = jest.fn().mockResolvedValue(models);
+ const getChats = jest.fn();
+ const client = { info: { wid: { _serialized: '[email protected]' } }, pupPage: { evaluate }, getChats };
+ const host = {
+ ensureReady: jest.fn(),
+ getClient: () => client as unknown as Client,
+ isPageTransportError: () => false,
+ reportIfPageTransportError: jest.fn(),
+ logger,
+ } as unknown as WwebjsEngineHost;
+ return { host, evaluate, getChats };
+ }
+
+ const personal = {
+ id: { _serialized: '[email protected]' },
+ formattedTitle: 'Alice',
+ isGroup: false,
+ unreadCount: 2,
+ t: 1_700_000_000,
+ archive: true,
+ pin: 1,
+ isMuted: false,
+ lastMessage: { id: { _serialized: 'm1' }, type: 'chat', body: 'hello' },
+ };
+ const group = {
+ id: { _serialized: '[email protected]' },
+ formattedTitle: 'Team',
+ isGroup: true,
+ unreadCount: 0,
+ t: 1_700_000_100,
+ groupMetadata: {
+ participants: [
+ { id: { _serialized: '[email protected]' }, isAdmin: true },
+ { id: { _serialized: '[email protected]' }, isAdmin: false },
+ ],
+ parentGroup: { _serialized: '[email protected]' },
+ },
+ };
+
+ it('getChats maps the rehydrated models and never calls client.getChats', async () => {
+ const { host, evaluate, getChats } = makeHost([personal, group]);
+
+ const summaries = await new WwebjsChats(host, {} as WwebjsMessaging).getChats();
+
+ expect(evaluate).toHaveBeenCalledWith(readChatModels);
+ expect(getChats).not.toHaveBeenCalled();
+ expect(summaries[0]).toMatchObject({
+ name: 'Alice',
+ isGroup: false,
+ unreadCount: 2,
+ timestamp: 1_700_000_000,
+ lastMessage: 'hello',
+ archived: true,
+ pinned: true,
+ muted: false,
+ });
+ expect(summaries[1]).toMatchObject({ id: '[email protected]', name: 'Team', isGroup: true });
+ });
+
+ it('getGroups keeps only groups, with participants, admin flag and linked parent', async () => {
+ const { host, evaluate, getChats } = makeHost([personal, group]);
+
+ const groups = await new WwebjsGroups(host).getGroups();
+
+ expect(evaluate).toHaveBeenCalledWith(readChatModels);
+ expect(getChats).not.toHaveBeenCalled();
+ expect(groups).toEqual([
+ { id: '[email protected]', name: 'Team', participantsCount: 2, isAdmin: true, linkedParentJID: '[email protected]' },
+ ]);
+ });
+});
diff --git a/src/engine/adapters/wwebjs-chats.ts b/src/engine/adapters/wwebjs-chats.ts
index f46f1086e..1096c808e 100644
--- a/src/engine/adapters/wwebjs-chats.ts
+++ b/src/engine/adapters/wwebjs-chats.ts
@@ -1,5 +1,6 @@
import { BadRequestException } from '@nestjs/common';
-import { MessageTypes, type Client } from 'whatsapp-web.js';
+import * as wwebjs from 'whatsapp-web.js';
+import { MessageTypes, type Chat, type Client } from 'whatsapp-web.js';
import { ChatSummary, ChatState } from '../interfaces/whatsapp-engine.interface';
import { EngineTransportError } from '../../common/errors/engine-transport.error';
import { chatKind, isChannelJid } from '../identity/wa-id';
@@ -7,6 +8,71 @@ import { WwebjsMessaging } from './wwebjs-messaging';
import { type WwebjsEngineHost } from './wwebjs-host';
import { isProtocolTimeout } from './wwebjs-lifecycle';
+/**
+ * Build the chat list IN-PAGE with the same `window.WWebJS.getChatModel` whatsapp-web.js's own
+ * `client.getChats()` maps, yielding to the page event loop every 256 chats so the liveness probe's
+ * queued `getState()` evaluate can interleave. The library starts every getChatModel in one `map`,
+ * and a personal chat reaches no await at all (serialize() plus its last message), so on a large chat
+ * list that map is one uninterrupted synchronous stretch that starves the probe and lets the watchdog
+ * tear a healthy session down mid-read: the #1501 shape readLeanContacts fixed for contacts.
+ *
+ * The models and their order are unchanged, the group metadata updates still overlap, and one chat
+ * whose model rejects still rejects the whole read, as upstream does.
+ */
+export async function readChatModels(): Promise<unknown[]> {
+ const w = window as unknown as {
+ require: (m: string) => { Chat: { getModelsArray: () => unknown[] } };
+ WWebJS: { getChatModel: (chat: unknown) => Promise<unknown> };
+ };
+ // A copy: getModelsArray() is the collection's live array, which re-sorts on a new message and
+ // grows on a new chat, so indexing it across the yields below would read one chat twice and skip
+ // another. Upstream's single synchronous map never let it change underneath.
+ const chats = w.require('WAWebCollections').Chat.getModelsArray().slice();
+ const pending: Promise<unknown>[] = [];
+ for (let i = 0; i < chats.length; i++) {
+ const model = w.WWebJS.getChatModel(chats[i]);
+ // Handled here so a rejection that lands during a yield is not reported as unhandled; the
+ // Promise.all below still rejects with it.
+ model.catch(() => undefined);
+ pending.push(model);
+ if ((i & 0xff) === 0xff) await new Promise(resolve => setTimeout(resolve));
+ }
+ return Promise.all(pending);
+}
+
+/** The chat structures are classes at runtime; index.d.ts declares them as interfaces only. */
+type ChatConstructor = new (client: Client, data: unknown) => Chat;
+const { GroupChat, PrivateChat } = wwebjs as unknown as { GroupChat: ChatConstructor; PrivateChat: ChatConstructor };
+
+/**
+ * The whole chat list through {@link readChatModels}, rehydrated the way whatsapp-web.js's
+ * ChatFactory does for these entries, so every mapped field reads exactly as `client.getChats()`
+ * gave it. Shared by the chat and group lists. A dead page answers 503 with the death signal, a read
+ * that outran the protocol budget answers 503 without one, and anything else is rethrown.
+ */
+export async function listChats(host: WwebjsEngineHost, context: string): Promise<Chat[]> {
+ const client = host.getClient();
+ const page = (client as unknown as { pupPage: { evaluate: <T>(fn: () => Promise<T>) => Promise<T> } }).pupPage;
+ let models: unknown[];
+ try {
+ models = await page.evaluate(readChatModels);
+ } catch (error) {
+ // Same split every sibling read makes (see getChatsByLabel): a dead page is a 503 and an
+ // early death signal, not an opaque 500 under a status that still says READY (#1081).
+ if (host.isPageTransportError(error)) {
+ host.reportIfPageTransportError(error, context);
+ throw new EngineTransportError('Transport died while listing chats');
+ }
+ if (isProtocolTimeout(error)) {
+ throw new EngineTransportError('WhatsApp Web did not answer the chat list read in time');
+ }
+ throw error;
+ }
+ return models.map(data =>
+ (data as { isGroup?: boolean }).isGroup ? new GroupChat(client, data) : new PrivateChat(client, data),
+ );
+}
+
/**
* Chat-list operations extracted from WhatsAppWebJsAdapter. The adapter keeps the public methods as
* thin forwarders and injects the shared host surface (./wwebjs-host) via closures, so the delegate
@@ -26,22 +92,7 @@ export class WwebjsChats {
async getChats(): Promise<ChatSummary[]> {
this.host.ensureReady();
- let chats: Awaited<ReturnType<Client['getChats']>>;
- try {
- chats = await this.client().getChats();
- } catch (error) {
- // Same split every sibling read makes (see getChatsByLabel): a dead page is a 503 and an
- // early death signal, not an opaque 500 under a status that still says READY (#1081).
- if (this.host.isPageTransportError(error)) {
- this.host.reportIfPageTransportError(error, 'getChats');
- throw new EngineTransportError('Transport died while listing chats');
- }
- // A read that outran the protocol budget got no answer: a 503, but no death.
- if (isProtocolTimeout(error)) {
- throw new EngineTransportError('WhatsApp Web did not answer the chat list read in time');
- }
- throw error;
- }
+ const chats = await listChats(this.host, 'getChats');
const summaries: ChatSummary[] = [];
let skipped = 0;
diff --git a/src/engine/adapters/wwebjs-group-transport-death.spec.ts b/src/engine/adapters/wwebjs-group-transport-death.spec.ts
index 681d4b1f9..c33f18464 100644
--- a/src/engine/adapters/wwebjs-group-transport-death.spec.ts
+++ b/src/engine/adapters/wwebjs-group-transport-death.spec.ts
@@ -22,7 +22,9 @@ describe('group reads distinguish a dead page from an ordinary failure', () => {
info: {},
// requireGroupChat runs before the guarded read, so it must resolve a real group.
getChatById: jest.fn().mockResolvedValue({ isGroup: true }),
- getChats: op === 'getGroups' ? jest.fn().mockRejectedValue(reject) : jest.fn().mockResolvedValue([]),
+ pupPage: {
+ evaluate: op === 'getGroups' ? jest.fn().mockRejectedValue(reject) : jest.fn().mockResolvedValue([]),
+ },
getGroupMembershipRequests:
op === 'getGroupMembershipRequests' ? jest.fn().mockRejectedValue(reject) : jest.fn().mockResolvedValue([]),
};
diff --git a/src/engine/adapters/wwebjs-groups.ts b/src/engine/adapters/wwebjs-groups.ts
index c32a6b260..2afde2d34 100644
--- a/src/engine/adapters/wwebjs-groups.ts
+++ b/src/engine/adapters/wwebjs-groups.ts
@@ -20,6 +20,7 @@ import { InvalidInviteCodeError } from '../../common/errors/invalid-invite-code.
import { toMessageMedia } from './wwebjs-messaging';
import { type WwebjsEngineHost, withPage, reportPageDeath } from './wwebjs-host';
import { isProtocolTimeout } from './wwebjs-lifecycle';
+import { listChats } from './wwebjs-chats';
/**
* Extracts the JID of the parent community a group is linked to, if any.
@@ -82,30 +83,28 @@ export class WwebjsGroups {
async getGroups(): Promise<Group[]> {
this.host.ensureReady();
- return withPage(this.host, 'getGroups', async () => {
- const client = this.client();
- const chats = await client.getChats();
-
- // Filter only group chats
- const groups = chats.filter(chat => chat.isGroup);
-
- // List path: read linkedParentJID synchronously from whatever metadata getChats()
- // already loaded. We deliberately do NOT fall back to getChatById per group here —
- // that would be an N+1 round-trip across every group on every list call. Groups
- // whose metadata isn't loaded report null; the single-group endpoint (getGroupInfo,
- // which loads full metadata via getChatById) is the authoritative source.
- return groups.map(g => {
- const groupChat = g as unknown as GroupChat;
- return {
- id: g.id._serialized,
- name: g.name,
- participantsCount: groupChat.participants?.length,
- isAdmin: groupChat.participants?.some(
- p => p.isAdmin && readWid(p.id) !== undefined && readWid(p.id) === readWid(client.info?.wid),
- ),
- linkedParentJID: extractLinkedParentJID(groupChat.groupMetadata),
- };
- });
+ const client = this.client();
+ const chats = await listChats(this.host, 'getGroups');
+
+ // Filter only group chats
+ const groups = chats.filter(chat => chat.isGroup);
+
+ // List path: read linkedParentJID synchronously from whatever metadata the chat list
+ // already loaded. We deliberately do NOT fall back to getChatById per group here:
+ // that would be an N+1 round-trip across every group on every list call. Groups
+ // whose metadata isn't loaded report null; the single-group endpoint (getGroupInfo,
+ // which loads full metadata via getChatById) is the authoritative source.
+ return groups.map(g => {
+ const groupChat = g as unknown as GroupChat;
+ return {
+ id: g.id._serialized,
+ name: g.name,
+ participantsCount: groupChat.participants?.length,
+ isAdmin: groupChat.participants?.some(
+ p => p.isAdmin && readWid(p.id) !== undefined && readWid(p.id) === readWid(client.info?.wid),
+ ),
+ linkedParentJID: extractLinkedParentJID(groupChat.groupMetadata),
+ };
});
}
diff --git a/src/engine/adapters/wwebjs-protocol-timeout.spec.ts b/src/engine/adapters/wwebjs-protocol-timeout.spec.ts
index 3c8cb03a3..ac9fcae9d 100644
--- a/src/engine/adapters/wwebjs-protocol-timeout.spec.ts
+++ b/src/engine/adapters/wwebjs-protocol-timeout.spec.ts
@@ -220,15 +220,18 @@ describe('a protocol timeout is a 503, never a not-found verdict', () => {
expect(reportIfPageTransportError).not.toHaveBeenCalled();
});
- // The two list reads walk the whole store in one command, so they are the ones a large account
- // pushes past the budget; neither has a not-found verdict, but a raw rethrow would answer 500.
+ // The list reads walk the whole store in one command, so they are the ones a large account
+ // pushes past the budget; none has a not-found verdict, but a raw rethrow would answer 500.
it.each([
- ['getContacts', (host: WwebjsEngineHost) => new WwebjsContacts(host).getContacts(), 'pupPage'],
- ['getChats', (host: WwebjsEngineHost) => chats(host).getChats(), 'getChats'],
- ] as const)('%s answers an expired protocolTimeout with a 503 and reports no death', async (_op, call, via) => {
+ ['getContacts', (host: WwebjsEngineHost) => new WwebjsContacts(host).getContacts()],
+ ['getChats', (host: WwebjsEngineHost) => chats(host).getChats()],
+ ['getGroups', (host: WwebjsEngineHost) => new WwebjsGroups(host).getGroups()],
+ ] as const)('%s answers an expired protocolTimeout with a 503 and reports no death', async (_op, call) => {
const timeout = jest.fn().mockRejectedValue(new Error(await puppeteerProtocolTimeoutMessage()));
- const client = via === 'pupPage' ? { pupPage: { evaluate: timeout } } : { getChats: timeout };
- const { host, reportIfPageTransportError } = makeHost(client as unknown as Record<string, jest.Mock>);
+ const { host, reportIfPageTransportError } = makeHost({ pupPage: { evaluate: timeout } } as unknown as Record<
+ string,
+ jest.Mock
+ >);
await expect(call(host)).rejects.toBeInstanceOf(EngineTransportError);
expect(timeout).toHaveBeenCalledTimes(1);