Skip to content
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
41 changes: 28 additions & 13 deletions pkg/group/service/group_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,26 +415,41 @@ func (g *groupService) GetMyGroups(instance *instance_model.Instance) ([]types.G

resp, err := client.GetJoinedGroups(context.Background())
if err != nil {
g.loggerWrapper.GetLogger(instance.Id).LogError("[%s] error create group: %v", instance.Id, err)
g.loggerWrapper.GetLogger(instance.Id).LogError("[%s] error getting joined groups: %v", instance.Id, err)
return nil, err
}

var jid string = client.Store.ID.String()
var jidClear = strings.Split(jid, ".")[0]
jidOfAdmin, ok := utils.ParseJID(jidClear)
if !ok {
g.loggerWrapper.GetLogger(instance.Id).LogError("[%s] Error validating message fields", instance.Id)
return nil, errors.New("invalid phone number")
}
var adminGroups []types.GroupInfo
// ToNonAD removes the device suffix (e.g. ":5") so the phone number
// can be compared against OwnerPN and participant PhoneNumber fields.
// WhatsApp now uses LID format for JIDs, so we must compare via the
// phone number fields (OwnerPN / PhoneNumber) instead of OwnerJID / JID.
myUser := client.Store.ID.ToNonAD().User

myGroups := make([]types.GroupInfo, 0, len(resp))
for _, group := range resp {
if group.OwnerJID == jidOfAdmin {
adminGroups = append(adminGroups, *group)
_ = adminGroups
// Primary check: OwnerPN holds the owner's phone-number JID even when
// the main OwnerJID is in LID format. Guard myUser != "" to avoid
// false positives when the client JID is unexpectedly zero-valued.
ownerPhone := group.OwnerPN.User
ownerJID := group.OwnerJID.User
if myUser != "" && (ownerPhone == myUser || ownerJID == myUser) {
myGroups = append(myGroups, *group)
continue
}
// Fallback: scan participants; PhoneNumber is always phone-number JID.
for _, participant := range group.Participants {
participantPhone := participant.PhoneNumber.User
if participantPhone == "" {
participantPhone = participant.JID.User
}
if myUser != "" && participantPhone == myUser && (participant.IsAdmin || participant.IsSuperAdmin) {
myGroups = append(myGroups, *group)
break
}
}
}

return adminGroups, nil
return myGroups, nil
}

func (g *groupService) JoinGroupLink(data *JoinGroupStruct, instance *instance_model.Instance) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (r *Routes) AssignRoutes(eng *gin.Engine) {
routes.POST("/description", r.jidValidationMiddleware.ValidateNumberField(), r.groupHandler.SetGroupDescription)
routes.POST("/create", r.jidValidationMiddleware.ValidateMultipleNumbers("participants"), r.groupHandler.CreateGroup)
routes.POST("/participant", r.jidValidationMiddleware.ValidateJIDFields("number", "participants"), r.groupHandler.UpdateParticipant)
routes.GET("/myall", r.groupHandler.GetMyGroups) // TODO: not working
routes.GET("/myall", r.groupHandler.GetMyGroups)
routes.POST("/join", r.groupHandler.JoinGroupLink)
routes.POST("/leave", r.jidValidationMiddleware.ValidateNumberField(), r.groupHandler.LeaveGroup)
}
Expand Down