From 81111faa058d8e715285a2bfc9a42636074f7c3d Mon Sep 17 00:00:00 2001 From: purpshell Date: Wed, 10 Aug 2022 13:54:27 +0300 Subject: [PATCH] attempted fix. Buttons are broken, lists are working --- src/structures/Buttons.js | 6 ++++- src/util/Injected.js | 55 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index 66b7cdf..16e6cb4 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -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 + }; }); } diff --git a/src/util/Injected.js b/src/util/Injected.js index a5eeae3..0e0b23f 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -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;