Skip to content

Commit

Permalink
Send members conditionally for query members (#94)
Browse files Browse the repository at this point in the history
Members aren't always needed. Additionally, reserved fields can't be submitted.
  • Loading branch information
ferhatelmas authored Sep 23, 2020
1 parent 00382e0 commit 746919e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,16 @@ func (ch *Channel) QueryMembers(q *QueryOption, sorters ...*SortOption) ([]*Chan
"sort": sorters,
}

if len(ch.Members) > 0 {
qp["members"] = ch.Members
if ch.ID == "" && len(ch.Members) > 0 {
members := make([]*ChannelMember, 0, len(ch.Members))
for _, m := range ch.Members {
if m.User != nil {
members = append(members, &ChannelMember{UserID: m.User.ID})
} else {
members = append(members, &ChannelMember{UserID: m.UserID})
}
}
qp["members"] = members
}

data, err := json.Marshal(&qp)
Expand Down

0 comments on commit 746919e

Please sign in to comment.