Merge branch 'fix-buttons-list' of https://github.com/pedroslopez/whatsapp-web.js into fix-buttons-list

This commit is contained in:
purpshell
2022-08-23 20:47:22 +03:00
8 changed files with 136 additions and 10 deletions

View File

@@ -989,7 +989,13 @@ class Client extends EventEmitter {
*/
async getCommonGroups(contactId) {
const commonGroups = await this.pupPage.evaluate(async (contactId) => {
const contact = window.Store.Contact.get(contactId);
let contact = window.Store.Contact.get(contactId);
if (!contact) {
const wid = window.Store.WidFactory.createUserWid(contactId);
const chatConstructor = window.Store.Contact.getModelsArray().find(c=>!c.isGroup).constructor;
contact = new chatConstructor({id: wid});
}
if (contact.commonGroups) {
return contact.commonGroups.serialize();
}

View File

@@ -178,9 +178,9 @@ class RemoteAuth extends BaseAuthStrategy {
await fs.promises.rm(dirElement, {
recursive: true,
force: true
});
}).catch(() => {});
} else {
await fs.promises.unlink(dirElement);
await fs.promises.unlink(dirElement).catch(() => {});
}
}
}

View File

@@ -70,10 +70,10 @@ class Buttons {
* @returns {FormattedButtonSpec[]}
*/
_format(buttons){
// Limit the buttons (max 3 of regular and 2 of special buttons)
const templateButtons = buttons.filter(button => button.url || button.number).slice(0,2);
// Limit the buttons (max 3 of regular and 3 of special buttons) 5 buttons total at the same time
const templateButtons = buttons.filter(button => button.url || button.number).slice(0,3);
const regularButtons = buttons.filter(button => !button.url && !button.number).slice(0,3);
buttons = templateButtons.concat(regularButtons);
buttons = templateButtons.concat(regularButtons).slice(0,5);
return buttons.map((button, index) => {
if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)';
@@ -100,7 +100,7 @@ class Buttons {
index,
quickReplyButton: {
displayText: button.body,
id: button.id || index
id: button.id || `${index}`
}
};
}

View File

@@ -222,6 +222,14 @@ exports.ExposeStore = (moduleRaidStr) => {
};
delete proto.templateMessage;
}
if (proto.buttonsMessage) {
proto.viewOnceMessage = {
message: {
buttonsMessage: proto.buttonsMessage,
},
};
delete proto.buttonsMessage;
}
if (proto.listMessage) {
proto.viewOnceMessage = {
message: {
@@ -348,7 +356,6 @@ exports.LoadUtils = () => {
window.WWebJS.prepareMessageButtons = (buttonsOptions) => {
const returnObject = {};
if (!buttonsOptions.buttons) {
return returnObject;
}
@@ -397,7 +404,7 @@ exports.LoadUtils = () => {
returnObject.isDynamicReplyButtonsMsg = true;
returnObject.dynamicReplyButtons = buttonsOptions.buttons.map((button, index) => ({
buttonId: button.index || `${index}`,
buttonId: button.quickReplyButton.id.toString() || `${index}`,
buttonText: {displayText: button.quickReplyButton?.displayText},
type: 1,
}));