@arcaelas/whatsapp 6.1.3 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +19 -15
  2. package/build/cjs/index.d.ts +9 -5
  3. package/build/cjs/index.js +8 -7
  4. package/build/cjs/lib/bot/decorator.d.ts +2 -9
  5. package/build/cjs/lib/bot/decorator.js +0 -1
  6. package/build/cjs/lib/bot/decorators.d.ts +48 -4
  7. package/build/cjs/lib/bot/decorators.js +2 -2
  8. package/build/cjs/lib/chat/index.d.ts +144 -152
  9. package/build/cjs/lib/chat/index.js +138 -209
  10. package/build/cjs/lib/contact/index.d.ts +114 -80
  11. package/build/cjs/lib/contact/index.js +187 -94
  12. package/build/cjs/lib/message/index.d.ts +400 -321
  13. package/build/cjs/lib/message/index.js +425 -913
  14. package/build/cjs/lib/status/index.d.ts +22 -33
  15. package/build/cjs/lib/status/index.js +52 -93
  16. package/build/cjs/lib/store/index.d.ts +16 -0
  17. package/build/cjs/lib/store/index.js +29 -3
  18. package/build/cjs/lib/whatsapp/index.d.ts +44 -212
  19. package/build/cjs/lib/whatsapp/index.js +473 -1067
  20. package/build/esm/index.d.ts +9 -5
  21. package/build/esm/index.js +6 -4
  22. package/build/esm/lib/bot/decorator.d.ts +2 -9
  23. package/build/esm/lib/bot/decorator.js +1 -1
  24. package/build/esm/lib/bot/decorators.d.ts +48 -4
  25. package/build/esm/lib/bot/decorators.js +2 -2
  26. package/build/esm/lib/chat/index.d.ts +144 -152
  27. package/build/esm/lib/chat/index.js +139 -209
  28. package/build/esm/lib/contact/index.d.ts +114 -80
  29. package/build/esm/lib/contact/index.js +186 -94
  30. package/build/esm/lib/message/index.d.ts +400 -321
  31. package/build/esm/lib/message/index.js +422 -913
  32. package/build/esm/lib/status/index.d.ts +22 -33
  33. package/build/esm/lib/status/index.js +49 -93
  34. package/build/esm/lib/store/index.d.ts +16 -0
  35. package/build/esm/lib/store/index.js +25 -0
  36. package/build/esm/lib/whatsapp/index.d.ts +44 -212
  37. package/build/esm/lib/whatsapp/index.js +476 -1069
  38. package/package.json +1 -1
  39. package/build/cjs/lib/internal.d.ts +0 -40
  40. package/build/cjs/lib/internal.js +0 -38
  41. package/build/esm/lib/internal.d.ts +0 -40
  42. package/build/esm/lib/internal.js +0 -34
@@ -3,19 +3,17 @@
3
3
  * @description Entidad Chat — conversaciones individuales y grupales.
4
4
  * Chat entity — individual and group conversations.
5
5
  */
6
- import { internals } from '../../lib/internal.js';
7
- import { Message } from '../../lib/message/index.js';
8
- import { deserialize, serialize } from '../../lib/store/index.js';
6
+ import { deserialize, jid_of, serialize } from '../../lib/store/index.js';
9
7
  /**
10
- * Clase base del chat: recibe el raw y deriva todo con getters.
11
- * Base Chat class: receives the raw and derives everything via getters.
8
+ * Chat: recibe el raw y deriva todo con getters.
9
+ * Chat: receives the raw and derives everything via getters.
12
10
  */
