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

”Delete on my device" caused the message to be mistakenly deleted #2323

Open
ethan2cl opened this issue Sep 4, 2024 · 1 comment
Open
Labels
bug Something isn't working needs triage

Comments

@ethan2cl
Copy link

ethan2cl commented Sep 4, 2024

Environment

  • **WPPConnect version(s): 1.0.30
  • WA-JS version(s): 3.8.3
  • Node version: Node 20.11.1
  • WhatsApp version: 2.3000.1015891883-alpha
  • MultiDevice (BETA): yes

Description

Hello,
There are two ways to delete messages on mobile phones, "delete on everyone's device" and "delete on my device", as shown in the figure below.

WechatIMG138

There is a clear trigger event for 'delete on everyone's device', I just need to listen to the 'chat. msg.revoke' event, as shown in the following code. I can accurately listen to the 'delete on everyone's device' trigger on my phone, and then I can handle some things

try {
  if (!window['onRevokedMessage'].exposed) {
    WPP.on('chat.msg_revoke', (data) => {
      const eventData = {
        author: data.author,
        from: data.from,
        to: data.to,
        id: data.id,
        refId: data.refId,
      };
      window['onRevokedMessage'](eventData);
    });
    window['onRevokedMessage'].exposed = true;
  }
} catch (error) {
  console.error(error);
}

However, there is no specific event here to monitor the 'delete on my device' action. I tried some events and eventually found that clicking 'delete on my device' on my phone triggers a message deletion event. So, I added an event in the 【wapi/listeners】 directory to listen for the 'delete on my device' action, as follows.

export function addOnMessageRemove() {
  window.WAPI.onMessageRemove = (callback) => {
    WPP.whatsapp.MsgStore.on('remove', (msgModel) => {
      const msg = window.WAPI._serializeMessageObj(msgModel);
      callback(msg);
    });
    return true;
  };
}

This can indeed detect the action of 'delete on my device', but there will be a serious issue. When I click on the logout disconnect link on my phone, it triggers many removal events for messages, but in reality, these messages are not deleted. It looks like the DOM is being re rendered due to the browser being closed, which leads to the accidental triggering of many removal events.

WechatIMG140

Is there a clear event that can point to 'delete on my device'? Or can you help me solve this problem? Not very grateful.
I have tried delaying execution, but it still triggers incorrectly in the end

@ethan2cl ethan2cl added bug Something isn't working needs triage labels Sep 4, 2024
@ethan2cl
Copy link
Author

help.....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant