From 7e36cceaf0eea684bad3cc3bd1d706bf347d0de5 Mon Sep 17 00:00:00 2001 From: Shir Serlui <70711723+shirser121@users.noreply.github.com> Date: Mon, 7 Feb 2022 03:00:10 +0200 Subject: [PATCH] `extra` options can override other options when sending message (#1103) * Fix the option to use special options When we want to use some extra function we need to pass it into the options object, but because it inserted in the first line, the auto options reset some options (like 'type'). This is minor change that can help to add functionallity * Update Injected.js Put the special options in the end * Update Injected.js Fix , mistake * only `extra` options can override everything else Co-authored-by: Pedro Lopez --- src/Client.js | 2 +- src/util/Injected.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Client.js b/src/Client.js index 3d8de39..b09c2f3 100644 --- a/src/Client.js +++ b/src/Client.js @@ -540,7 +540,7 @@ class Client extends EventEmitter { quotedMessageId: options.quotedMessageId, parseVCards: options.parseVCards === false ? false : true, mentionedJidList: Array.isArray(options.mentions) ? options.mentions.map(contact => contact.id._serialized) : [], - ...options.extra + extraOptions: options.extra }; const sendSeen = typeof options.sendSeen === 'undefined' ? true : options.sendSeen; diff --git a/src/util/Injected.js b/src/util/Injected.js index 06b7049..fe0f9c8 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -153,7 +153,7 @@ exports.LoadUtils = () => { } } - let extraOptions = {}; + let buttonOptions = {}; if(options.buttons){ let caption; if(options.buttons.type === 'chat') { @@ -162,7 +162,7 @@ exports.LoadUtils = () => { }else{ caption = options.caption ? options.caption : ' '; //Caption can't be empty } - extraOptions = { + buttonOptions = { productHeaderImageRejected: false, isFromTemplate: false, isDynamicReplyButtonsMsg: true, @@ -175,12 +175,12 @@ exports.LoadUtils = () => { delete options.buttons; } + let listOptions = {}; if(options.list){ if(window.Store.Conn.platform === 'smba' || window.Store.Conn.platform === 'smbi'){ throw '[LT01] Whatsapp business can\'t send this yet'; } - extraOptions = { - ...extraOptions, + listOptions = { type: 'list', footer: options.list.footer, list: { @@ -190,7 +190,7 @@ exports.LoadUtils = () => { body: options.list.description }; delete options.list; - delete extraOptions.list.footer; + delete listOptions.list.footer; } const newMsgId = new window.Store.MsgKey({ @@ -199,6 +199,9 @@ exports.LoadUtils = () => { id: window.Store.genId(), }); + const extraOptions = options.extraOptions || {}; + delete options.extraOptions; + const message = { ...options, id: newMsgId, @@ -215,6 +218,8 @@ exports.LoadUtils = () => { ...attOptions, ...quotedMsgOptions, ...vcardOptions, + ...buttonOptions, + ...listOptions, ...extraOptions };