13
- export class Chat {
11
+ export default class Chat {
14
12
  /**
15
- * @internal Documento crudo del chat. `id` es el identificador del engine (JID, LID o
16
- * `@g.us`); `pinned` y `mute_end_time` son epoch ms.
17
- * Raw chat document. `id` is the engine identifier (JID, LID or `@g.us`); `pinned` and
18
- * `mute_end_time` are epoch ms.
13
+ * @internal Documento crudo. `id` es el identificador del engine (JID, LID o `@g.us`);
14
+ * `pinned`, `mute_end_time` y `activity` son epoch ms.
15
+ * Raw document. `id` is the engine identifier (JID, LID or `@g.us`); `pinned`,
16
+ * `mute_end_time` and `activity` are epoch ms.
19
17
  */
20
18
  constructor(_raw) {
21
19
  this._raw = _raw;
@@ -50,71 +48,50 @@ export class Chat {
50
48
  return end != null && end > Date.now() ? new Date(end).toISOString() : null;
51
49
  }
52
50
  }
53
- /** Máximo de chats fijados que acepta WhatsApp; el cuarto se descarta en silencio. / Max pinned chats WhatsApp accepts; the fourth is silently dropped. */
54
- const MAX_PINNED = 3;
55
51
  /**
56
- * Factoría de Chat ligada al contexto WhatsApp.
57
- * Context-bound Chat factory.
52
+ * Chat ligado a la sesión viva: el socket y el engine llegan resueltos, así que sus métodos
53
+ * no vuelven a comprobarlos.
54
+ * Chat bound to the live session: socket and engine arrive resolved, so its methods do not
55
+ * check them again.
58
56
  *
59
- * @param wa - Instancia principal / Main WhatsApp instance
57
+ * @param init - Sesión activa: cliente, motor y socket / Active session: client, engine and socket
58
+ * @returns Clase `Chat` con acceso a la sesión / `Chat` class with session access
60
59
  */
61
- export function chat(wa) {
60
+ export function chat(init) {
61
+ // WhatsApp acepta 3 chats fijados y descarta el cuarto sin avisar.
62
+ // WhatsApp accepts 3 pinned chats and silently drops the fourth.
63
+ const MAX_PINNED = 3;
62
64
  /**
63
- * Último mensaje del chat en el formato que exige `chatModify`.
64
- * The chat's last message in the shape `chatModify` requires.
65
+ * Último mensaje del chat, en las dos formas que hacen falta: la marca de actividad que
66
+ * ordena la lista y el `lastMessages` que exige `chatModify`.
67
+ * The chat's last message, in the two shapes needed: the activity stamp that orders the
68
+ * list and the `lastMessages` shape `chatModify` requires.
65
69
  */
66
- async function last_messages(cid) {
67
- const [raw] = await wa.engine.list(`/chat/${cid}/message`, 0, 1);
68
- const parsed = deserialize(raw ?? null);
69
- return parsed
70
- ? [{ key: { remoteJid: cid, id: parsed.id, fromMe: parsed.me }, messageTimestamp: Math.floor(parsed.created_at / 1000) }]
71
- : [];
72
- }
73
- /**
74
- * Cuenta los chats fijados distintos del indicado, cortando al llegar al máximo.
75
- * Counts pinned chats other than the given one, stopping once the max is reached.
76
- */
77
- async function count_pinned(exclude) {
78
- let total = 0;
79
- for (let offset = 0; total < MAX_PINNED; offset += 200) {
80
- const page = await wa.engine.list('/chat', offset, 200);
81
- if (page.length === 0) {
82
- break;
83
- }
84
- for (const raw of page) {
85
- const parsed = deserialize(raw);
86
- if (parsed && parsed.id !== exclude && parsed.pinned != null) {
87
- total++;
88
- }
89
- }
90
- }
91
- return total;
92
- }
70
+ const tail = async (cid) => {
71
+ const doc = deserialize((await init.engine.list(`/chat/${cid}/message`, 0, 1))[0] ?? null);
72
+ return {
73
+ at: doc?.created_at ?? 0,
74
+ messages: doc ? [{ key: { remoteJid: cid, id: doc.id, fromMe: doc.me }, messageTimestamp: Math.floor(doc.created_at / 1_000) }] : [],
75
+ };
76
+ };
93
77
  /**
94
- * Participantes del grupo memoizados 15s, para no repetir `groupMetadata` en cada página.
95
- * Group participants memoized for 15s, avoiding a `groupMetadata` round-trip per page.
78
+ * Metadatos del grupo memoizados 15s: `members` y `content` los piden por cada chat de
79
+ * una página y sin caché sería un round-trip por fila.
80
+ * Group metadata memoized for 15s: `members` and `content` ask for them on every chat of
81
+ * a page, and without a cache that is one round-trip per row.
96
82
  */
97
- const groups_cache = new Map();
98
- function group_meta(jid) {
99
- if (!groups_cache.has(jid)) {
100
- const socket = internals(wa).socket;
101
- groups_cache.set(jid, socket ? socket.groupMetadata(jid).catch(() => ({ participants: [] })) : Promise.resolve({ participants: [] }));
102
- setTimeout(() => groups_cache.delete(jid), 15_000);
83
+ const groups = new Map();
84
+ const meta = (jid) => {
85
+ if (!groups.has(jid)) {
86
+ groups.set(jid, init.socket.groupMetadata(jid).catch(() => ({ participants: [] })));
87
+ setTimeout(() => groups.delete(jid), 15_000);
103
88
  }
104
- return groups_cache.get(jid);
105
- }
106
- /**
107
- * Contacto desde el engine, o ficha mínima local cuando no está persistido (sin red).
108
- * Contact from the engine, or a minimal local card when not persisted (no network).
109
- */
110
- async function load_contact(id) {
111
- const cached = deserialize(await wa.engine.get(`/contact/${id}`));
112
- return new wa.Contact(cached ?? { id });
113
- }
114
- return class _Chat extends Chat {
89
+ return groups.get(jid);
90
+ };
91
+ class _Chat extends Chat {
115
92
  /**
116
- * Participantes del chat: los integrantes en grupos, el contacto y yo en 1:1.
117
- * Chat participants: members for groups, the contact and myself for 1:1.
93
+ * Participantes: los integrantes en grupos, el contacto y yo en 1:1.
94
+ * Participants: members for groups, the contact and myself for 1:1.
118
95
  *
119
96
  * @param offset - Desplazamiento / Offset
120
97
  * @param limit - Tamaño de página / Page size
@@ -122,219 +99,172 @@ export function chat(wa) {
122
99
  */
123
100
  async members(offset = 0, limit = 50) {
124
101
  const ids = this.type === 'group'
125
- ? (await group_meta(this._raw.id)).participants.map((participant) => participant.id)
126
- : [this._raw.id, internals(wa).socket?.user?.id].filter((id) => Boolean(id));
127
- return Promise.all(ids.slice(offset, offset + limit).map(load_contact));
102
+ ? (await meta(this._raw.id)).participants.map((participant) => participant.id)
103
+ : [this._raw.id, init.socket.user?.id].filter((id) => Boolean(id));
104
+ return Promise.all(ids.slice(offset, offset + limit).map(async (id) => new init.wa.Contact(deserialize(await init.engine.get(`/contact/${id}`)) ?? { id })));
128
105
  }
129
106
  /**
130
- * Descripción del chat: el asunto del grupo o, en un 1:1, la bio del contacto.
131
- * Es asíncrono porque ninguno de los dos vive en el documento del chat.
132
- * Chat description: the group's subject or, on a 1:1, the contact's bio. It is async
133
- * because neither of them lives in the chat document.
107
+ * Descripción: el asunto del grupo o, en un 1:1, la bio del contacto. Es asíncrono
108
+ * porque ninguna de las dos vive en el documento del chat.
109
+ * Description: the group's subject or, on a 1:1, the contact's bio. It is async because
110
+ * neither of them lives in the chat document.
134
111
  *
135
- * @returns Descripción, o cadena vacía si no hay / Description, or an empty string when absent
112
+ * @returns Descripción, o cadena vacía / Description, or an empty string
136
113
  */
137
114
  async content() {
138
- if (this.type === 'group') {
139
- return (await group_meta(this._raw.id)).desc ?? '';
140
- }
141
- return deserialize(await wa.engine.get(`/contact/${this._raw.id}`))?.status ?? '';
115
+ return this.type === 'group'
116
+ ? (await meta(this._raw.id)).desc ?? ''
117
+ : deserialize(await init.engine.get(`/contact/${this._raw.id}`))?.status ?? '';
142
118
  }
143
119
  /**
144
- * Mensajes del chat paginados desde el más reciente.
145
- * Chat messages paginated from the most recent one.
120
+ * Mensajes del chat, del más reciente al más antiguo.
121
+ * Chat messages, from the most recent to the oldest.
146
122
  *
147
123
  * @param offset - Desplazamiento / Offset
148
124
  * @param limit - Tamaño de página / Page size
149
125
  * @returns Página de mensajes / Message page
150
126
  */
151
127
  async messages(offset = 0, limit = 50) {
152
- return Message.list(wa, this._raw.id, offset, limit);
128
+ return init.wa.Message.list(this._raw.id, offset, limit);
153
129
  }
154
130
  /**
155
- * Activa o desactiva el indicador «escribiendo…».
156
- * Toggles the "typing…" indicator.
131
+ * Publica el indicador «escribiendo…».
132
+ * Publishes the "typing…" indicator.
157
133
  *
158
- * @param value - true activa, false vuelve a pausa / true enables, false returns to paused
159
- * @returns true si el socket estaba disponible / true when the socket was available
134
+ * @param value - true escribe, false vuelve a pausa / true types, false returns to paused
160
135
  */
161
136
  async typing(value) {
162
- let ok = false;
163
- const socket = internals(wa).socket;
164
- if (socket) {
165
- await socket.sendPresenceUpdate(value ? 'composing' : 'paused', this._raw.id);
166
- ok = true;
167
- }
168
- return ok;
137
+ await init.socket.sendPresenceUpdate(value ? 'composing' : 'paused', this._raw.id);
138
+ return true;
169
139
  }
170
140
  /**
171
- * Activa o desactiva el indicador «grabando audio…».
172
- * Toggles the "recording audio…" indicator.
141
+ * Publica el indicador «grabando audio…».
142
+ * Publishes the "recording audio…" indicator.
173
143
  *
174
- * @param value - true activa, false vuelve a pausa / true enables, false returns to paused
175
- * @returns true si el socket estaba disponible / true when the socket was available
144
+ * @param value - true graba, false vuelve a pausa / true records, false returns to paused
176
145
  */
177
146
  async recording(value) {
178
- let ok = false;
179
- const socket = internals(wa).socket;
180
- if (socket) {
181
- await socket.sendPresenceUpdate(value ? 'recording' : 'paused', this._raw.id);
182
- ok = true;
183
- }
184
- return ok;
147
+ await init.socket.sendPresenceUpdate(value ? 'recording' : 'paused', this._raw.id);
148
+ return true;
185
149
  }
186
150
  /**
187
- * Archiva o desarchiva el chat en la cuenta de WhatsApp.
188
- * Archives or unarchives the chat on the WhatsApp account.
151
+ * Archiva o desarchiva el chat en la cuenta.
152
+ * Archives or unarchives the chat on the account.
189
153
  *
190
154
  * @param value - true archiva, false desarchiva / true archives, false unarchives
191
- * @returns true si la acción se envió / true when the action was sent
192
155
  */
193
156
  async archive(value) {
194
- let ok = false;
195
- const socket = internals(wa).socket;
196
- if (socket) {
197
- await socket.chatModify({ archive: value, lastMessages: await last_messages(this._raw.id) }, this._raw.id);
198
- this._raw.archived = value;
199
- await wa.engine.set(`/chat/${this._raw.id}`, serialize(this._raw));
200
- ok = true;
201
- }
202
- return ok;
157
+ const last = await tail(this._raw.id);
158
+ await init.socket.chatModify({ archive: value, lastMessages: last.messages }, this._raw.id);
159
+ this._raw.archived = value;
160
+ // Archivar no es actividad: el chat conserva su posición en la lista.
161
+ // Archiving is not activity: the chat keeps its position in the list.
162
+ await init.engine.set(`/chat/${this._raw.id}`, serialize(this._raw), this._raw.activity ?? last.at);
163
+ return true;
203
164
  }
204
165
  /**
205
- * Fija o desfija el chat en la cuenta de WhatsApp. WhatsApp acepta hasta 3 chats
206
- * fijados y descarta el cuarto sin avisar, así que el límite se verifica antes.
207
- * Pins or unpins the chat on the WhatsApp account. WhatsApp accepts up to 3 pinned
208
- * chats and silently drops the fourth, so the limit is checked beforehand.
166
+ * Fija o desfija el chat. Al fijar comprueba el límite, porque WhatsApp descarta el
167
+ * cuarto chat fijado sin avisar.
168
+ * Pins or unpins the chat. When pinning it checks the limit, since WhatsApp silently
169
+ * drops the fourth pinned chat.
209
170
  *
210
171
  * @param value - true fija, false desfija / true pins, false unpins
211
- * @returns false si el socket está caído o ya hay 3 chats fijados / false when the socket is down or 3 chats are already pinned
172
+ * @returns false si ya hay 3 chats fijados / false when 3 chats are already pinned
212
173
  */
213
174
  async pin(value) {
214
- let ok = false;
215
- const socket = internals(wa).socket;
216
- if (socket) {
217
- const allowed = value ? (await count_pinned(this._raw.id)) < MAX_PINNED : true;
218
- if (allowed) {
219
- await socket.chatModify({ pin: value }, this._raw.id);
220
- this._raw.pinned = value ? Date.now() : null;
221
- await wa.engine.set(`/chat/${this._raw.id}`, serialize(this._raw));
222
- ok = true;
175
+ let pinned = 0;
176
+ for (let offset = 0; value && pinned < MAX_PINNED; offset += 200) {
177
+ const page = await init.engine.list('/chat', offset, 200);
178
+ if (page.length === 0) {
179
+ break;
223
180
  }
181
+ pinned += page.filter((raw) => {
182
+ const doc = deserialize(raw);
183
+ return doc?.pinned != null && doc.id !== this._raw.id;
184
+ }).length;
185
+ }
186
+ if (pinned >= MAX_PINNED) {
187
+ return false;
224
188
  }
225
- return ok;
189
+ await init.socket.chatModify({ pin: value }, this._raw.id);
190
+ this._raw.pinned = value ? Date.now() : null;
191
+ await init.engine.set(`/chat/${this._raw.id}`, serialize(this._raw), this._raw.activity ?? (await tail(this._raw.id)).at);
192
+ return true;
226
193
  }
227
194
  /**
228
- * Silencia el chat hasta la fecha indicada. `false` o una fecha pasada lo des-silencian.
229
- * Mutes the chat until the given date. `false` or a past date unmutes it.
195
+ * Silencia el chat hasta la fecha indicada; `false` o una fecha pasada lo reactivan.
196
+ * Mutes the chat until the given date; `false` or a past date unmutes it.
230
197
  *
231
- * @param until - Fecha límite (ISO, epoch ms o Date) o false / Deadline (ISO, epoch ms or Date) or false
232
- * @returns true si la acción se envió / true when the action was sent
198
+ * @param until - Fecha límite (ISO, epoch ms o Date), o false / Deadline (ISO, epoch ms or Date), or false
233
199
  */
234
200
  async mute(until) {
235
- let ok = false;
236
- const socket = internals(wa).socket;
237
- if (socket) {
238
- const end = until === false ? 0 : new Date(until).getTime();
239
- const muted = end > Date.now();
240
- await socket.chatModify({ mute: muted ? end : null }, this._raw.id);
241
- this._raw.mute_end_time = muted ? end : null;
242
- await wa.engine.set(`/chat/${this._raw.id}`, serialize(this._raw));
243
- ok = true;
244
- }
245
- return ok;
201
+ const end = until === false ? 0 : new Date(until).getTime();
202
+ const muted = end > Date.now();
203
+ await init.socket.chatModify({ mute: muted ? end : null }, this._raw.id);
204
+ this._raw.mute_end_time = muted ? end : null;
205
+ await init.engine.set(`/chat/${this._raw.id}`, serialize(this._raw), this._raw.activity ?? (await tail(this._raw.id)).at);
206
+ return true;
246
207
  }
247
208
  /**
248
- * Marca el chat completo como leído en la cuenta de WhatsApp.
249
- * Marks the whole chat as read on the WhatsApp account.
250
- *
251
- * @returns true si la acción se envió / true when the action was sent
209
+ * Marca el chat completo como leído en la cuenta.
210
+ * Marks the whole chat as read on the account.
252
211
  */
253
212
  async seen() {
254
- let ok = false;
255
- const socket = internals(wa).socket;
256
- if (socket) {
257
- await socket.chatModify({ markRead: true, lastMessages: await last_messages(this._raw.id) }, this._raw.id);
258
- this._raw.unread_count = 0;
259
- await wa.engine.set(`/chat/${this._raw.id}`, serialize(this._raw));
260
- ok = true;
261
- }
262
- return ok;
213
+ const last = await tail(this._raw.id);
214
+ await init.socket.chatModify({ markRead: true, lastMessages: last.messages }, this._raw.id);
215
+ this._raw.unread_count = 0;
216
+ await init.engine.set(`/chat/${this._raw.id}`, serialize(this._raw), this._raw.activity ?? last.at);
217
+ return true;
263
218
  }
264
219
  /**
265
- * Vacía los mensajes del chat en la cuenta de WhatsApp y en el engine, conservando el chat.
266
- * Clears the chat messages on the WhatsApp account and in the engine, keeping the chat.
267
- *
268
- * @returns true siempre; la limpieza local es idempotente / always true; local cleanup is idempotent
220
+ * Vacía los mensajes del chat en la cuenta y en el engine, conservando el chat.
221
+ * Clears the chat messages on the account and in the engine, keeping the chat.
269
222
  */
270
223
  async clear() {
271
- const socket = internals(wa).socket;
272
- if (socket) {
273
- await socket
274
- .chatModify({ clear: true, lastMessages: await last_messages(this._raw.id) }, this._raw.id)
275
- .catch(() => null);
276
- }
277
- await wa.engine.unset(`/chat/${this._raw.id}/message`);
224
+ await init.socket.chatModify({ clear: true, lastMessages: (await tail(this._raw.id)).messages }, this._raw.id).catch(() => null);
225
+ await init.engine.unset(`/chat/${this._raw.id}/message`);
278
226
  return true;
279
227
  }
280
228
  /**
281
- * Elimina el chat y sus mensajes en la cuenta de WhatsApp y en el engine; en grupos
282
- * abandona el grupo.
283
- * Deletes the chat and its messages on the WhatsApp account and in the engine; for
284
- * groups it leaves the group.
285
- *
286
- * @returns true siempre; la limpieza local es idempotente / always true; local cleanup is idempotent
229
+ * Elimina el chat y sus mensajes en la cuenta y en el engine; en grupos, además sale
230
+ * del grupo.
231
+ * Deletes the chat and its messages on the account and in the engine; for groups it
232
+ * also leaves the group.
287
233
  */
288
234
  async delete() {
289
- const socket = internals(wa).socket;
290
- if (socket) {
291
- if (this.type === 'group') {
292
- await socket.groupLeave(this._raw.id).catch(() => null);
293
- }
294
- else {
295
- await socket
296
- .chatModify({ delete: true, lastMessages: await last_messages(this._raw.id) }, this._raw.id)
297
- .catch(() => null);
298
- }
299
- }
300
- await wa.engine.unset(`/chat/${this._raw.id}`);
235
+ await (this.type === 'group'
236
+ ? init.socket.groupLeave(this._raw.id)
237
+ : init.socket.chatModify({ delete: true, lastMessages: (await tail(this._raw.id)).messages }, this._raw.id)).catch(() => null);
238
+ await init.engine.unset(`/chat/${this._raw.id}`);
301
239
  return true;
302
240
  }
303
241
  /**
304
- * Carga un chat por teléfono, JID, LID o id de grupo: el persistido en el engine o,
305
- * si todavía no existe, una instancia mínima lista para usar (no se persiste).
306
- * Loads a chat by phone, JID, LID or group id: the engine-persisted one or, when it
307
- * does not exist yet, a minimal ready-to-use instance (not persisted).
242
+ * Chat por teléfono, JID, LID o id de grupo: el persistido o, si no existe todavía,
243
+ * una instancia mínima lista para usar que no se persiste.
244
+ * Chat by phone, JID, LID or group id: the persisted one or, when it does not exist
245
+ * yet, a minimal ready-to-use instance that is not persisted.
308
246
  *
309
247
  * @param cid - Teléfono, JID, LID o id de grupo / Phone, JID, LID or group id
310
- * @returns Chat o null si el identificador es irresoluble / Chat or null when the identifier cannot be resolved
248
+ * @returns Chat, o null si el identificador es irresoluble / Chat, or null when the identifier cannot be resolved
311
249
  */
312
250
  static async get(cid) {
313
- const digits = String(cid).replace(/\D+/g, '');
314
- const jid = String(cid).includes('@')
315
- ? await internals(wa).resolve_jid(String(cid))
316
- : digits
317
- ? `${digits}@s.whatsapp.net`
318
- : null;
319
- if (jid) {
320
- const cached = deserialize(await wa.engine.get(`/chat/${jid}`));
321
- return new _Chat(cached ?? { id: jid });
322
- }
323
- return null;
251
+ const id = await jid_of(init.engine, String(cid), init.socket);
252
+ return id ? new this(deserialize(await init.engine.get(`/chat/${id}`)) ?? { id }) : null;
324
253
  }
325
254
  /**
326
- * Pagina los chats persistidos, del más reciente al más antiguo.
327
- * Paginates persisted chats, from the most recent to the oldest.
255
+ * Pagina los chats persistidos, del más activo al más antiguo.
256
+ * Paginates persisted chats, from the most active to the oldest.
328
257
  *
329
258
  * @param offset - Desplazamiento / Offset
330
259
  * @param limit - Tamaño de página / Page size
331
260
  * @returns Página de chats / Chat page
332
261
  */
333
262
  static async list(offset = 0, limit = 50) {
334
- return (await wa.engine.list('/chat', offset, limit))
263
+ return (await init.engine.list('/chat', offset, limit))
335
264
  .map((raw) => deserialize(raw))
336
- .filter((parsed) => parsed !== null)
337
- .map((parsed) => new _Chat(parsed));
265
+ .filter((doc) => doc !== null)
266
+ .map((doc) => new this(doc));
338
267
  }
339
- };
268
+ }
269
+ return _Chat;
340
270
  }