attempted fix. Buttons are broken, lists are working

This commit is contained in:
purpshell
2022-08-10 13:54:27 +03:00
parent b1693b49e0
commit 81111faa05
2 changed files with 57 additions and 4 deletions

View File

@@ -73,7 +73,11 @@ class Buttons {
_format(buttons){
buttons = buttons.slice(0,3); // phone users can only see 3 buttons, so lets limit this
return buttons.map((btn) => {
return {'buttonId':btn.id ? String(btn.id) : Util.generateHash(6),'buttonText':{'displayText':btn.body},'type':1};
return {
buttonId: btn.id ? String(btn.id) : Util.generateHash(6),
buttonText: {displayText: btn.body},
type: 1
};
});
}

View File

@@ -70,6 +70,49 @@ exports.ExposeStore = (moduleRaidStr) => {
});
};
}
// Function to modify functions.
window.injectToFunction = (selector, callback) => {
const oldFunct = window.mR.findModule(selector.name)[selector.index][selector.property];
window.mR.findModule(selector.name)[selector.index][selector.property] = (...args) => callback(oldFunct, args);
};
window.injectToFunction({index: 0, name: 'createMsgProtobuf', property: 'createMsgProtobuf'}, (func, args) => {
const proto = func(...args);
if (proto.listMessage) {
proto.viewOnceMessage = {
message: {
listMessage: proto.listMessage
}
};
delete proto.listMessage;
}
if (proto.buttonsMessage) {
proto.viewOnceMessage = {
message: {
buttonsMessage: proto.buttonsMessage,
},
};
delete proto.buttonsMessage;
}
return proto;
});
window.injectToFunction({index: 0, name: 'typeAttributeFromProtobuf', property: 'typeAttributeFromProtobuf'}, (func, ...args) => {
const [proto] = args;
if (
proto.buttonsMessage?.headerType === 1 ||
proto.buttonsMessage?.headerType === 2
) {
return 'text';
}
if (proto.listMessage) {
return 'text';
}
return func(...args);
});
};
exports.LoadUtils = () => {
@@ -182,14 +225,20 @@ exports.LoadUtils = () => {
} else {
caption = options.caption ? options.caption : ' '; //Caption can't be empty
}
// TODO: fix this
const ButtonsCollection = window.mR.findModule('ButtonCollection')[0].ButtonCollection;
const collection = new ButtonsCollection();
const quickButtons = options.buttons.buttons.map(a => {
return {id: a.buttonId, displayText: a.buttonText.displayText, isState: true, selected: false, stale: false};
});
collection.add(quickButtons, {merge: true});
buttonOptions = {
productHeaderImageRejected: false,
isFromTemplate: false,
isDynamicReplyButtonsMsg: true,
title: options.buttons.title ? options.buttons.title : undefined,
footer: options.buttons.footer ? options.buttons.footer : undefined,
dynamicReplyButtons: options.buttons.buttons,
replyButtons: options.buttons.buttons,
replyButtons: collection,
caption: caption
};
delete options.buttons;