diff --git a/restapi.go b/restapi.go index b2d69598f..0b1789ac4 100644 --- a/restapi.go +++ b/restapi.go @@ -2711,11 +2711,22 @@ func (s *Session) ThreadMemberRemove(threadID, memberID string, options ...Reque return err } -// ThreadMember returns thread member object for the specified member of a thread -func (s *Session) ThreadMember(threadID, memberID string, options ...RequestOption) (member *ThreadMember, err error) { - endpoint := EndpointThreadMember(threadID, memberID) +// ThreadMember returns thread member object for the specified member of a thread. +// withMember : Whether to include a guild member object. +func (s *Session) ThreadMember(threadID, memberID string, withMember bool, options ...RequestOption) (member *ThreadMember, err error) { + uri := EndpointThreadMember(threadID, memberID) + + queryParams := url.Values{} + if withMember { + queryParams.Set("with_member", "true") + } + + if len(queryParams) > 0 { + uri += "?" + queryParams.Encode() + } + var body []byte - body, err = s.RequestWithBucketID("GET", endpoint, nil, endpoint, options...) + body, err = s.RequestWithBucketID("GET", uri, nil, uri, options...) if err != nil { return @@ -2726,9 +2737,29 @@ func (s *Session) ThreadMember(threadID, memberID string, options ...RequestOpti } // ThreadMembers returns all members of specified thread. -func (s *Session) ThreadMembers(threadID string, options ...RequestOption) (members []*ThreadMember, err error) { +// limit : Max number of thread members to return (1-100). Defaults to 100. +// afterID : Get thread members after this user ID. +// withMember : Whether to include a guild member object for each thread member. +func (s *Session) ThreadMembers(threadID string, limit int, withMember bool, afterID string, options ...RequestOption) (members []*ThreadMember, err error) { + uri := EndpointThreadMembers(threadID) + + queryParams := url.Values{} + if withMember { + queryParams.Set("with_member", "true") + } + if limit > 0 { + queryParams.Set("limit", strconv.Itoa(limit)) + } + if afterID != "" { + queryParams.Set("after", afterID) + } + + if len(queryParams) > 0 { + uri += "?" + queryParams.Encode() + } + var body []byte - body, err = s.RequestWithBucketID("GET", EndpointThreadMembers(threadID), nil, EndpointThreadMembers(threadID), options...) + body, err = s.RequestWithBucketID("GET", uri, nil, uri, options...) if err != nil { return diff --git a/structs.go b/structs.go index c0a26d4d8..0cfffca3c 100644 --- a/structs.go +++ b/structs.go @@ -531,6 +531,10 @@ type ThreadMember struct { JoinTimestamp time.Time `json:"join_timestamp"` // Any user-thread settings, currently only used for notifications Flags int `json:"flags"` + // Additional information about the user. + // NOTE: only present if the withMember parameter is set to true + // when calling Session.ThreadMembers or Session.ThreadMember. + Member *Member `json:"member,omitempty"` } // ThreadsList represents a list of threads alongisde with thread member objects for the current user.