mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
Merge branch 'main' into fix-buttons-list
This commit is contained in:
@@ -774,7 +774,7 @@ class Client extends EventEmitter {
|
||||
*/
|
||||
async getInviteInfo(inviteCode) {
|
||||
return await this.pupPage.evaluate(inviteCode => {
|
||||
return window.Store.InviteInfo.sendQueryGroupInvite(inviteCode);
|
||||
return window.Store.InviteInfo.queryGroupInvite(inviteCode);
|
||||
}, inviteCode);
|
||||
}
|
||||
|
||||
@@ -784,11 +784,11 @@ class Client extends EventEmitter {
|
||||
* @returns {Promise<string>} Id of the joined Chat
|
||||
*/
|
||||
async acceptInvite(inviteCode) {
|
||||
const chatId = await this.pupPage.evaluate(async inviteCode => {
|
||||
return await window.Store.Invite.sendJoinGroupViaInvite(inviteCode);
|
||||
const res = await this.pupPage.evaluate(async inviteCode => {
|
||||
return await window.Store.Invite.joinGroupViaInvite(inviteCode);
|
||||
}, inviteCode);
|
||||
|
||||
return chatId._serialized;
|
||||
return res.gid._serialized;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1095,19 +1095,17 @@ class Client extends EventEmitter {
|
||||
|
||||
const createRes = await this.pupPage.evaluate(async (name, participantIds) => {
|
||||
const participantWIDs = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||
const id = window.Store.MsgKey.newId();
|
||||
const res = await window.Store.GroupUtils.sendCreateGroup(name, participantWIDs, undefined, id);
|
||||
return res;
|
||||
return await window.Store.GroupUtils.createGroup(name, participantWIDs, 0);
|
||||
}, name, participants);
|
||||
|
||||
const missingParticipants = createRes.participants.reduce(((missing, c) => {
|
||||
const id = Object.keys(c)[0];
|
||||
const statusCode = c[id].code;
|
||||
const id = c.wid._serialized;
|
||||
const statusCode = c.error ? c.error.toString() : '200';
|
||||
if (statusCode != 200) return Object.assign(missing, { [id]: statusCode });
|
||||
return missing;
|
||||
}), {});
|
||||
|
||||
return { gid: createRes.gid, missingParticipants };
|
||||
return { gid: createRes.wid, missingParticipants };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,10 +59,15 @@ class GroupChat extends Chat {
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async addParticipants(participantIds) {
|
||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||
return window.Store.GroupParticipants.sendAddParticipants(chatWid, participantWids);
|
||||
const chat = await window.Store.Chat.find(chatWid);
|
||||
const participants = await Promise.all(participantIds.map(async p => {
|
||||
const wid = window.Store.WidFactory.createWid(p);
|
||||
return await window.Store.Contact.get(wid);
|
||||
}));
|
||||
await window.Store.GroupParticipants.addParticipants(chat, participants);
|
||||
return { status: 200 };
|
||||
}, this.id._serialized, participantIds);
|
||||
}
|
||||
|
||||
@@ -72,10 +77,14 @@ class GroupChat extends Chat {
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async removeParticipants(participantIds) {
|
||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||
return window.Store.GroupParticipants.sendRemoveParticipants(chatWid, participantWids);
|
||||
const chat = await window.Store.Chat.find(chatWid);
|
||||
const participants = participantIds.map(p => {
|
||||
return chat.groupMetadata.participants.get(p);
|
||||
}).filter(p => Boolean(p));
|
||||
await window.Store.GroupParticipants.removeParticipants(chat, participants);
|
||||
return { status: 200 };
|
||||
}, this.id._serialized, participantIds);
|
||||
}
|
||||
|
||||
@@ -85,10 +94,14 @@ class GroupChat extends Chat {
|
||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
||||
*/
|
||||
async promoteParticipants(participantIds) {
|
||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||
return window.Store.GroupParticipants.sendPromoteParticipants(chatWid, participantWids);
|
||||
const chat = await window.Store.Chat.find(chatWid);
|
||||
const participants = participantIds.map(p => {
|
||||
return chat.groupMetadata.participants.get(p);
|
||||
}).filter(p => Boolean(p));
|
||||
await window.Store.GroupParticipants.promoteParticipants(chat, participants);
|
||||
return { status: 200 };
|
||||
}, this.id._serialized, participantIds);
|
||||
}
|
||||
|
||||
@@ -98,10 +111,14 @@ class GroupChat extends Chat {
|
||||
* @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
|
||||
*/
|
||||
async demoteParticipants(participantIds) {
|
||||
return await this.client.pupPage.evaluate((chatId, participantIds) => {
|
||||
return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
const participantWids = participantIds.map(p => window.Store.WidFactory.createWid(p));
|
||||
return window.Store.GroupParticipants.sendDemoteParticipants(chatWid, participantWids);
|
||||
const chat = await window.Store.Chat.find(chatWid);
|
||||
const participants = participantIds.map(p => {
|
||||
return chat.groupMetadata.participants.get(p);
|
||||
}).filter(p => Boolean(p));
|
||||
await window.Store.GroupParticipants.demoteParticipants(chat, participants);
|
||||
return { status: 200 };
|
||||
}, this.id._serialized, participantIds);
|
||||
}
|
||||
|
||||
@@ -114,7 +131,8 @@ class GroupChat extends Chat {
|
||||
const success = await this.client.pupPage.evaluate(async (chatId, subject) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
try {
|
||||
return await window.Store.GroupUtils.sendSetGroupSubject(chatWid, subject);
|
||||
await window.Store.GroupUtils.setGroupSubject(chatWid, subject);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if(err.name === 'ServerStatusCodeError') return false;
|
||||
throw err;
|
||||
@@ -136,7 +154,8 @@ class GroupChat extends Chat {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
let descId = window.Store.GroupMetadata.get(chatWid).descId;
|
||||
try {
|
||||
return await window.Store.GroupUtils.sendSetGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId);
|
||||
await window.Store.GroupUtils.setGroupDescription(chatWid, description, window.Store.MsgKey.newId(), descId);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if(err.name === 'ServerStatusCodeError') return false;
|
||||
throw err;
|
||||
@@ -157,7 +176,8 @@ class GroupChat extends Chat {
|
||||
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
try {
|
||||
return await window.Store.GroupUtils.sendSetGroupProperty(chatWid, 'announcement', adminsOnly ? 1 : 0);
|
||||
await window.Store.GroupUtils.setGroupProperty(chatWid, 'announcement', adminsOnly ? 1 : 0);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if(err.name === 'ServerStatusCodeError') return false;
|
||||
throw err;
|
||||
@@ -179,7 +199,8 @@ class GroupChat extends Chat {
|
||||
const success = await this.client.pupPage.evaluate(async (chatId, adminsOnly) => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
try {
|
||||
return await window.Store.GroupUtils.sendSetGroupProperty(chatWid, 'restrict', adminsOnly ? 1 : 0);
|
||||
await window.Store.GroupUtils.setGroupProperty(chatWid, 'restrict', adminsOnly ? 1 : 0);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if(err.name === 'ServerStatusCodeError') return false;
|
||||
throw err;
|
||||
@@ -197,12 +218,12 @@ class GroupChat extends Chat {
|
||||
* @returns {Promise<string>} Group's invite code
|
||||
*/
|
||||
async getInviteCode() {
|
||||
const code = await this.client.pupPage.evaluate(async chatId => {
|
||||
const codeRes = await this.client.pupPage.evaluate(async chatId => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
return window.Store.Invite.sendQueryGroupInviteCode(chatWid);
|
||||
return window.Store.Invite.queryGroupInviteCode(chatWid);
|
||||
}, this.id._serialized);
|
||||
|
||||
return code;
|
||||
return codeRes.code;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,12 +231,12 @@ class GroupChat extends Chat {
|
||||
* @returns {Promise<string>} New invite code
|
||||
*/
|
||||
async revokeInvite() {
|
||||
const code = await this.client.pupPage.evaluate(chatId => {
|
||||
const codeRes = await this.client.pupPage.evaluate(chatId => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
return window.Store.Invite.sendRevokeGroupInviteCode(chatWid);
|
||||
return window.Store.Invite.resetGroupInviteCode(chatWid);
|
||||
}, this.id._serialized);
|
||||
|
||||
return code;
|
||||
return codeRes.code;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,9 +244,10 @@ class GroupChat extends Chat {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async leave() {
|
||||
await this.client.pupPage.evaluate(chatId => {
|
||||
await this.client.pupPage.evaluate(async chatId => {
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId);
|
||||
return window.Store.GroupUtils.sendExitGroup(chatWid);
|
||||
const chat = await window.Store.Chat.find(chatWid);
|
||||
return window.Store.GroupUtils.sendExitGroup(chat);
|
||||
}, this.id._serialized);
|
||||
}
|
||||
|
||||
|
||||
@@ -386,7 +386,9 @@ class Message extends Base {
|
||||
|
||||
const result = await this.client.pupPage.evaluate(async (msgId) => {
|
||||
const msg = window.Store.Msg.get(msgId);
|
||||
|
||||
if (!msg) {
|
||||
return undefined;
|
||||
}
|
||||
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
||||
// try to resolve media
|
||||
await msg.downloadMedia({
|
||||
|
||||
@@ -13,10 +13,9 @@ exports.ExposeStore = (moduleRaidStr) => {
|
||||
window.Store.Cmd = window.mR.findModule('Cmd')[0].Cmd;
|
||||
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
|
||||
window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
|
||||
window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].LegacyPhoneFeatures;
|
||||
window.Store.GroupMetadata = window.mR.findModule('GroupMetadata')[0].default.GroupMetadata;
|
||||
window.Store.Invite = window.mR.findModule('sendJoinGroupViaInvite')[0];
|
||||
window.Store.InviteInfo = window.mR.findModule('sendQueryGroupInvite')[0];
|
||||
window.Store.Invite = window.mR.findModule('resetGroupInviteCode')[0];
|
||||
window.Store.InviteInfo = window.mR.findModule('queryGroupInvite')[0];
|
||||
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection;
|
||||
window.Store.MediaPrep = window.mR.findModule('MediaPrep')[0];
|
||||
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
|
||||
@@ -42,7 +41,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
||||
window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0];
|
||||
window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0];
|
||||
window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0];
|
||||
window.Store.GroupParticipants = window.mR.findModule('sendPromoteParticipants')[0];
|
||||
window.Store.GroupParticipants = window.mR.findModule('promoteParticipants')[1];
|
||||
window.Store.JoinInviteV4 = window.mR.findModule('sendJoinGroupViaInviteV4')[0];
|
||||
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
|
||||
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
|
||||
@@ -61,9 +60,9 @@ exports.ExposeStore = (moduleRaidStr) => {
|
||||
};
|
||||
|
||||
window.Store.GroupUtils = {
|
||||
...window.mR.findModule('sendCreateGroup')[0],
|
||||
...window.mR.findModule('sendSetGroupSubject')[0],
|
||||
...window.mR.findModule('markExited')[0]
|
||||
...window.mR.findModule('createGroup')[0],
|
||||
...window.mR.findModule('setGroupDescription')[0],
|
||||
...window.mR.findModule('sendExitGroup')[0]
|
||||
};
|
||||
|
||||
if (!window.Store.Chat._find) {
|
||||
@@ -356,6 +355,11 @@ exports.ExposeStore = (moduleRaidStr) => {
|
||||
} else {
|
||||
window.Store.MDBackend = true;
|
||||
}
|
||||
|
||||
const _features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0];
|
||||
if(_features) {
|
||||
window.Store.Features = _features.LegacyPhoneFeatures;
|
||||
}
|
||||
};
|
||||
|
||||
exports.LoadUtils = () => {
|
||||
|
||||
@@ -79,6 +79,7 @@ class InterfaceController {
|
||||
*/
|
||||
async getFeatures() {
|
||||
return await this.pupPage.evaluate(() => {
|
||||
if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
|
||||
return window.Store.Features.F;
|
||||
});
|
||||
}
|
||||
@@ -89,6 +90,7 @@ class InterfaceController {
|
||||
*/
|
||||
async checkFeatureStatus(feature) {
|
||||
return await this.pupPage.evaluate((feature) => {
|
||||
if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
|
||||
return window.Store.Features.supportsFeature(feature);
|
||||
}, feature);
|
||||
}
|
||||
@@ -99,6 +101,7 @@ class InterfaceController {
|
||||
*/
|
||||
async enableFeatures(features) {
|
||||
await this.pupPage.evaluate((features) => {
|
||||
if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
|
||||
for (const feature in features) {
|
||||
window.Store.Features.setFeature(features[feature], true);
|
||||
}
|
||||
@@ -111,6 +114,7 @@ class InterfaceController {
|
||||
*/
|
||||
async disableFeatures(features) {
|
||||
await this.pupPage.evaluate((features) => {
|
||||
if(!window.Store.Features) throw new Error('This version of Whatsapp Web does not support features');
|
||||
for (const feature in features) {
|
||||
window.Store.Features.setFeature(features[feature], false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user