Skip to content

fix: canonicalize JIDs in GetAvatar, DeleteMessageEveryone and EditMessage - #163

Open
FlavioPulli wants to merge 1 commit into
evolution-foundation:developfrom
FlavioPulli:fix/canonical-jid-avatar-revoke-edit-develop
Open

fix: canonicalize JIDs in GetAvatar, DeleteMessageEveryone and EditMessage#163
FlavioPulli wants to merge 1 commit into
evolution-foundation:developfrom
FlavioPulli:fix/canonical-jid-avatar-revoke-edit-develop

Conversation

@FlavioPulli

@FlavioPulli FlavioPulli commented Aug 4, 2026

Copy link
Copy Markdown

CreateJID intentionally prefixes phone numbers with + (+55...@s.whatsapp.net). Message sending tolerates it because whatsmeow normalizes the JID during usync/device resolution, and the raw-node paths (typing, receipts, reactions) already strip it via utils.CanonicalJID — but three paths still use the prefixed JID as-is:

  • GetAvatar: GetProfilePictureInfo runs a usync IQ against the JID, querying a nonexistent +... user and timing out after ~75s (info query timed out) instead of returning the picture.
  • DeleteMessageEveryone / EditMessage: the JID lands inside the protocolMessage Key of the revoke/edit, so receiving devices look up a chat named +... that doesn't exist and silently ignore the operation.

Apply utils.CanonicalJID right after ParseJID in all three, matching what the send/receipt paths already do. No-op for group and @lid JIDs (their CreateJID paths never add the prefix).


Retargeted to develop (replaces #130), as requested by @iagocotta in #128 (comment).

Note that main and develop have no common ancestor — the GitHub API refuses to compare them (No common ancestor between main and develop) — so the base branch of the original PR could not simply be edited. This branch was created from develop and the commit cherry-picked onto it.

utils.CanonicalJID does not exist on develop (it is only on main), so the 3-line helper is included in this PR.

Verified on this branch: go build ./... and go vet ./... both pass.

Summary by Sourcery

Canonicalize JIDs in user and message operations to ensure WhatsApp lookups and protocol messages target the correct chats.

Bug Fixes:

  • Normalize recipient JIDs in DeleteMessageEveryone so revoke operations are applied instead of being silently ignored by recipients.
  • Normalize recipient JIDs in EditMessage so edits are delivered correctly rather than being ignored due to mismatched chat identifiers.
  • Canonicalize JIDs in GetAvatar so profile picture lookups query existing users and no longer time out.

Enhancements:

  • Introduce a shared CanonicalJID helper to standardize JID normalization across the codebase.

…ssage

CreateJID intentionally prefixes phone numbers with "+"
(+55...@s.whatsapp.net). Message sending tolerates it because whatsmeow
normalizes the JID during usync/device resolution, and the raw-node
paths (typing, receipts, reactions) already strip it via
utils.CanonicalJID — but three paths still use the prefixed JID as-is:

- GetAvatar: GetProfilePictureInfo runs a usync IQ against the JID,
  querying a nonexistent "+..." user and timing out after ~75s
  ("info query timed out") instead of returning the picture.
- DeleteMessageEveryone / EditMessage: the JID lands inside the
  protocolMessage Key of the revoke/edit, so receiving devices look up
  a chat named "+..." that doesn't exist and silently ignore the
  operation.

Apply utils.CanonicalJID right after ParseJID in all three, matching
what the send/receipt paths already do. No-op for group and @lid JIDs
(their CreateJID paths never add the prefix).
@sourcery-ai

sourcery-ai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR ensures phone-number-based JIDs are canonicalized (leading '+' stripped) before use in avatar lookup and message revoke/edit flows, by introducing a small CanonicalJID helper and applying it in the relevant service methods.

Sequence diagram for canonicalized JID in GetAvatar flow

sequenceDiagram
    actor ClientApp
    participant UserService as userService
    participant Utils as utils
    participant WhatsAppClient as client

    ClientApp->>UserService: GetAvatar(data, instance)
    UserService->>UserService: ParseJID(data.Phone)
    UserService->>Utils: CanonicalJID(jid)
    Utils-->>UserService: canonicalJID
    UserService->>WhatsAppClient: GetProfilePictureInfo(canonicalJID, data.Preview)
    WhatsAppClient-->>UserService: ProfilePictureInfo
    UserService-->>ClientApp: Avatar response
Loading

Sequence diagram for canonicalized JID in DeleteMessageEveryone/EditMessage flows

sequenceDiagram
    actor ClientApp
    participant MessageService as messageService
    participant Utils as utils
    participant WhatsAppClient as client

    ClientApp->>MessageService: DeleteMessageEveryone(data, instance)
    MessageService->>MessageService: ParseJID(data.Phone)
    MessageService->>Utils: CanonicalJID(recipient)
    Utils-->>MessageService: canonicalRecipient
    MessageService->>WhatsAppClient: SendMessage(protocolMessage with canonicalRecipient)
    WhatsAppClient-->>MessageService: revoke response

    ClientApp->>MessageService: EditMessage(data, instance)
    MessageService->>MessageService: ParseJID(data.Phone)
    MessageService->>Utils: CanonicalJID(recipient)
    Utils-->>MessageService: canonicalRecipient
    MessageService->>WhatsAppClient: SendMessage(protocolMessage with canonicalRecipient)
    WhatsAppClient-->>MessageService: edit response
Loading

File-Level Changes

Change Details Files
Canonicalize phone-number JIDs before DeleteMessageEveryone and EditMessage operations so revokes/edits are correctly delivered.
  • After ParseJID/validation, normalize the recipient JID via utils.CanonicalJID before logging and sending revoke/edit protocol messages.
  • Add inline comments documenting that the JID ends up in protocolMessage.Key and why the '+' prefix causes recipients to ignore the operation.
pkg/message/service/message_service.go
Introduce a CanonicalJID helper on develop to normalize JIDs consistently with main.
  • Add utils.CanonicalJID that strips a leading '+' from JID.User using strings.TrimPrefix.
  • Document in the helper comment that it exists to normalize client-supplied JIDs for lookups/comparisons.
pkg/utils/utils.go
Canonicalize JIDs before avatar retrieval to avoid usync queries against nonexistent '+...' users.
  • After ParseJID/validation in GetAvatar, normalize the jid via utils.CanonicalJID before calling GetProfilePictureInfo.
  • Add inline comments explaining that GetProfilePictureInfo queries the JID as-is and the '+' prefix leads to timeouts against nonexistent users.
pkg/user/service/user_service.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant