ESLINT + Clean

This commit is contained in:
Rajeh Taher
2023-02-19 15:16:29 +02:00
committed by cheveguerra
parent ec0ee3c243
commit ceabbd5177
2 changed files with 43 additions and 50 deletions

View File

@@ -17,6 +17,7 @@ const MessageMedia = require('./MessageMedia');
* @property {{displayText: string, url: string}=} urlButton * @property {{displayText: string, url: string}=} urlButton
* @property {{displayText: string, phoneNumber: string}=} callButton * @property {{displayText: string, phoneNumber: string}=} callButton
* @property {{displayText: string, id: string}=} quickReplyButton * @property {{displayText: string, id: string}=} quickReplyButton
* @property {{regularButtons: {text: string, id: string}}=} regularButtons
*/ */
/** /**
@@ -28,8 +29,9 @@ class Buttons {
* @param {ButtonSpec[]} buttons - See {@link ButtonSpec} * @param {ButtonSpec[]} buttons - See {@link ButtonSpec}
* @param {string?} title * @param {string?} title
* @param {string?} footer * @param {string?} footer
* @param {boolean?} templateOverride
*/ */
constructor(body, buttons, title, footer) { constructor(body, buttons, title, footer, templateOverride) {
/** /**
* Message body * Message body
* @type {string|MessageMedia} * @type {string|MessageMedia}
@@ -59,7 +61,7 @@ class Buttons {
* buttons of message * buttons of message
* @type {FormattedButtonSpec[]} * @type {FormattedButtonSpec[]}
*/ */
this.buttons = this._format(buttons); this.buttons = this._format(buttons, templateOverride);
if(!this.buttons.length){ throw '[BT01] No buttons';} if(!this.buttons.length){ throw '[BT01] No buttons';}
} }
@@ -69,7 +71,7 @@ class Buttons {
* @param {ButtonSpec[]} buttons * @param {ButtonSpec[]} buttons
* @returns {FormattedButtonSpec[]} * @returns {FormattedButtonSpec[]}
*/ */
_format(buttons){ _format(buttons, templateOverride){
// Limit the buttons (max 3 of regular and 3 of special buttons) 5 buttons total at the same time // 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); const templateButtons = buttons.filter(button => button.url || button.number);
const regularButtons = buttons.filter(button => !button.url && !button.number); const regularButtons = buttons.filter(button => !button.url && !button.number);
@@ -78,7 +80,7 @@ class Buttons {
return buttons.map((button, index) => { return buttons.map((button, index) => {
if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)'; if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)';
if (button.number) { if (button.number) {
console.log("[WARNING] THIS FEATURE (CALL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test") console.log('[WARNING] THIS FEATURE (CALL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test');
return { return {
index, index,
callButton: { callButton: {
@@ -87,7 +89,7 @@ class Buttons {
} }
}; };
} else if (button.url) { } else if (button.url) {
console.log("[WARNING] THIS FEATURE (URL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test") console.log('[WARNING] THIS FEATURE (URL BUTTONS) IS UNSTABLE AND IS NOT TESTED OR EXPECTED TO WORK ON ALL PLATFORMS. Help test this feature with us on https://github.com/wwebjs/buttons-test');
return { return {
index, index,
urlButton: { urlButton: {
@@ -96,13 +98,21 @@ class Buttons {
} }
}; };
} else { } else {
return { if (templateOverride) return {
index, index,
quickReplyButton: { quickReplyButton: {
displayText: button.body, displayText: button.body,
id: button.id || `${index}` id: button.id || `${index}`
} }
}; };
return {
index,
regularButtons: {
id: button.id,
text: button.body
}
}
} }
}); });

View File

@@ -251,6 +251,20 @@ exports.ExposeStore = (moduleRaidStr) => {
property: 'typeAttributeFromProtobuf' property: 'typeAttributeFromProtobuf'
}, (func, args) => { }, (func, args) => {
const [proto] = args; const [proto] = args;
if (proto.ephemeralMessage) {
const { message } = proto.ephemeralMessage;
return message ? func(message) : 'text';
}
if (proto.deviceSentMessage) {
const { message } = proto.deviceSentMessage;
return message ? func(message) : 'text';
}
if (proto.viewOnceMessage) {
const { message } = proto.viewOnceMessage;
return message ? func(message) : 'text';
}
if (proto.templateMessage?.hydratedTemplate) { if (proto.templateMessage?.hydratedTemplate) {
const keys = Object.keys(proto.templateMessage?.hydratedTemplate); const keys = Object.keys(proto.templateMessage?.hydratedTemplate);
const messagePart = [ const messagePart = [
@@ -275,59 +289,28 @@ exports.ExposeStore = (moduleRaidStr) => {
return func(...args); return func(...args);
}); });
window.injectToFunction({
index: 0,
name: 'typeAttributeFromProtobuf',
property: 'typeAttributeFromProtobuf'
}, (func, args) => {
const [proto] = args;
if (proto.ephemeralMessage) {
const { message } = proto.ephemeralMessage;
return message ? func(message) : 'text';
}
if (proto.deviceSentMessage) {
const { message } = proto.deviceSentMessage;
return message ? func(message) : 'text';
}
if (proto.viewOnceMessage) {
const { message } = proto.viewOnceMessage;
return message ? func(message) : 'text';
}
return func(...args);
});
window.injectToFunction({ window.injectToFunction({
index: 0, index: 0,
name: 'mediaTypeFromProtobuf', name: 'mediaTypeFromProtobuf',
property: 'mediaTypeFromProtobuf' property: 'mediaTypeFromProtobuf'
}, (func, args) => { }, (func, args) => {
const [proto] = args; const [proto] = args;
if (proto.deviceSentMessage) {
const { message } = proto.deviceSentMessage;
return message ? func(message) : null;
}
if (proto.ephemeralMessage) {
const { message } = proto.ephemeralMessage;
return message ? func(message) : null;
}
if (proto.viewOnceMessage) {
const { message } = proto.viewOnceMessage;
return message ? func(message) : null;
}
if (proto.templateMessage?.hydratedTemplate) { if (proto.templateMessage?.hydratedTemplate) {
return func(proto.templateMessage.hydratedTemplate); return func(proto.templateMessage.hydratedTemplate);
} }
return func(...args);
});
window.injectToFunction({
index: 0,
name: 'mediaTypeFromProtobuf',
property: 'mediaTypeFromProtobuf'
}, (func, args) => {
const [proto] = args;
if (proto.deviceSentMessage) {
const { message } = proto.deviceSentMessage;
return message ? func(message) : null;
}
if (proto.ephemeralMessage) {
const { message } = proto.ephemeralMessage;
return message ? func(message) : null;
}
if (proto.viewOnceMessage) {
const { message } = proto.viewOnceMessage;
return message ? func(message) : null;
}
return func(...args); return func(...args);
}); });