Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion src/util/Injected/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,65 @@ exports.LoadUtils = () => {

if (options.waitUntilMsgSent) await sendMsgResultPromise;

return window
let sentMsg = window
.require('WAWebCollections')
.Msg.get(newMsgKey._serialized);

// The sent message can be indexed under a key built with the
// chat's sibling wid (lid <-> phone number); the random id part
// of the key does not depend on the wid, so look it up directly
// in the chat's own collection
if (!sentMsg) {
sentMsg = chat.msgs
.getModelsArray()
.find((m) => m.id.id === newMsgKey.id);
}

let altWid;
if (
!sentMsg &&
typeof chat.id?.isUser === 'function' &&
chat.id.isUser()
) {
altWid = window
.require('WAWebApiContact')
.getAlternateUserWid(chat.id);
if (altWid) {
const altMsgKey = new (window.require('WAWebMsgKey'))({
from: from,
to: altWid,
id: newId,
participant: participant,
selfDir: 'out',
});
sentMsg =
window
.require('WAWebCollections')
.Msg.get(altMsgKey._serialized) ||
window
.require('WAWebCollections')
.Chat.get(altWid)
?.msgs.getModelsArray()
.find((m) => m.id.id === newMsgKey.id);
}
}

// Keep a debug trail so clients can inspect why the sent message
// could not be found in the collections
if (!sentMsg) {
window.WWebJS.lastSendMessageDebug = {
newMsgKey: newMsgKey._serialized,
chatId: chat.id._serialized,
altWid: altWid ? altWid._serialized : null,
lastChatMsgKeys: chat.msgs
.getModelsArray()
.slice(-3)
.map((m) => m.id._serialized),
time: Date.now(),
};
}

return sentMsg;
};

window.WWebJS.editMessage = async (msg, content, options = {}) => {
Expand Down
Loading