mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 11:39:14 +00:00
Compare commits
20 Commits
main
...
patch-part
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48a3a03cdc | ||
|
|
9b659a26fa | ||
|
|
f0c7a0b0c2 | ||
|
|
53b8c1d967 | ||
|
|
56ec18a67c | ||
|
|
3775fd7c3e | ||
|
|
4247257850 | ||
|
|
374a6c505f | ||
|
|
1f80a86962 | ||
|
|
a9bbc0ed99 | ||
|
|
b99aa61dcc | ||
|
|
4ffd83015e | ||
|
|
510d44dc3e | ||
|
|
02ad3e0fd0 | ||
|
|
6ae8c42816 | ||
|
|
7fc72fe149 | ||
|
|
e980bf9b07 | ||
|
|
8e6314212d | ||
|
|
eb0d000159 | ||
|
|
cf5c5e4ec1 |
4
index.d.ts
vendored
4
index.d.ts
vendored
@@ -1108,11 +1108,11 @@ declare namespace WAWebJS {
|
|||||||
|
|
||||||
/** Promotes or demotes participants by IDs to regular users or admins */
|
/** Promotes or demotes participants by IDs to regular users or admins */
|
||||||
export type ChangeParticipantsPermissions =
|
export type ChangeParticipantsPermissions =
|
||||||
(participantIds: Array<string>) => Promise<{ status: number }>
|
(participantIds: Array<string>, sleep?: number) => Promise<{ status: number }>
|
||||||
|
|
||||||
/** Adds or removes a list of participants by ID to the group */
|
/** Adds or removes a list of participants by ID to the group */
|
||||||
export type ChangeGroupParticipants =
|
export type ChangeGroupParticipants =
|
||||||
(participantIds: Array<string>) => Promise<{
|
(participantIds: Array<string>, sleep?: number) => Promise<{
|
||||||
status: number;
|
status: number;
|
||||||
participants: Array<{
|
participants: Array<{
|
||||||
[key: string]: {
|
[key: string]: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Chat = require('./Chat');
|
const Chat = require('./Chat');
|
||||||
|
const Util = require('../util/Util');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Group participant information
|
* Group participant information
|
||||||
@@ -52,57 +53,65 @@ class GroupChat extends Chat {
|
|||||||
get participants() {
|
get participants() {
|
||||||
return this.groupMetadata.participants;
|
return this.groupMetadata.participants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal function to change a number of participant's state..
|
||||||
|
* @param {string} type (promote|demote|add|remove)
|
||||||
|
*/
|
||||||
|
async _changeParticipants(participantIds, type, sleep = null) {
|
||||||
|
return await this.client.pupPage.evaluate(async (chatId, participantIds, type, sleep) => {
|
||||||
|
if (type != 'add' && type != 'remove' && type != 'promote' && type != 'demote') return null;
|
||||||
|
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||||
|
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||||
|
const status = [];
|
||||||
|
for (const participantWid of participantWids) {
|
||||||
|
status.push(await window.Store.GroupParticipants['send'+type.charAt(0).toUpperCase() + type.slice(1)+'Participants'](chatWid, [participantWid]));
|
||||||
|
if (sleep) {
|
||||||
|
await Util.sleep(sleep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}, this.id._serialized, participantIds, type, sleep);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a list of participants by ID to the group
|
* Adds a list of participants by ID to the group
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @returns {Promise<Object>}
|
* @param {?number} default 100ms, amount to sleep in milliseconds before adding the next participant
|
||||||
|
* @returns {Promise<Array<Object>>}
|
||||||
*/
|
*/
|
||||||
async addParticipants(participantIds) {
|
async addParticipants(participantIds, sleep = 100) {
|
||||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
return this._changeParticipants(participantIds, 'add', sleep);
|
||||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
||||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
|
||||||
return window.Store.GroupParticipants.sendAddParticipants(chatWid, participantWids);
|
|
||||||
}, this.id._serialized, participantIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a list of participants by ID to the group
|
* Removes a list of participants by ID to the group
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @returns {Promise<Object>}
|
* @param {?number} default 100ms, amount to sleep in milliseconds before removing the next participant
|
||||||
|
* @returns {Promise<Array<Object>>}
|
||||||
*/
|
*/
|
||||||
async removeParticipants(participantIds) {
|
async removeParticipants(participantIds, sleep = 100) {
|
||||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
return this._changeParticipants(participantIds, 'remove', sleep);
|
||||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
||||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
|
||||||
return window.Store.GroupParticipants.sendRemoveParticipants(chatWid, participantWids);
|
|
||||||
}, this.id._serialized, participantIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promotes participants by IDs to admins
|
* Promote participants to admins by IDs
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
* @param {?number} default 100ms, amount to sleep in milliseconds before promoting the next participant
|
||||||
|
* @returns {Promise<Array<Object>>}
|
||||||
*/
|
*/
|
||||||
async promoteParticipants(participantIds) {
|
async promoteParticipants(participantIds, sleep = 100) {
|
||||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
return this._changeParticipants(participantIds, 'promote', sleep);
|
||||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
||||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
|
||||||
return window.Store.GroupParticipants.sendPromoteParticipants(chatWid, participantWids);
|
|
||||||
}, this.id._serialized, participantIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Demotes participants by IDs to regular users
|
* Demotes admins to regular participants by IDs
|
||||||
* @param {Array<string>} participantIds
|
* @param {Array<string>} participantIds
|
||||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
* @param {?number} default 100ms, amount to sleep in milliseconds before demoting the next participant
|
||||||
|
* @returns {Promise<Array<Object>>}
|
||||||
*/
|
*/
|
||||||
async demoteParticipants(participantIds) {
|
async demoteParticipants(participantIds, sleep = 100) {
|
||||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
return this._changeParticipants(participantIds, 'demote', sleep);
|
||||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
|
||||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
|
||||||
return window.Store.GroupParticipants.sendDemoteParticipants(chatWid, participantWids);
|
|
||||||
}, this.id._serialized, participantIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,4 +240,4 @@ class GroupChat extends Chat {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = GroupChat;
|
module.exports = GroupChat;
|
||||||
|
|||||||
@@ -181,6 +181,10 @@ class Util {
|
|||||||
static setFfmpegPath(path) {
|
static setFfmpegPath(path) {
|
||||||
ffmpeg.setFfmpegPath(path);
|
ffmpeg.setFfmpegPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sleep(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Util;
|
module.exports = Util;
|
||||||
|
|||||||
Reference in New Issue
Block a user