Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete function for messages #3301

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ declare namespace WAWebJS {
/** Accept the Group V4 Invite in message */
acceptGroupV4Invite: () => Promise<{status: number}>,
/** 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 */
downloadMedia: () => Promise<MessageMedia>,
/** Returns the Chat this message was sent in */
Expand Down
25 changes: 14 additions & 11 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,23 +498,26 @@ class Message extends Base {
/**
* 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} [clearMedia = true] If true, any associated media will also be deleted from a device.
*/
async delete(everyone) {
await this.client.pupPage.evaluate(async (msgId, everyone) => {
async delete(everyone, clearMedia = true) {
alechkos marked this conversation as resolved.
Show resolved Hide resolved
await this.client.pupPage.evaluate(async (msgId, everyone, clearMedia) => {
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 (window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0')) {
return window.Store.Cmd.sendRevokeMsgs(chat, { list: [msg], type: 'message' }, { clearMedia: true });
} else {
return window.Store.Cmd.sendRevokeMsgs(chat, [msg], { clearMedia: true, type: msg.id.fromMe ? 'Sender' : 'Admin' });
}
return window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0')
? window.Store.Cmd.sendRevokeMsgs(chat, { list: [msg], type: 'message' }, { clearMedia: clearMedia })
: window.Store.Cmd.sendRevokeMsgs(chat, [msg], { clearMedia: true, type: msg.id.fromMe ? 'Sender' : 'Admin' });
}

return window.Store.Cmd.sendDeleteMsgs(chat, [msg], true);
}, this.id._serialized, everyone);
return window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.0')
? window.Store.Cmd.sendDeleteMsgs(chat, { list: [msg], type: 'message' }, clearMedia)
: window.Store.Cmd.sendDeleteMsgs(chat, [msg], clearMedia);
}, this.id._serialized, everyone, clearMedia);
}

/**
Expand Down
Loading