@arcaelas/whatsapp 6.2.0 → 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 +132 -152
- package/build/cjs/lib/chat/index.js +138 -219
- 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 -1099
- 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 +132 -152
- package/build/esm/lib/chat/index.js +139 -219
- 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 -1101
- 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,82 +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
|
*/
|
|
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
|
+
};
|
|
71
81
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*/
|
|
77
|
-
async function activity_of(cid) {
|
|
78
|
-
const [raw] = await wa.engine.list(`/chat/${cid}/message`, 0, 1);
|
|
79
|
-
return (0, store_1.deserialize)(raw ?? null)?.created_at ?? 0;
|
|
80
|
-
}
|
|
81
|
-
async function last_messages(cid) {
|
|
82
|
-
const [raw] = await wa.engine.list(`/chat/${cid}/message`, 0, 1);
|
|
83
|
-
const parsed = (0, store_1.deserialize)(raw ?? null);
|
|
84
|
-
return parsed
|
|
85
|
-
? [{ key: { remoteJid: cid, id: parsed.id, fromMe: parsed.me }, messageTimestamp: Math.floor(parsed.created_at / 1000) }]
|
|
86
|
-
: [];
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Cuenta los chats fijados distintos del indicado, cortando al llegar al máximo.
|
|
90
|
-
* Counts pinned chats other than the given one, stopping once the max is reached.
|
|
91
|
-
*/
|
|
92
|
-
async function count_pinned(exclude) {
|
|
93
|
-
let total = 0;
|
|
94
|
-
for (let offset = 0; total < MAX_PINNED; offset += 200) {
|
|
95
|
-
const page = await wa.engine.list('/chat', offset, 200);
|
|
96
|
-
if (page.length === 0) {
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
for (const raw of page) {
|
|
100
|
-
const parsed = (0, store_1.deserialize)(raw);
|
|
101
|
-
if (parsed && parsed.id !== exclude && parsed.pinned != null) {
|
|
102
|
-
total++;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return total;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Participantes del grupo memoizados 15s, para no repetir `groupMetadata` en cada página.
|
|
110
|
-
* 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.
|
|
111
86
|
*/
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
if (!
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
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);
|
|
118
92
|
}
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
* Contacto desde el engine, o ficha mínima local cuando no está persistido (sin red).
|
|
123
|
-
* Contact from the engine, or a minimal local card when not persisted (no network).
|
|
124
|
-
*/
|
|
125
|
-
async function load_contact(id) {
|
|
126
|
-
const cached = (0, store_1.deserialize)(await wa.engine.get(`/contact/${id}`));
|
|
127
|
-
return new wa.Contact(cached ?? { id });
|
|
128
|
-
}
|
|
129
|
-
return class _Chat extends Chat {
|
|
93
|
+
return groups.get(jid);
|
|
94
|
+
};
|
|
95
|
+
class _Chat extends Chat {
|
|
130
96
|
/**
|
|
131
|
-
* Participantes
|
|
132
|
-
*
|
|
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.
|
|
133
99
|
*
|
|
134
100
|
* @param offset - Desplazamiento / Offset
|
|
135
101
|
* @param limit - Tamaño de página / Page size
|
|
@@ -137,219 +103,172 @@ function chat(wa) {
|
|
|
137
103
|
*/
|
|
138
104
|
async members(offset = 0, limit = 50) {
|
|
139
105
|
const ids = this.type === 'group'
|
|
140
|
-
? (await
|
|
141
|
-
: [this._raw.id,
|
|
142
|
-
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 })));
|
|
143
109
|
}
|
|
144
110
|
/**
|
|
145
|
-
* Descripción
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
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.
|
|
149
115
|
*
|
|
150
|
-
* @returns Descripción, o cadena vacía
|
|
116
|
+
* @returns Descripción, o cadena vacía / Description, or an empty string
|
|
151
117
|
*/
|
|
152
118
|
async content() {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
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 ?? '';
|
|
157
122
|
}
|
|
158
123
|
/**
|
|
159
|
-
* Mensajes del chat
|
|
160
|
-
* Chat messages
|
|
124
|
+
* Mensajes del chat, del más reciente al más antiguo.
|
|
125
|
+
* Chat messages, from the most recent to the oldest.
|
|
161
126
|
*
|
|
162
127
|
* @param offset - Desplazamiento / Offset
|
|
163
128
|
* @param limit - Tamaño de página / Page size
|
|
164
129
|
* @returns Página de mensajes / Message page
|
|
165
130
|
*/
|
|
166
131
|
async messages(offset = 0, limit = 50) {
|
|
167
|
-
return
|
|
132
|
+
return init.wa.Message.list(this._raw.id, offset, limit);
|
|
168
133
|
}
|
|
169
134
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
135
|
+
* Publica el indicador «escribiendo…».
|
|
136
|
+
* Publishes the "typing…" indicator.
|
|
172
137
|
*
|
|
173
|
-
* @param value - true
|
|
174
|
-
* @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
|
|
175
139
|
*/
|
|
176
140
|
async typing(value) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (socket) {
|
|
180
|
-
await socket.sendPresenceUpdate(value ? 'composing' : 'paused', this._raw.id);
|
|
181
|
-
ok = true;
|
|
182
|
-
}
|
|
183
|
-
return ok;
|
|
141
|
+
await init.socket.sendPresenceUpdate(value ? 'composing' : 'paused', this._raw.id);
|
|
142
|
+
return true;
|
|
184
143
|
}
|
|
185
144
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
145
|
+
* Publica el indicador «grabando audio…».
|
|
146
|
+
* Publishes the "recording audio…" indicator.
|
|
188
147
|
*
|
|
189
|
-
* @param value - true
|
|
190
|
-
* @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
|
|
191
149
|
*/
|
|
192
150
|
async recording(value) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (socket) {
|
|
196
|
-
await socket.sendPresenceUpdate(value ? 'recording' : 'paused', this._raw.id);
|
|
197
|
-
ok = true;
|
|
198
|
-
}
|
|
199
|
-
return ok;
|
|
151
|
+
await init.socket.sendPresenceUpdate(value ? 'recording' : 'paused', this._raw.id);
|
|
152
|
+
return true;
|
|
200
153
|
}
|
|
201
154
|
/**
|
|
202
|
-
* Archiva o desarchiva el chat en la cuenta
|
|
203
|
-
* 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.
|
|
204
157
|
*
|
|
205
158
|
* @param value - true archiva, false desarchiva / true archives, false unarchives
|
|
206
|
-
* @returns true si la acción se envió / true when the action was sent
|
|
207
159
|
*/
|
|
208
160
|
async archive(value) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
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;
|
|
218
168
|
}
|
|
219
169
|
/**
|
|
220
|
-
* Fija o desfija el chat
|
|
221
|
-
*
|
|
222
|
-
* Pins or unpins the chat
|
|
223
|
-
*
|
|
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.
|
|
224
174
|
*
|
|
225
175
|
* @param value - true fija, false desfija / true pins, false unpins
|
|
226
|
-
* @returns false si
|
|
176
|
+
* @returns false si ya hay 3 chats fijados / false when 3 chats are already pinned
|
|
227
177
|
*/
|
|
228
178
|
async pin(value) {
|
|
229
|
-
let
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
await socket.chatModify({ pin: value }, this._raw.id);
|
|
235
|
-
this._raw.pinned = value ? Date.now() : null;
|
|
236
|
-
await wa.engine.set(`/chat/${this._raw.id}`, (0, store_1.serialize)(this._raw), this._raw.activity ?? (await activity_of(this._raw.id)));
|
|
237
|
-
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;
|
|
238
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;
|
|
239
192
|
}
|
|
240
|
-
|
|
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;
|
|
241
197
|
}
|
|
242
198
|
/**
|
|
243
|
-
* Silencia el chat hasta la fecha indicada
|
|
244
|
-
* 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.
|
|
245
201
|
*
|
|
246
|
-
* @param until - Fecha límite (ISO, epoch ms o Date) o false / Deadline (ISO, epoch ms or Date) or false
|
|
247
|
-
* @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
|
|
248
203
|
*/
|
|
249
204
|
async mute(until) {
|
|
250
|
-
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
this._raw.mute_end_time = muted ? end : null;
|
|
257
|
-
await wa.engine.set(`/chat/${this._raw.id}`, (0, store_1.serialize)(this._raw), this._raw.activity ?? (await activity_of(this._raw.id)));
|
|
258
|
-
ok = true;
|
|
259
|
-
}
|
|
260
|
-
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;
|
|
261
211
|
}
|
|
262
212
|
/**
|
|
263
|
-
* Marca el chat completo como leído en la cuenta
|
|
264
|
-
* Marks the whole chat as read on the
|
|
265
|
-
*
|
|
266
|
-
* @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.
|
|
267
215
|
*/
|
|
268
216
|
async seen() {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
await wa.engine.set(`/chat/${this._raw.id}`, (0, store_1.serialize)(this._raw), this._raw.activity ?? (await activity_of(this._raw.id)));
|
|
275
|
-
ok = true;
|
|
276
|
-
}
|
|
277
|
-
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;
|
|
278
222
|
}
|
|
279
223
|
/**
|
|
280
|
-
* Vacía los mensajes del chat en la cuenta
|
|
281
|
-
* Clears the chat messages on the
|
|
282
|
-
*
|
|
283
|
-
* @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.
|
|
284
226
|
*/
|
|
285
227
|
async clear() {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
await socket
|
|
289
|
-
.chatModify({ clear: true, lastMessages: await last_messages(this._raw.id) }, this._raw.id)
|
|
290
|
-
.catch(() => null);
|
|
291
|
-
}
|
|
292
|
-
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`);
|
|
293
230
|
return true;
|
|
294
231
|
}
|
|
295
232
|
/**
|
|
296
|
-
* Elimina el chat y sus mensajes en la cuenta
|
|
297
|
-
*
|
|
298
|
-
* Deletes the chat and its messages on the
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* @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.
|
|
302
237
|
*/
|
|
303
238
|
async delete() {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
await socket
|
|
311
|
-
.chatModify({ delete: true, lastMessages: await last_messages(this._raw.id) }, this._raw.id)
|
|
312
|
-
.catch(() => null);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
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}`);
|
|
316
243
|
return true;
|
|
317
244
|
}
|
|
318
245
|
/**
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
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.
|
|
323
250
|
*
|
|
324
251
|
* @param cid - Teléfono, JID, LID o id de grupo / Phone, JID, LID or group id
|
|
325
|
-
* @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
|
|
326
253
|
*/
|
|
327
254
|
static async get(cid) {
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
? await (0, internal_1.internals)(wa).resolve_jid(String(cid))
|
|
331
|
-
: digits
|
|
332
|
-
? `${digits}@s.whatsapp.net`
|
|
333
|
-
: null;
|
|
334
|
-
if (jid) {
|
|
335
|
-
const cached = (0, store_1.deserialize)(await wa.engine.get(`/chat/${jid}`));
|
|
336
|
-
return new _Chat(cached ?? { id: jid });
|
|
337
|
-
}
|
|
338
|
-
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;
|
|
339
257
|
}
|
|
340
258
|
/**
|
|
341
|
-
* Pagina los chats persistidos, del más
|
|
342
|
-
* 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.
|
|
343
261
|
*
|
|
344
262
|
* @param offset - Desplazamiento / Offset
|
|
345
263
|
* @param limit - Tamaño de página / Page size
|
|
346
264
|
* @returns Página de chats / Chat page
|
|
347
265
|
*/
|
|
348
266
|
static async list(offset = 0, limit = 50) {
|
|
349
|
-
return (await
|
|
267
|
+
return (await init.engine.list('/chat', offset, limit))
|
|
350
268
|
.map((raw) => (0, store_1.deserialize)(raw))
|
|
351
|
-
.filter((
|
|
352
|
-
.map((
|
|
269
|
+
.filter((doc) => doc !== null)
|
|
270
|
+
.map((doc) => new this(doc));
|
|
353
271
|
}
|
|
354
|
-
}
|
|
272
|
+
}
|
|
273
|
+
return _Chat;
|
|
355
274
|
}
|