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