whatsapp-web.js 1.33.3 → 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/Utils.js +22 -0
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);
|
|
@@ -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
|
};
|