feat: Edit message (#2254)

* function edit message
This commit is contained in:
tofers 2023-06-15 18:49:38 +03:00 • committed by GitHub
commit 8e8d0c9b3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 138 additions and 3 deletions

View file

@ -31,6 +31,7 @@ exports.ExposeStore = (moduleRaidStr) => {
window.Store.SendClear = window.mR.findModule('sendClear')[0];
window.Store.SendDelete = window.mR.findModule('sendDelete')[0];
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0];
window.Store.EditMessage = window.mR.findModule('addAndSendMessageEdit')[0];
window.Store.SendSeen = window.mR.findModule('sendSeen')[0];
window.Store.User = window.mR.findModule('getMaybeMeUser')[0];
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default;
@ -289,6 +290,40 @@ exports.LoadUtils = () => {
await window.Store.SendMessage.addAndSendMsgToChat(chat, message);
return window.Store.Msg.get(newMsgId._serialized);
};
window.WWebJS.editMessage = async (msg, content, options = {}) => {
const extraOptions = options.extraOptions || {};
delete options.extraOptions;
if (options.mentionedJidList) {
options.mentionedJidList = options.mentionedJidList.map(cId => window.Store.Contact.get(cId).id);
}
if (options.linkPreview) {
options.linkPreview = null;
// Not supported yet by WhatsApp Web on MD
if(!window.Store.MDBackend) {
const link = window.Store.Validators.findLink(content);
if (link) {
const preview = await window.Store.Wap.queryLinkPreview(link.url);
preview.preview = true;
preview.subtype = 'url';
options = { ...options, ...preview };
}
}
}
const internalOptions = {
...options,
...extraOptions
};
await window.Store.EditMessage.sendMessageEdit(msg, content, internalOptions);
return window.Store.Msg.get(msg.id._serialized);
};
window.WWebJS.toStickerData = async (mediaInfo) => {
if (mediaInfo.mimetype == 'image/webp') return mediaInfo;