fix: fix 'delete' method for messages (#3301)
This commit is contained in:
parent
0d040611e7
commit
bad202d2bc
2 changed files with 15 additions and 12 deletions
2
index.d.ts
vendored
2
index.d.ts
vendored
|
|
@ -960,7 +960,7 @@ declare namespace WAWebJS {
|
||||||
/** Accept the Group V4 Invite in message */
|
/** Accept the Group V4 Invite in message */
|
||||||
acceptGroupV4Invite: () => Promise<{status: number}>,
|
acceptGroupV4Invite: () => Promise<{status: number}>,
|
||||||
/** Deletes the message from the chat */
|
/** Deletes the message from the chat */
|
||||||
delete: (everyone?: boolean) => Promise<void>,
|
delete: (everyone?: boolean, clearMedia?: boolean) => Promise<void>,
|
||||||
/** Downloads and returns the attached message media */
|
/** Downloads and returns the attached message media */
|
||||||
downloadMedia: () => Promise<MessageMedia>,
|
downloadMedia: () => Promise<MessageMedia>,
|
||||||
/** Returns the Chat this message was sent in */
|
/** Returns the Chat this message was sent in */
|
||||||
|
|
|
||||||
|
|
@ -498,23 +498,26 @@ class Message extends Base {
|
||||||
/**
|
/**
|
||||||
* Deletes a message from the chat
|
* Deletes a message from the chat
|
||||||
* @param {?boolean} everyone If true and the message is sent by the current user or the user is an admin, will delete it for everyone in the chat.
|
* @param {?boolean} everyone If true and the message is sent by the current user or the user is an admin, will delete it for everyone in the chat.
|
||||||
|
* @param {?boolean} [clearMedia = true] If true, any associated media will also be deleted from a device.
|
||||||
*/
|
*/
|
||||||
async delete(everyone) {
|
async delete(everyone, clearMedia = true) {
|
||||||
await this.client.pupPage.evaluate(async (msgId, everyone) => {
|
await this.client.pupPage.evaluate(async (msgId, everyone, clearMedia) => {
|
||||||
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
const msg = window.Store.Msg.get(msgId) || (await window.Store.Msg.getMessagesById([msgId]))?.messages?.[0];
|
||||||
let chat = await window.Store.Chat.find(msg.id.remote);
|
const chat = window.Store.Chat.get(msg.id.remote) || (await window.Store.Chat.find(msg.id.remote));
|
||||||
|
|
||||||
|
const canRevoke =
|
||||||
|
window.Store.MsgActionChecks.canSenderRevokeMsg(msg) || window.Store.MsgActionChecks.canAdminRevokeMsg(msg);
|
||||||
|
|
||||||
const canRevoke = window.Store.MsgActionChecks.canSenderRevokeMsg(msg) || window.Store.MsgActionChecks.canAdminRevokeMsg(msg);
|
|
||||||
if (everyone && canRevoke) {
|
if (everyone && canRevoke) {
|
||||||
if (window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0')) {
|
return window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0')
|
||||||
return window.Store.Cmd.sendRevokeMsgs(chat, { list: [msg], type: 'message' }, { clearMedia: true });
|
? window.Store.Cmd.sendRevokeMsgs(chat, { list: [msg], type: 'message' }, { clearMedia: clearMedia })
|
||||||
} else {
|
: window.Store.Cmd.sendRevokeMsgs(chat, [msg], { clearMedia: true, type: msg.id.fromMe ? 'Sender' : 'Admin' });
|
||||||
return window.Store.Cmd.sendRevokeMsgs(chat, [msg], { clearMedia: true, type: msg.id.fromMe ? 'Sender' : 'Admin' });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return window.Store.Cmd.sendDeleteMsgs(chat, [msg], true);
|
return window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0')
|
||||||
}, this.id._serialized, everyone);
|
? window.Store.Cmd.sendDeleteMsgs(chat, { list: [msg], type: 'message' }, clearMedia)
|
||||||
|
: window.Store.Cmd.sendDeleteMsgs(chat, [msg], clearMedia);
|
||||||
|
}, this.id._serialized, everyone, clearMedia);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue