From ba6ec7feab8490e6d226696eec3bb537a3559324 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Fri, 9 Oct 2020 02:28:54 -0400 Subject: [PATCH] fix: apply message serialization fix everywhere Moving this to a serializer function like done with a couple other models guarantees getting messages with pending acks won't fail elsewhere. It also sets it up so the we can add/remove properties on the Message model as needed in the future. related: 51a10285883a2dfb55a34565ebda936711cc02eb --- src/Client.js | 12 ++++++------ src/structures/Chat.js | 2 +- src/util/Injected.js | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Client.js b/src/Client.js index 6913aee..dc3d82b 100644 --- a/src/Client.js +++ b/src/Client.js @@ -355,12 +355,12 @@ class Client extends EventEmitter { }); await page.evaluate(() => { - window.Store.Msg.on('add', (msg) => { if (msg.isNewMsg) window.onAddMessageEvent(msg); }); - window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(msg); }); - window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(msg); }); - window.Store.Msg.on('change:ack', (msg, ack) => { window.onMessageAckEvent({...msg.serialize(), pendingAckUpdate: undefined}, ack); }); - window.Store.Msg.on('change:isUnsentMedia', (msg, unsent) => { if (msg.id.fromMe && !unsent) window.onMessageMediaUploadedEvent(msg); }); - window.Store.Msg.on('remove', (msg) => { if (msg.isNewMsg) window.onRemoveMessageEvent(msg); }); + window.Store.Msg.on('add', (msg) => { if (msg.isNewMsg) window.onAddMessageEvent(window.WWebJS.getMessageModel(msg)); }); + window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); }); + window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); }); + window.Store.Msg.on('change:ack', (msg,ack) => { window.onMessageAckEvent(window.WWebJS.getMessageModel(msg), ack); }); + window.Store.Msg.on('change:isUnsentMedia', (msg, unsent) => { if (msg.id.fromMe && !unsent) window.onMessageMediaUploadedEvent(window.WWebJS.getMessageModel(msg)); }); + window.Store.Msg.on('remove', (msg) => { if (msg.isNewMsg) window.onRemoveMessageEvent(window.WWebJS.getMessageModel(msg)); }); window.Store.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); }); window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); }); }); diff --git a/src/structures/Chat.js b/src/structures/Chat.js index 8a451db..70f6c8d 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -162,7 +162,7 @@ class Chat extends Base { } msgs.sort((a, b) => (a.t > b.t) ? 1 : -1); - return msgs.splice(msgs.length - limit).map(m => m.serialize()); + return msgs.splice(msgs.length - limit).map(m => window.WWebJS.getMessageModel(m)); }, this.id._serialized, searchOptions.limit); diff --git a/src/util/Injected.js b/src/util/Injected.js index bcff32c..484c873 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -166,6 +166,12 @@ exports.LoadUtils = () => { return mediaData; }; + window.WWebJS.getMessageModel = message => { + const msg = message.serialize(); + delete msg.pendingAckUpdate; + return msg; + }; + window.WWebJS.getChatModel = async chat => { let res = chat.serialize(); res.isGroup = chat.isGroup;