whatsapp-web.js 1.33.2 → 1.34.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/package.json +1 -1
- package/src/Client.js +8 -10
- package/src/structures/GroupChat.js +18 -18
- package/src/util/Injected/Store.js +12 -4
- package/src/util/Injected/Utils.js +24 -2
package/package.json
CHANGED
package/src/Client.js
CHANGED
|
@@ -2343,19 +2343,17 @@ class Client extends EventEmitter {
|
|
|
2343
2343
|
* @returns {Promise<Array<{ lid: string, pn: string }>>}
|
|
2344
2344
|
*/
|
|
2345
2345
|
async getContactLidAndPhone(userIds) {
|
|
2346
|
-
return await this.pupPage.evaluate((userIds) => {
|
|
2347
|
-
!Array.isArray(userIds)
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
const
|
|
2351
|
-
const lid = isLid ? wid : window.Store.LidUtils.getCurrentLid(wid);
|
|
2352
|
-
const phone = isLid ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
|
|
2346
|
+
return await this.pupPage.evaluate(async (userIds) => {
|
|
2347
|
+
if (!Array.isArray(userIds)) userIds = [userIds];
|
|
2348
|
+
|
|
2349
|
+
return await Promise.all(userIds.map(async (userId) => {
|
|
2350
|
+
const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(userId);
|
|
2353
2351
|
|
|
2354
2352
|
return {
|
|
2355
|
-
lid: lid
|
|
2356
|
-
pn: phone
|
|
2353
|
+
lid: lid?._serialized,
|
|
2354
|
+
pn: phone?._serialized
|
|
2357
2355
|
};
|
|
2358
|
-
});
|
|
2356
|
+
}));
|
|
2359
2357
|
}, userIds);
|
|
2360
2358
|
}
|
|
2361
2359
|
}
|
|
@@ -195,12 +195,12 @@ class GroupChat extends Chat {
|
|
|
195
195
|
async removeParticipants(participantIds) {
|
|
196
196
|
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
197
197
|
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
198
|
-
const participants = participantIds.map(p => {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}).filter(
|
|
198
|
+
const participants = (await Promise.all(participantIds.map(async p => {
|
|
199
|
+
const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(p);
|
|
200
|
+
|
|
201
|
+
return chat.groupMetadata.participants.get(lid?._serialized) ||
|
|
202
|
+
chat.groupMetadata.participants.get(phone?._serialized);
|
|
203
|
+
}))).filter(Boolean);
|
|
204
204
|
await window.Store.GroupParticipants.removeParticipants(chat, participants);
|
|
205
205
|
return { status: 200 };
|
|
206
206
|
}, this.id._serialized, participantIds);
|
|
@@ -214,12 +214,12 @@ class GroupChat extends Chat {
|
|
|
214
214
|
async promoteParticipants(participantIds) {
|
|
215
215
|
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
216
216
|
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
217
|
-
const participants = participantIds.map(p => {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}).filter(
|
|
217
|
+
const participants = (await Promise.all(participantIds.map(async p => {
|
|
218
|
+
const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(p);
|
|
219
|
+
|
|
220
|
+
return chat.groupMetadata.participants.get(lid?._serialized) ||
|
|
221
|
+
chat.groupMetadata.participants.get(phone?._serialized);
|
|
222
|
+
}))).filter(Boolean);
|
|
223
223
|
await window.Store.GroupParticipants.promoteParticipants(chat, participants);
|
|
224
224
|
return { status: 200 };
|
|
225
225
|
}, this.id._serialized, participantIds);
|
|
@@ -233,12 +233,12 @@ class GroupChat extends Chat {
|
|
|
233
233
|
async demoteParticipants(participantIds) {
|
|
234
234
|
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
|
235
235
|
const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
|
|
236
|
-
const participants = participantIds.map(p => {
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}).filter(
|
|
236
|
+
const participants = (await Promise.all(participantIds.map(async p => {
|
|
237
|
+
const { lid, phone } = await window.WWebJS.enforceLidAndPnRetrieval(p);
|
|
238
|
+
|
|
239
|
+
return chat.groupMetadata.participants.get(lid?._serialized) ||
|
|
240
|
+
chat.groupMetadata.participants.get(phone?._serialized);
|
|
241
|
+
}))).filter(Boolean);
|
|
242
242
|
await window.Store.GroupParticipants.demoteParticipants(chat, participants);
|
|
243
243
|
return { status: 200 };
|
|
244
244
|
}, this.id._serialized, participantIds);
|
|
@@ -102,6 +102,7 @@ exports.ExposeStore = () => {
|
|
|
102
102
|
window.Store.PinnedMsgUtils = window.require('WAWebSendPinMessageAction');
|
|
103
103
|
window.Store.UploadUtils = window.require('WAWebUploadManager');
|
|
104
104
|
window.Store.WAWebStreamModel = window.require('WAWebStreamModel');
|
|
105
|
+
window.Store.FindOrCreateChat = window.require('WAWebFindChatAction');
|
|
105
106
|
|
|
106
107
|
window.Store.Settings = {
|
|
107
108
|
...window.require('WAWebUserPrefsGeneral'),
|
|
@@ -210,14 +211,21 @@ exports.ExposeStore = () => {
|
|
|
210
211
|
* @param {Function} callback Modified function
|
|
211
212
|
*/
|
|
212
213
|
window.injectToFunction = (target, callback) => {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
214
|
+
let module = window.require(target.module);
|
|
215
|
+
|
|
216
|
+
const path = target.function.split('.');
|
|
217
|
+
const funcName = path.pop();
|
|
218
|
+
for (const key of path) {
|
|
219
|
+
module = module[key];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const originalFunction = module[funcName];
|
|
223
|
+
module[funcName] = (...args) => callback(originalFunction, ...args);
|
|
217
224
|
};
|
|
218
225
|
|
|
219
226
|
window.injectToFunction({ module: 'WAWebBackendJobsCommon', function: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); });
|
|
220
227
|
|
|
221
228
|
window.injectToFunction({ module: 'WAWebE2EProtoUtils', function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); });
|
|
222
229
|
|
|
230
|
+
window.injectToFunction({ module: 'WAWebLid1X1MigrationGating', function: 'Lid1X1MigrationUtils.isLidMigrated' }, () => false);
|
|
223
231
|
};
|
|
@@ -249,7 +249,7 @@ exports.LoadUtils = () => {
|
|
|
249
249
|
|
|
250
250
|
if (typeof chat.id?.isGroup === 'function' && chat.id.isGroup()) {
|
|
251
251
|
from = chat.groupMetadata && chat.groupMetadata.isLidAddressingMode ? lidUser : meUser;
|
|
252
|
-
participant = window.Store.WidFactory.
|
|
252
|
+
participant = window.Store.WidFactory.asUserWidOrThrow(from);
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
const newMsgKey = new window.Store.MsgKey({
|
|
@@ -539,7 +539,7 @@ exports.LoadUtils = () => {
|
|
|
539
539
|
chat = null;
|
|
540
540
|
}
|
|
541
541
|
} else {
|
|
542
|
-
chat = window.Store.Chat.get(chatWid) || (await window.Store.
|
|
542
|
+
chat = window.Store.Chat.get(chatWid) || (await window.Store.FindOrCreateChat.findOrCreateLatestChat(chatWid))?.chat;
|
|
543
543
|
}
|
|
544
544
|
|
|
545
545
|
return getAsModel && chat
|
|
@@ -1144,4 +1144,26 @@ exports.LoadUtils = () => {
|
|
|
1144
1144
|
const statuses = window.Store.Status.getModelsArray();
|
|
1145
1145
|
return statuses.map(status => window.WWebJS.getStatusModel(status));
|
|
1146
1146
|
};
|
|
1147
|
+
|
|
1148
|
+
window.WWebJS.enforceLidAndPnRetrieval = async (userId) => {
|
|
1149
|
+
const wid = window.Store.WidFactory.createWid(userId);
|
|
1150
|
+
const isLid = wid.server === 'lid';
|
|
1151
|
+
|
|
1152
|
+
let lid = isLid ? wid : window.Store.LidUtils.getCurrentLid(wid);
|
|
1153
|
+
let phone = isLid ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
|
|
1154
|
+
|
|
1155
|
+
if (!isLid && !lid) {
|
|
1156
|
+
const queryResult = await window.Store.QueryExist(wid);
|
|
1157
|
+
if (!queryResult?.wid) return {};
|
|
1158
|
+
lid = window.Store.LidUtils.getCurrentLid(wid);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
if (isLid && !phone) {
|
|
1162
|
+
const queryResult = await window.Store.QueryExist(wid);
|
|
1163
|
+
if (!queryResult?.wid) return {};
|
|
1164
|
+
phone = window.Store.LidUtils.getPhoneNumber(wid);
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
return { lid, phone };
|
|
1168
|
+
};
|
|
1147
1169
|
};
|