@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.
- package/README.md +19 -15
- package/build/cjs/index.d.ts +9 -5
- package/build/cjs/index.js +8 -7
- package/build/cjs/lib/bot/decorator.d.ts +2 -9
- package/build/cjs/lib/bot/decorator.js +0 -1
- package/build/cjs/lib/bot/decorators.d.ts +48 -4
- package/build/cjs/lib/bot/decorators.js +2 -2
- package/build/cjs/lib/chat/index.d.ts +144 -152
- package/build/cjs/lib/chat/index.js +138 -209
- package/build/cjs/lib/contact/index.d.ts +114 -80
- package/build/cjs/lib/contact/index.js +187 -94
- package/build/cjs/lib/message/index.d.ts +400 -321
- package/build/cjs/lib/message/index.js +425 -913
- package/build/cjs/lib/status/index.d.ts +22 -33
- package/build/cjs/lib/status/index.js +52 -93
- package/build/cjs/lib/store/index.d.ts +16 -0
- package/build/cjs/lib/store/index.js +29 -3
- package/build/cjs/lib/whatsapp/index.d.ts +44 -212
- package/build/cjs/lib/whatsapp/index.js +473 -1067
- package/build/esm/index.d.ts +9 -5
- package/build/esm/index.js +6 -4
- package/build/esm/lib/bot/decorator.d.ts +2 -9
- package/build/esm/lib/bot/decorator.js +1 -1
- package/build/esm/lib/bot/decorators.d.ts +48 -4
- package/build/esm/lib/bot/decorators.js +2 -2
- package/build/esm/lib/chat/index.d.ts +144 -152
- package/build/esm/lib/chat/index.js +139 -209
- package/build/esm/lib/contact/index.d.ts +114 -80
- package/build/esm/lib/contact/index.js +186 -94
- package/build/esm/lib/message/index.d.ts +400 -321
- package/build/esm/lib/message/index.js +422 -913
- package/build/esm/lib/status/index.d.ts +22 -33
- package/build/esm/lib/status/index.js +49 -93
- package/build/esm/lib/store/index.d.ts +16 -0
- package/build/esm/lib/store/index.js +25 -0
- package/build/esm/lib/whatsapp/index.d.ts +44 -212
- package/build/esm/lib/whatsapp/index.js +476 -1069
- package/package.json +1 -1
- package/build/cjs/lib/internal.d.ts +0 -40
- package/build/cjs/lib/internal.js +0 -38
- package/build/esm/lib/internal.d.ts +0 -40
- 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
|
-
*
|
|
15
|
-
*
|
|
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
|
|
20
|
-
*
|
|
21
|
-
* Raw
|
|
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.
|
|
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
|
-
*
|
|
62
|
-
*
|
|
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
|
|
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(
|
|
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
|
|
69
|
-
*
|
|
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
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
? [{ key: { remoteJid: cid, id:
|
|
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
|
-
*
|
|
100
|
-
*
|
|
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
|
|
103
|
-
|
|
104
|
-
if (!
|
|
105
|
-
|
|
106
|
-
|
|
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
|
|
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
|
|
122
|
-
*
|
|
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
|
|
131
|
-
: [this._raw.id,
|
|
132
|
-
return Promise.all(ids.slice(offset, offset + limit).map(
|
|
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
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
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
|
|
116
|
+
* @returns Descripción, o cadena vacía / Description, or an empty string
|
|
141
117
|
*/
|
|
142
118
|
async content() {
|
|
143
|
-
|
|
144
|
-
|
|
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
|
|
150
|
-
* Chat messages
|
|
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
|
|
132
|
+
return init.wa.Message.list(this._raw.id, offset, limit);
|
|
158
133
|
}
|
|
159
134
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
135
|
+
* Publica el indicador «escribiendo…».
|
|
136
|
+
* Publishes the "typing…" indicator.
|
|
162
137
|
*
|
|
163
|
-
* @param value - true
|
|
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
|
-
|
|
168
|
-
|
|
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
|
-
*
|
|
177
|
-
*
|
|
145
|
+
* Publica el indicador «grabando audio…».
|
|
146
|
+
* Publishes the "recording audio…" indicator.
|
|
178
147
|
*
|
|
179
|
-
* @param value - true
|
|
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
|
-
|
|
184
|
-
|
|
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
|
|
193
|
-
* Archives or unarchives the chat on the
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
|
211
|
-
*
|
|
212
|
-
* Pins or unpins the chat
|
|
213
|
-
*
|
|
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
|
|
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
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
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
|
|
234
|
-
* Mutes the chat until the given date
|
|
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
|
-
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
|
254
|
-
* Marks the whole chat as read on the
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
|
271
|
-
* Clears the chat messages on the
|
|
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
|
-
|
|
277
|
-
|
|
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
|
|
287
|
-
*
|
|
288
|
-
* Deletes the chat and its messages on the
|
|
289
|
-
*
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
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
|
|
319
|
-
|
|
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
|
|
332
|
-
* Paginates persisted chats, from the most
|
|
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
|
|
267
|
+
return (await init.engine.list('/chat', offset, limit))
|
|
340
268
|
.map((raw) => (0, store_1.deserialize)(raw))
|
|
341
|
-
.filter((
|
|
342
|
-
.map((
|
|
269
|
+
.filter((doc) => doc !== null)
|
|
270
|
+
.map((doc) => new this(doc));
|
|
343
271
|
}
|
|
344
|
-
}
|
|
272
|
+
}
|
|
273
|
+
return _Chat;
|
|
345
274
|
}
|