fix(group): fix GET /group/myall to handle WhatsApp LID JID format#34
Open
edilsonoliveirama wants to merge 2 commits intoEvolutionAPI:mainfrom
Open
fix(group): fix GET /group/myall to handle WhatsApp LID JID format#34edilsonoliveirama wants to merge 2 commits intoEvolutionAPI:mainfrom
edilsonoliveirama wants to merge 2 commits intoEvolutionAPI:mainfrom
Conversation
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>
Reviewer's GuideAdjusts 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 detectionclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider preallocating
myGroupswithlen(resp)as capacity to avoid repeated allocations when many groups are returned. - If
OwnerPN,OwnerJID, orparticipant.PhoneNumber/participant.JIDcan be nil or zero-valued structs in some cases, it may be safer to add defensive checks before dereferencing.Userto 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.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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Problema
EN:
GET /group/myallalways returned an empty array even when the authenticated user owned or administered multiple groups.PT:
GET /group/myallsempre 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.Userandparticipant.JID.Useragainst 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.Usereparticipant.JID.Usercom 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:
group.OwnerPN.User— theOwnerPNfield always holds the owner's phone-number JID even whenOwnerJIDis in LID formatparticipant.PhoneNumber.User— thePhoneNumberfield always holds the participant's phone-number JID even whenJIDis in LID format// TODO: not workingcomment from the route since the endpoint now worksPT:
group.OwnerPN.User— o campoOwnerPNsempre contém o JID em formato de telefone do dono, mesmo quandoOwnerJIDestá em formato LIDparticipant.PhoneNumber.User— o campoPhoneNumbersempre contém o JID em formato de telefone do participante, mesmo quandoJIDestá em formato LID// TODO: not workingda rota, pois o endpoint agora funcionaValidation / 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:
Enhancements:
Chores: