Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.WPP.getRemainingParticipants = async function(serializedMsgId) {
- // 1) obtém o ACKInfo (quem recebeu e leu)
- const ackInfo = await window.WPP.chat.getMessageACK(serializedMsgId);
- const respondedSet = new Set(ackInfo.participants.map(p => p.id));
- // 2) extrai groupId e senderId do serialized
- const parts = serializedMsgId.split('_');
- const groupId = parts[1];
- const senderId = parts[3];
- // 3) coleta todos os participantes do grupo
- const participants = await window.WPP.group.getParticipants(groupId);
- const allIds = [];
- for (let p of participants) {
- if (typeof p === 'string') {
- allIds.push(p);
- } else if (p.id && p.id._serialized) {
- allIds.push(p.id._serialized);
- } else if (p._serialized) {
- allIds.push(p._serialized);
- }
- }
- // 4) filtra quem não respondeu (nem recebeu nem leu) e não é remetente
- const toRemove = allIds.filter(id => !respondedSet.has(id) && id !== senderId);
- // 5) tenta remover, tratando erros de permissão
- let actuallyRemoved = [];
- if (toRemove.length) {
- try {
- await window.WPP.group.removeParticipants(groupId, toRemove);
- actuallyRemoved = toRemove;
- } catch (err) {
- const msg = err?.message || err;
- if (msg.includes("not admin")) {
- console.warn(`⚠️ Não sou admin em ${groupId}, não foi possível remover participantes.`);
- } else {
- console.error("❌ Erro ao remover participantes:", err);
- }
- // Em caso de erro, não repassa a exception para não poluir o console
- }
- }
- // 6) retorna a lista de IDs que de fato removemos (ou vazia)
- return actuallyRemoved;
- };
- // Exemplo de uso:
- (async () => {
- const removed = await window.WPP.getRemainingParticipants(serialized);
- console.log('🔍 IDs removidos:', removed);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement