@pney/whatsapp-web 1.34.6 → 1.34.7-2
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/.env.example +0 -1
- package/.gitattributes +4 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +1 -0
- package/.lintstagedrc.json +6 -0
- package/.prettierignore +8 -0
- package/.prettierrc.json +10 -0
- package/README.md +83 -80
- package/commitlint.config.js +29 -0
- package/eslint.config.mjs +67 -0
- package/example.js +151 -71
- package/index.d.ts +982 -734
- package/index.js +4 -4
- package/package.json +3 -3
- package/shell.js +4 -4
- package/src/Client.js +1860 -920
- package/src/authStrategies/BaseAuthStrategy.js +4 -2
- package/src/authStrategies/LocalAuth.js +25 -12
- package/src/authStrategies/NoAuth.js +3 -4
- package/src/authStrategies/RemoteAuth.js +92 -43
- package/src/factories/ChatFactory.js +1 -1
- package/src/factories/ContactFactory.js +2 -2
- package/src/structures/Base.js +5 -3
- package/src/structures/Broadcast.js +1 -2
- package/src/structures/BusinessContact.js +1 -2
- package/src/structures/Buttons.js +14 -10
- package/src/structures/Call.js +10 -6
- package/src/structures/Channel.js +171 -91
- package/src/structures/Chat.js +57 -41
- package/src/structures/ClientInfo.js +1 -1
- package/src/structures/Contact.js +37 -16
- package/src/structures/GroupChat.js +425 -228
- package/src/structures/GroupNotification.js +21 -12
- package/src/structures/Label.js +6 -6
- package/src/structures/List.js +22 -14
- package/src/structures/Location.js +5 -4
- package/src/structures/Message.js +412 -168
- package/src/structures/MessageMedia.js +31 -18
- package/src/structures/Order.js +4 -4
- package/src/structures/Payment.js +6 -3
- package/src/structures/Poll.js +2 -2
- package/src/structures/PollVote.js +9 -6
- package/src/structures/PrivateChat.js +2 -4
- package/src/structures/PrivateContact.js +2 -4
- package/src/structures/Product.js +1 -1
- package/src/structures/ProductMetadata.js +1 -2
- package/src/structures/Reaction.js +2 -4
- package/src/structures/ScheduledEvent.js +22 -10
- package/src/util/Constants.js +8 -6
- package/src/util/Injected/AuthStore/AuthStore.js +7 -3
- package/src/util/Injected/Utils.js +753 -345
- package/src/util/InterfaceController.js +72 -25
- package/src/util/Puppeteer.js +1 -1
- package/src/util/Util.js +28 -15
- package/src/webCache/LocalWebCache.js +7 -5
- package/src/webCache/RemoteWebCache.js +10 -4
- package/src/webCache/WebCache.js +8 -5
- package/src/webCache/WebCacheFactory.js +9 -9
- package/CODE_OF_CONDUCT.md +0 -133
|
@@ -37,11 +37,12 @@ class Channel extends Base {
|
|
|
37
37
|
*/
|
|
38
38
|
this.name = data.name;
|
|
39
39
|
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
41
|
* The channel description
|
|
42
42
|
* @type {string}
|
|
43
43
|
*/
|
|
44
|
-
this.description =
|
|
44
|
+
this.description =
|
|
45
|
+
data.channelMetadata?.description ?? data.description ?? '';
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
48
|
* Indicates if it is a Channel
|
|
@@ -89,7 +90,9 @@ class Channel extends Base {
|
|
|
89
90
|
* Last message in the channel
|
|
90
91
|
* @type {Message}
|
|
91
92
|
*/
|
|
92
|
-
this.lastMessage = data.lastMessage
|
|
93
|
+
this.lastMessage = data.lastMessage
|
|
94
|
+
? new Message(super.client, data.lastMessage)
|
|
95
|
+
: undefined;
|
|
93
96
|
|
|
94
97
|
return super._patch(data);
|
|
95
98
|
}
|
|
@@ -100,58 +103,82 @@ class Channel extends Base {
|
|
|
100
103
|
* @returns {Promise<Array<{contact: Contact, role: string}>>} Returns an array of objects that handle the subscribed contacts and their roles in the channel
|
|
101
104
|
*/
|
|
102
105
|
async getSubscribers(limit) {
|
|
103
|
-
return await this.client.pupPage.evaluate(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
106
|
+
return await this.client.pupPage.evaluate(
|
|
107
|
+
async (channelId, limit) => {
|
|
108
|
+
const channel = await window.WWebJS.getChat(channelId, {
|
|
109
|
+
getAsModel: false,
|
|
110
|
+
});
|
|
111
|
+
if (!channel) return [];
|
|
112
|
+
!limit &&
|
|
113
|
+
(limit = window
|
|
114
|
+
.require('WAWebNewsletterGatingUtils')
|
|
115
|
+
.getMaxSubscriberNumber());
|
|
116
|
+
const response = await window
|
|
117
|
+
.require('WAWebMexFetchNewsletterSubscribersJob')
|
|
118
|
+
.mexFetchNewsletterSubscribers(channelId, limit);
|
|
119
|
+
const contacts = window
|
|
120
|
+
.require('WAWebNewsletterSubscriberListAction')
|
|
121
|
+
.getSubscribersInContacts(response.subscribers);
|
|
122
|
+
return Promise.all(
|
|
123
|
+
contacts.map((obj) => ({
|
|
124
|
+
...obj,
|
|
125
|
+
contact: window.WWebJS.getContactModel(obj.contact),
|
|
126
|
+
})),
|
|
127
|
+
);
|
|
128
|
+
},
|
|
129
|
+
this.id._serialized,
|
|
130
|
+
limit,
|
|
131
|
+
);
|
|
114
132
|
}
|
|
115
133
|
|
|
116
134
|
/**
|
|
117
135
|
* Updates the channel subject
|
|
118
|
-
* @param {string} newSubject
|
|
136
|
+
* @param {string} newSubject
|
|
119
137
|
* @returns {Promise<boolean>} Returns true if the subject was properly updated. This can return false if the user does not have the necessary permissions.
|
|
120
138
|
*/
|
|
121
139
|
async setSubject(newSubject) {
|
|
122
|
-
const success = await this._setChannelMetadata(
|
|
140
|
+
const success = await this._setChannelMetadata(
|
|
141
|
+
{ name: newSubject },
|
|
142
|
+
{ editName: true },
|
|
143
|
+
);
|
|
123
144
|
success && (this.name = newSubject);
|
|
124
145
|
return success;
|
|
125
146
|
}
|
|
126
147
|
|
|
127
148
|
/**
|
|
128
149
|
* Updates the channel description
|
|
129
|
-
* @param {string} newDescription
|
|
150
|
+
* @param {string} newDescription
|
|
130
151
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
131
152
|
*/
|
|
132
153
|
async setDescription(newDescription) {
|
|
133
|
-
const success = await this._setChannelMetadata(
|
|
154
|
+
const success = await this._setChannelMetadata(
|
|
155
|
+
{ description: newDescription },
|
|
156
|
+
{ editDescription: true },
|
|
157
|
+
);
|
|
134
158
|
success && (this.description = newDescription);
|
|
135
159
|
return success;
|
|
136
160
|
}
|
|
137
161
|
|
|
138
162
|
/**
|
|
139
163
|
* Updates the channel profile picture
|
|
140
|
-
* @param {MessageMedia} newProfilePicture
|
|
164
|
+
* @param {MessageMedia} newProfilePicture
|
|
141
165
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
142
166
|
*/
|
|
143
167
|
async setProfilePicture(newProfilePicture) {
|
|
144
|
-
return await this._setChannelMetadata(
|
|
168
|
+
return await this._setChannelMetadata(
|
|
169
|
+
{ picture: newProfilePicture },
|
|
170
|
+
{ editPicture: true },
|
|
171
|
+
);
|
|
145
172
|
}
|
|
146
173
|
|
|
147
174
|
/**
|
|
148
175
|
* Updates available reactions to use in the channel
|
|
149
|
-
*
|
|
176
|
+
*
|
|
150
177
|
* Valid values for passing to the method are:
|
|
151
178
|
* 0 for NONE reactions to be avaliable
|
|
152
179
|
* 1 for BASIC reactions to be available: 👍, ❤️, 😂, 😮, 😢, 🙏
|
|
153
180
|
* 2 for ALL reactions to be available
|
|
154
|
-
* @param {number} reactionCode
|
|
181
|
+
* @param {number} reactionCode
|
|
155
182
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
156
183
|
*/
|
|
157
184
|
async setReactionSetting(reactionCode) {
|
|
@@ -159,11 +186,11 @@ class Channel extends Base {
|
|
|
159
186
|
const reactionMapper = {
|
|
160
187
|
0: 3,
|
|
161
188
|
1: 1,
|
|
162
|
-
2: 0
|
|
189
|
+
2: 0,
|
|
163
190
|
};
|
|
164
191
|
const success = await this._setChannelMetadata(
|
|
165
192
|
{ reactionCodesSetting: reactionMapper[reactionCode] },
|
|
166
|
-
{ editReactionCodesSetting: true }
|
|
193
|
+
{ editReactionCodesSetting: true },
|
|
167
194
|
);
|
|
168
195
|
success && (this.channelMetadata.reactionCodesSetting = reactionCode);
|
|
169
196
|
return success;
|
|
@@ -181,7 +208,7 @@ class Channel extends Base {
|
|
|
181
208
|
}
|
|
182
209
|
return success;
|
|
183
210
|
}
|
|
184
|
-
|
|
211
|
+
|
|
185
212
|
/**
|
|
186
213
|
* Unmutes the channel
|
|
187
214
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
@@ -229,11 +256,15 @@ class Channel extends Base {
|
|
|
229
256
|
/**
|
|
230
257
|
* Sends a channel admin invitation to a user, allowing them to become an admin of the channel
|
|
231
258
|
* @param {string} chatId The ID of a user to send the channel admin invitation to
|
|
232
|
-
* @param {SendChannelAdminInviteOptions} options
|
|
259
|
+
* @param {SendChannelAdminInviteOptions} options
|
|
233
260
|
* @returns {Promise<boolean>} Returns true if an invitation was sent successfully, false otherwise
|
|
234
261
|
*/
|
|
235
262
|
async sendChannelAdminInvite(chatId, options = {}) {
|
|
236
|
-
return this.client.sendChannelAdminInvite(
|
|
263
|
+
return this.client.sendChannelAdminInvite(
|
|
264
|
+
chatId,
|
|
265
|
+
this.id._serialized,
|
|
266
|
+
options,
|
|
267
|
+
);
|
|
237
268
|
}
|
|
238
269
|
|
|
239
270
|
/**
|
|
@@ -250,7 +281,10 @@ class Channel extends Base {
|
|
|
250
281
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
251
282
|
*/
|
|
252
283
|
async revokeChannelAdminInvite(userId) {
|
|
253
|
-
return this.client.revokeChannelAdminInvite(
|
|
284
|
+
return this.client.revokeChannelAdminInvite(
|
|
285
|
+
this.id._serialized,
|
|
286
|
+
userId,
|
|
287
|
+
);
|
|
254
288
|
}
|
|
255
289
|
|
|
256
290
|
/**
|
|
@@ -276,7 +310,11 @@ class Channel extends Base {
|
|
|
276
310
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
277
311
|
*/
|
|
278
312
|
async transferChannelOwnership(newOwnerId, options = {}) {
|
|
279
|
-
return this.client.transferChannelOwnership(
|
|
313
|
+
return this.client.transferChannelOwnership(
|
|
314
|
+
this.id._serialized,
|
|
315
|
+
newOwnerId,
|
|
316
|
+
options,
|
|
317
|
+
);
|
|
280
318
|
}
|
|
281
319
|
|
|
282
320
|
/**
|
|
@@ -287,36 +325,50 @@ class Channel extends Base {
|
|
|
287
325
|
* @returns {Promise<Array<Message>>}
|
|
288
326
|
*/
|
|
289
327
|
async fetchMessages(searchOptions) {
|
|
290
|
-
let messages = await this.client.pupPage.evaluate(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
328
|
+
let messages = await this.client.pupPage.evaluate(
|
|
329
|
+
async (channelId, searchOptions) => {
|
|
330
|
+
const msgFilter = (m) => {
|
|
331
|
+
if (
|
|
332
|
+
m.isNotification ||
|
|
333
|
+
m.type === 'newsletter_notification'
|
|
334
|
+
) {
|
|
335
|
+
return false; // dont include notification messages
|
|
336
|
+
}
|
|
337
|
+
if (
|
|
338
|
+
searchOptions &&
|
|
339
|
+
searchOptions.fromMe !== undefined &&
|
|
340
|
+
m.id.fromMe !== searchOptions.fromMe
|
|
341
|
+
) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
return true;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const channel = await window.WWebJS.getChat(channelId, {
|
|
348
|
+
getAsModel: false,
|
|
349
|
+
});
|
|
350
|
+
let msgs = channel.msgs.getModelsArray().filter(msgFilter);
|
|
351
|
+
|
|
352
|
+
if (searchOptions && searchOptions.limit > 0) {
|
|
353
|
+
while (msgs.length < searchOptions.limit) {
|
|
354
|
+
const loadedMessages = await window
|
|
355
|
+
.require('WAWebChatLoadMessages')
|
|
356
|
+
.loadEarlierMsgs({ chat: channel });
|
|
357
|
+
if (!loadedMessages || !loadedMessages.length) break;
|
|
358
|
+
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (msgs.length > searchOptions.limit) {
|
|
362
|
+
msgs.sort((a, b) => (a.t > b.t ? 1 : -1));
|
|
363
|
+
msgs = msgs.splice(msgs.length - searchOptions.limit);
|
|
364
|
+
}
|
|
314
365
|
}
|
|
315
|
-
}
|
|
316
366
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
367
|
+
return msgs.map((m) => window.WWebJS.getMessageModel(m));
|
|
368
|
+
},
|
|
369
|
+
this.id._serialized,
|
|
370
|
+
searchOptions,
|
|
371
|
+
);
|
|
320
372
|
|
|
321
373
|
return messages.map((msg) => new Message(this.client, msg));
|
|
322
374
|
}
|
|
@@ -336,27 +388,39 @@ class Channel extends Base {
|
|
|
336
388
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
337
389
|
*/
|
|
338
390
|
async _setChannelMetadata(value, property) {
|
|
339
|
-
return await this.client.pupPage.evaluate(
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
391
|
+
return await this.client.pupPage.evaluate(
|
|
392
|
+
async (channelId, value, property) => {
|
|
393
|
+
const channel = await window.WWebJS.getChat(channelId, {
|
|
394
|
+
getAsModel: false,
|
|
395
|
+
});
|
|
396
|
+
if (!channel) return false;
|
|
397
|
+
if (property.editPicture) {
|
|
398
|
+
value.picture = value.picture
|
|
399
|
+
? await window.WWebJS.cropAndResizeImage(
|
|
400
|
+
value.picture,
|
|
401
|
+
{
|
|
402
|
+
asDataUrl: true,
|
|
403
|
+
mimetype: 'image/jpeg',
|
|
404
|
+
size: 640,
|
|
405
|
+
quality: 1,
|
|
406
|
+
},
|
|
407
|
+
)
|
|
408
|
+
: null;
|
|
409
|
+
}
|
|
410
|
+
try {
|
|
411
|
+
await window
|
|
412
|
+
.require('WAWebEditNewsletterMetadataAction')
|
|
413
|
+
.editNewsletterMetadataAction(channel, property, value);
|
|
414
|
+
return true;
|
|
415
|
+
} catch (err) {
|
|
416
|
+
if (err.name === 'ServerStatusCodeError') return false;
|
|
417
|
+
throw err;
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
this.id._serialized,
|
|
421
|
+
value,
|
|
422
|
+
property,
|
|
423
|
+
);
|
|
360
424
|
}
|
|
361
425
|
|
|
362
426
|
/**
|
|
@@ -365,19 +429,35 @@ class Channel extends Base {
|
|
|
365
429
|
* @returns {Promise<boolean>} Returns true if the operation completed successfully, false otherwise
|
|
366
430
|
*/
|
|
367
431
|
async _muteUnmuteChannel(action) {
|
|
368
|
-
return await this.client.pupPage.evaluate(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
432
|
+
return await this.client.pupPage.evaluate(
|
|
433
|
+
async (channelId, action) => {
|
|
434
|
+
try {
|
|
435
|
+
await window
|
|
436
|
+
.require('WAWebNewsletterUpdateUserSettingJob')
|
|
437
|
+
.updateNewsletterUserSetting({
|
|
438
|
+
newsletterJid: window
|
|
439
|
+
.require('WAJids')
|
|
440
|
+
.toNewsletterJid(channelId),
|
|
441
|
+
type: window.require('WAWebNewsletterModelUtils')
|
|
442
|
+
.ADMIN_NOTIFICATIONS,
|
|
443
|
+
muteExpirationValue:
|
|
444
|
+
action === 'MUTE'
|
|
445
|
+
? window.require(
|
|
446
|
+
'WAWebNewsletterModelUtils',
|
|
447
|
+
).MUTED_STATE
|
|
448
|
+
: window.require(
|
|
449
|
+
'WAWebNewsletterModelUtils',
|
|
450
|
+
).UNMUTED_STATE,
|
|
451
|
+
});
|
|
452
|
+
return true;
|
|
453
|
+
} catch (err) {
|
|
454
|
+
if (err.name === 'ServerStatusCodeError') return false;
|
|
455
|
+
throw err;
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
this.id._serialized,
|
|
459
|
+
action,
|
|
460
|
+
);
|
|
381
461
|
}
|
|
382
462
|
}
|
|
383
463
|
|
package/src/structures/Chat.js
CHANGED
|
@@ -85,15 +85,17 @@ class Chat extends Base {
|
|
|
85
85
|
* Last message fo chat
|
|
86
86
|
* @type {Message}
|
|
87
87
|
*/
|
|
88
|
-
this.lastMessage = data.lastMessage
|
|
89
|
-
|
|
88
|
+
this.lastMessage = data.lastMessage
|
|
89
|
+
? new Message(this.client, data.lastMessage)
|
|
90
|
+
: undefined;
|
|
91
|
+
|
|
90
92
|
return super._patch(data);
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
96
|
* Send a message to this chat
|
|
95
97
|
* @param {string|MessageMedia|Location} content
|
|
96
|
-
* @param {MessageSendOptions} [options]
|
|
98
|
+
* @param {MessageSendOptions} [options]
|
|
97
99
|
* @returns {Promise<Message>} Message that was just sent
|
|
98
100
|
*/
|
|
99
101
|
async sendMessage(content, options) {
|
|
@@ -113,7 +115,7 @@ class Chat extends Base {
|
|
|
113
115
|
* @returns {Promise<boolean>} result
|
|
114
116
|
*/
|
|
115
117
|
async clearMessages() {
|
|
116
|
-
return this.client.pupPage.evaluate(chatId => {
|
|
118
|
+
return this.client.pupPage.evaluate((chatId) => {
|
|
117
119
|
return window.WWebJS.sendClearChat(chatId);
|
|
118
120
|
}, this.id._serialized);
|
|
119
121
|
}
|
|
@@ -123,7 +125,7 @@ class Chat extends Base {
|
|
|
123
125
|
* @returns {Promise<Boolean>} result
|
|
124
126
|
*/
|
|
125
127
|
async delete() {
|
|
126
|
-
return this.client.pupPage.evaluate(chatId => {
|
|
128
|
+
return this.client.pupPage.evaluate((chatId) => {
|
|
127
129
|
return window.WWebJS.sendDeleteChat(chatId);
|
|
128
130
|
}, this.id._serialized);
|
|
129
131
|
}
|
|
@@ -164,7 +166,10 @@ class Chat extends Base {
|
|
|
164
166
|
* @returns {Promise<{isMuted: boolean, muteExpiration: number}>}
|
|
165
167
|
*/
|
|
166
168
|
async mute(unmuteDate) {
|
|
167
|
-
const result = await this.client.muteChat(
|
|
169
|
+
const result = await this.client.muteChat(
|
|
170
|
+
this.id._serialized,
|
|
171
|
+
unmuteDate,
|
|
172
|
+
);
|
|
168
173
|
this.isMuted = result.isMuted;
|
|
169
174
|
this.muteExpiration = result.muteExpiration;
|
|
170
175
|
return result;
|
|
@@ -184,7 +189,7 @@ class Chat extends Base {
|
|
|
184
189
|
/**
|
|
185
190
|
* Mark this chat as unread
|
|
186
191
|
*/
|
|
187
|
-
async markUnread(){
|
|
192
|
+
async markUnread() {
|
|
188
193
|
return this.client.markChatUnread(this.id._serialized);
|
|
189
194
|
}
|
|
190
195
|
|
|
@@ -196,45 +201,56 @@ class Chat extends Base {
|
|
|
196
201
|
* @returns {Promise<Array<Message>>}
|
|
197
202
|
*/
|
|
198
203
|
async fetchMessages(searchOptions) {
|
|
199
|
-
let messages = await this.client.pupPage.evaluate(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
let messages = await this.client.pupPage.evaluate(
|
|
205
|
+
async (chatId, searchOptions) => {
|
|
206
|
+
const msgFilter = (m) => {
|
|
207
|
+
if (m.isNotification) {
|
|
208
|
+
return false; // dont include notification messages
|
|
209
|
+
}
|
|
210
|
+
if (
|
|
211
|
+
searchOptions &&
|
|
212
|
+
searchOptions.fromMe !== undefined &&
|
|
213
|
+
m.id.fromMe !== searchOptions.fromMe
|
|
214
|
+
) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
return true;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const chat = await window.WWebJS.getChat(chatId, {
|
|
221
|
+
getAsModel: false,
|
|
222
|
+
});
|
|
223
|
+
let msgs = chat.msgs.getModelsArray().filter(msgFilter);
|
|
224
|
+
|
|
225
|
+
if (searchOptions && searchOptions.limit > 0) {
|
|
226
|
+
while (msgs.length < searchOptions.limit) {
|
|
227
|
+
const loadedMessages = await window
|
|
228
|
+
.require('WAWebChatLoadMessages')
|
|
229
|
+
.loadEarlierMsgs({ chat });
|
|
230
|
+
if (!loadedMessages || !loadedMessages.length) break;
|
|
231
|
+
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (msgs.length > searchOptions.limit) {
|
|
235
|
+
msgs.sort((a, b) => (a.t > b.t ? 1 : -1));
|
|
236
|
+
msgs = msgs.splice(msgs.length - searchOptions.limit);
|
|
237
|
+
}
|
|
206
238
|
}
|
|
207
|
-
return true;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
211
|
-
let msgs = chat.msgs.getModelsArray().filter(msgFilter);
|
|
212
239
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (msgs.length > searchOptions.limit) {
|
|
221
|
-
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
|
|
222
|
-
msgs = msgs.splice(msgs.length - searchOptions.limit);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
240
|
+
return msgs.map((m) => window.WWebJS.getMessageModel(m));
|
|
241
|
+
},
|
|
242
|
+
this.id._serialized,
|
|
243
|
+
searchOptions,
|
|
244
|
+
);
|
|
225
245
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}, this.id._serialized, searchOptions);
|
|
229
|
-
|
|
230
|
-
return messages.map(m => new Message(this.client, m));
|
|
246
|
+
return messages.map((m) => new Message(this.client, m));
|
|
231
247
|
}
|
|
232
248
|
|
|
233
249
|
/**
|
|
234
250
|
* Simulate typing in chat. This will last for 25 seconds.
|
|
235
251
|
*/
|
|
236
252
|
async sendStateTyping() {
|
|
237
|
-
return this.client.pupPage.evaluate(chatId => {
|
|
253
|
+
return this.client.pupPage.evaluate((chatId) => {
|
|
238
254
|
window.WWebJS.sendChatstate('typing', chatId);
|
|
239
255
|
return true;
|
|
240
256
|
}, this.id._serialized);
|
|
@@ -244,7 +260,7 @@ class Chat extends Base {
|
|
|
244
260
|
* Simulate recording audio in chat. This will last for 25 seconds.
|
|
245
261
|
*/
|
|
246
262
|
async sendStateRecording() {
|
|
247
|
-
return this.client.pupPage.evaluate(chatId => {
|
|
263
|
+
return this.client.pupPage.evaluate((chatId) => {
|
|
248
264
|
window.WWebJS.sendChatstate('recording', chatId);
|
|
249
265
|
return true;
|
|
250
266
|
}, this.id._serialized);
|
|
@@ -254,7 +270,7 @@ class Chat extends Base {
|
|
|
254
270
|
* Stops typing or recording in chat immediately.
|
|
255
271
|
*/
|
|
256
272
|
async clearState() {
|
|
257
|
-
return this.client.pupPage.evaluate(chatId => {
|
|
273
|
+
return this.client.pupPage.evaluate((chatId) => {
|
|
258
274
|
window.WWebJS.sendChatstate('stop', chatId);
|
|
259
275
|
return true;
|
|
260
276
|
}, this.id._serialized);
|
|
@@ -292,7 +308,7 @@ class Chat extends Base {
|
|
|
292
308
|
async getPinnedMessages() {
|
|
293
309
|
return this.client.getPinnedMessages(this.id._serialized);
|
|
294
310
|
}
|
|
295
|
-
|
|
311
|
+
|
|
296
312
|
/**
|
|
297
313
|
* Sync chat history conversation
|
|
298
314
|
* @return {Promise<boolean>} True if operation completed successfully, false otherwise.
|
|
@@ -327,7 +343,7 @@ class Chat extends Base {
|
|
|
327
343
|
*/
|
|
328
344
|
async getCustomerNote() {
|
|
329
345
|
if (this.isGroup || this.isChannel) return null;
|
|
330
|
-
|
|
346
|
+
|
|
331
347
|
return this.client.getCustomerNote(this.id._serialized);
|
|
332
348
|
}
|
|
333
349
|
}
|