mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 12:39:20 +00:00
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: 51a1028588
This commit is contained in:
@@ -355,12 +355,12 @@ class Client extends EventEmitter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
window.Store.Msg.on('add', (msg) => { if (msg.isNewMsg) window.onAddMessageEvent(msg); });
|
window.Store.Msg.on('add', (msg) => { if (msg.isNewMsg) window.onAddMessageEvent(window.WWebJS.getMessageModel(msg)); });
|
||||||
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(msg); });
|
window.Store.Msg.on('change', (msg) => { window.onChangeMessageEvent(window.WWebJS.getMessageModel(msg)); });
|
||||||
window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(msg); });
|
window.Store.Msg.on('change:type', (msg) => { window.onChangeMessageTypeEvent(window.WWebJS.getMessageModel(msg)); });
|
||||||
window.Store.Msg.on('change:ack', (msg, ack) => { window.onMessageAckEvent({...msg.serialize(), pendingAckUpdate: undefined}, ack); });
|
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(msg); });
|
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(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.AppState.on('change:state', (_AppState, state) => { window.onAppStateChangedEvent(state); });
|
||||||
window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); });
|
window.Store.Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ class Chat extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
|
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);
|
}, this.id._serialized, searchOptions.limit);
|
||||||
|
|
||||||
|
|||||||
@@ -166,6 +166,12 @@ exports.LoadUtils = () => {
|
|||||||
return mediaData;
|
return mediaData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.WWebJS.getMessageModel = message => {
|
||||||
|
const msg = message.serialize();
|
||||||
|
delete msg.pendingAckUpdate;
|
||||||
|
return msg;
|
||||||
|
};
|
||||||
|
|
||||||
window.WWebJS.getChatModel = async chat => {
|
window.WWebJS.getChatModel = async chat => {
|
||||||
let res = chat.serialize();
|
let res = chat.serialize();
|
||||||
res.isGroup = chat.isGroup;
|
res.isGroup = chat.isGroup;
|
||||||
|
|||||||
Reference in New Issue
Block a user