Skip to content

fix(group): fix GET /group/myall to handle WhatsApp LID JID format#34

Open
edilsonoliveirama wants to merge 2 commits intoEvolutionAPI:mainfrom
edilsonoliveirama:fix/group-myall-lid-jid
Open

fix(group): fix GET /group/myall to handle WhatsApp LID JID format#34
edilsonoliveirama wants to merge 2 commits intoEvolutionAPI:mainfrom
edilsonoliveirama:fix/group-myall-lid-jid

Conversation

@edilsonoliveirama
Copy link
Copy Markdown

@edilsonoliveirama edilsonoliveirama commented Apr 20, 2026

Problem / Problema

EN: GET /group/myall always returned an empty array even when the authenticated user owned or administered multiple groups.

PT: GET /group/myall sempre retornava um array vazio mesmo quando o usuário autenticado era dono ou administrador de vários grupos.


Root Cause / Causa Raiz

EN: WhatsApp migrated to LID (Linked ID) format for participant and owner JIDs in group metadata. The previous implementation compared group.OwnerJID.User and participant.JID.User against the client's phone number, but both fields now contain LID values (e.g. 216857898393848@lid) instead of phone numbers, so the comparison never matched.

PT: O WhatsApp migrou para o formato LID (Linked ID) nos JIDs de participantes e donos de grupos. A implementação anterior comparava group.OwnerJID.User e participant.JID.User com o número de telefone do cliente, mas esses campos agora contêm valores LID (ex.: 216857898393848@lid) e não números de telefone, então a comparação nunca era satisfeita.


Fix / Correção

EN:

  • Use group.OwnerPN.User — the OwnerPN field always holds the owner's phone-number JID even when OwnerJID is in LID format
  • Use participant.PhoneNumber.User — the PhoneNumber field always holds the participant's phone-number JID even when JID is in LID format
  • Extended logic to also include groups where the user is admin but not the creator
  • Removed the // TODO: not working comment from the route since the endpoint now works

PT:

  • Usa group.OwnerPN.User — o campo OwnerPN sempre contém o JID em formato de telefone do dono, mesmo quando OwnerJID está em formato LID
  • Usa participant.PhoneNumber.User — o campo PhoneNumber sempre contém o JID em formato de telefone do participante, mesmo quando JID está em formato LID
  • Lógica estendida para incluir também grupos onde o usuário é admin mas não o criador
  • Removido o comentário // TODO: not working da rota, pois o endpoint agora funciona

Validation / Validação

EN: Tested against a real WhatsApp account. Before the fix the endpoint returned {"data":[],"message":"success"}. After the fix it correctly returns all groups where the user is owner or admin.

PT: Testado com uma conta WhatsApp real. Antes da correção o endpoint retornava {"data":[],"message":"success"}. Após a correção retorna corretamente todos os grupos onde o usuário é dono ou administrador.

Summary by Sourcery

Fix the group listing service so GET /group/myall correctly returns all groups administered or owned by the authenticated user using WhatsApp’s updated JID/LID formats.

Bug Fixes:

  • Correct handling of WhatsApp LID-based JIDs in group metadata so ownership and admin status are detected via phone-number JIDs instead of LID JIDs.
  • Ensure GET /group/myall returns all groups where the user is owner or admin instead of always returning an empty list.

Enhancements:

  • Expand group detection logic to include groups where the user is an admin but not the creator.
  • Improve error logging message when fetching joined groups from the client.

Chores:

  • Remove the stale TODO comment marking the /group/myall endpoint as not working.

WhatsApp now uses LID (Linked ID) format for participant and owner JIDs
in groups. The previous implementation compared group.OwnerJID.User and
participant.JID.User against the client phone number, but both fields are
now LID values (e.g. 216857898393848@lid) rather than phone numbers,
causing the endpoint to always return an empty array.

Fix uses group.OwnerPN.User (phone-number JID of the owner, always
populated alongside the LID-based OwnerJID) and participant.PhoneNumber.User
(phone-number JID per participant) for the comparison. Also extends the
logic to include groups where the user is admin but not the creator.
Removes the TODO comment from the route since the endpoint now works.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 20, 2026

Reviewer's Guide

Adjusts GetMyGroups to correctly identify groups where the current user is owner or admin using phone-number JIDs instead of LID JIDs, and cleans up the corresponding /group/myall route comment.

Class diagram for updated GetMyGroups ownership and admin detection

classDiagram
    class groupService {
        +loggerWrapper LoggerWrapper
        +GetMyGroups(instance Instance) []GroupInfo
    }

    class LoggerWrapper {
        +GetLogger(instanceId string) Logger
    }

    class Logger {
        +LogError(format string, args interface) void
    }

    class Instance {
        +Id string
    }

    class WhatsAppClient {
        +Store WhatsAppStore
        +GetJoinedGroups(ctx Context) ([]*GroupInfo, error)
    }

    class WhatsAppStore {
        +ID JID
        +ID.ToNonAD() JID
    }

    class JID {
        +User string
    }

    class GroupInfo {
        +OwnerPN JID
        +OwnerJID JID
        +Participants []Participant
    }

    class Participant {
        +PhoneNumber JID
        +JID JID
        +IsAdmin bool
        +IsSuperAdmin bool
    }

    class Context

    groupService --> Instance : uses
    groupService --> LoggerWrapper : uses
    LoggerWrapper --> Logger : returns
    groupService --> WhatsAppClient : uses
    WhatsAppClient --> WhatsAppStore : has
    WhatsAppStore --> JID : has
    GroupInfo --> JID : uses
    GroupInfo --> Participant : has many
    Participant --> JID : uses
    groupService --> GroupInfo : returns
Loading

File-Level Changes

Change Details Files
Fix group ownership/admin detection in GetMyGroups to work with WhatsApp LID JID format and include admin-but-not-owner memberships.
  • Replace manual parsing of client.Store.ID into a JID with use of ToNonAD().User to obtain the phone-number user part
  • Iterate joined groups and select ones where OwnerPN.User or OwnerJID.User matches the current user
  • Fallback to scanning group participants and match via participant.PhoneNumber.User or participant.JID.User when PhoneNumber is empty
  • Require that matched participants are admins or super-admins before including the group
  • Rename adminGroups to myGroups and adjust return accordingly
  • Improve error log message when GetJoinedGroups fails
pkg/group/service/group_service.go
Clean up /group/myall route comment now that the endpoint works.
  • Remove the // TODO: not working comment from the /group/myall route registration while keeping the handler mapping unchanged
pkg/routes/routes.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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider preallocating myGroups with len(resp) as capacity to avoid repeated allocations when many groups are returned.
  • If OwnerPN, OwnerJID, or participant.PhoneNumber/participant.JID can be nil or zero-valued structs in some cases, it may be safer to add defensive checks before dereferencing .User to avoid potential panics.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider preallocating `myGroups` with `len(resp)` as capacity to avoid repeated allocations when many groups are returned.
- If `OwnerPN`, `OwnerJID`, or `participant.PhoneNumber`/`participant.JID` can be nil or zero-valued structs in some cases, it may be safer to add defensive checks before dereferencing `.User` to avoid potential panics.

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.

- Pre-allocate myGroups slice with len(resp) capacity to avoid repeated
  allocations when the user participates in many groups

- Guard all JID.User comparisons with myUser != "" to avoid false
  positives when the client's own JID is unexpectedly zero-valued;
  extract ownerPhone/ownerJID locals to reduce repeated field access

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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