Skip to content

Commit

Permalink
s/users/participants/ for calls.*
Browse files Browse the repository at this point in the history
  • Loading branch information
winston-stripe committed Sep 26, 2024
1 parent 240605c commit 03e3447
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
64 changes: 32 additions & 32 deletions calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ import (
)

type Call struct {
ID string `json:"id"`
Title string `json:"title"`
DateStart JSONTime `json:"date_start"`
DateEnd JSONTime `json:"date_end"`
ExternalUniqueID string `json:"external_unique_id"`
JoinURL string `json:"join_url"`
DesktopAppJoinURL string `json:"desktop_app_join_url"`
ExternalDisplayID string `json:"external_display_id"`
Users []CallUser `json:"users"`
Channels []string `json:"channels"`
}

// A thin user representation which has a SlackID, ExternalID, or both.
ID string `json:"id"`
Title string `json:"title"`
DateStart JSONTime `json:"date_start"`
DateEnd JSONTime `json:"date_end"`
ExternalUniqueID string `json:"external_unique_id"`
JoinURL string `json:"join_url"`
DesktopAppJoinURL string `json:"desktop_app_join_url"`
ExternalDisplayID string `json:"external_display_id"`
Participants []CallParticipant `json:"users"`
Channels []string `json:"channels"`
}

// CallParticipant is a thin user representation which has a SlackID, ExternalID, or both.
//
// See: https://api.slack.com/apis/calls#users
type CallUser struct {
type CallParticipant struct {
SlackID string `json:"slack_id,omitempty"`
ExternalID string `json:"external_id,omitempty"`
DisplayName string `json:"display_name,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
}

// Valid checks if the CallUser has a is valid with a SlackID or ExternalID or both.
func (u CallUser) Valid() bool {
func (u CallParticipant) Valid() bool {
return u.SlackID != "" || u.ExternalID != ""
}

Expand All @@ -44,7 +44,7 @@ type AddCallParameters struct {
DesktopAppJoinURL string
ExternalDisplayID string
DateStart JSONTime
Users []CallUser
Participants []CallParticipant
}

type UpdateCallParameters struct {
Expand Down Expand Up @@ -90,8 +90,8 @@ func (api *Client) AddCallContext(ctx context.Context, params AddCallParameters)
if params.Title != "" {
values.Set("title", params.Title)
}
if len(params.Users) > 0 {
data, err := json.Marshal(params.Users)
if len(params.Participants) > 0 {
data, err := json.Marshal(params.Participants)
if err != nil {
return Call{}, err
}
Expand Down Expand Up @@ -176,33 +176,33 @@ func (api *Client) EndCallContext(ctx context.Context, callID string, params End
return response.Err()
}

// CallAddUsers adds users to a Call.
func (api *Client) CallAddUsers(callID string, users []CallUser) error {
return api.CallAddUsersContext(context.Background(), callID, users)
// CallAddParticipants adds users to a Call.
func (api *Client) CallAddParticipants(callID string, participants []CallParticipant) error {
return api.CallAddParticipantsContext(context.Background(), callID, participants)
}

// CallAddUsersContext adds users to a Call.
func (api *Client) CallAddUsersContext(ctx context.Context, callID string, users []CallUser) error {
return api.setCallUsers(ctx, "calls.participants.add", callID, users)
// CallAddParticipantsContext adds users to a Call.
func (api *Client) CallAddParticipantsContext(ctx context.Context, callID string, participants []CallParticipant) error {
return api.setCallParticipants(ctx, "calls.participants.add", callID, participants)
}

// CallRemoveUsers removes users from a Call.
func (api *Client) CallRemoveUsers(callID string, users []CallUser) error {
return api.CallRemoveUsersContext(context.Background(), callID, users)
// CallRemoveParticipants removes users from a Call.
func (api *Client) CallRemoveParticipants(callID string, participants []CallParticipant) error {
return api.CallRemoveParticipantsContext(context.Background(), callID, participants)
}

// CallRemoveUsersContext removes users from a Call.
func (api *Client) CallRemoveUsersContext(ctx context.Context, callID string, users []CallUser) error {
return api.setCallUsers(ctx, "calls.participants.remove", callID, users)
// CallRemoveParticipantsContext removes users from a Call.
func (api *Client) CallRemoveParticipantsContext(ctx context.Context, callID string, participants []CallParticipant) error {
return api.setCallParticipants(ctx, "calls.participants.remove", callID, participants)
}

func (api *Client) setCallUsers(ctx context.Context, method, callID string, users []CallUser) error {
func (api *Client) setCallParticipants(ctx context.Context, method, callID string, participants []CallParticipant) error {
values := url.Values{
"token": {api.token},
"id": {callID},
}

data, err := json.Marshal(users)
data, err := json.Marshal(participants)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion calls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func addCallHandler(t *testing.T) http.HandlerFunc {
DesktopAppJoinURL: r.FormValue("desktop_app_join_url"),
}
callTestId += 1
json.Unmarshal([]byte(r.FormValue("users")), &call.Users)
json.Unmarshal([]byte(r.FormValue("users")), &call.Participants)
if start := r.FormValue("date_start"); start != "" {
dateStart, err := strconv.ParseInt(start, 10, 64)
require.NoError(t, err)
Expand Down

0 comments on commit 03e3447

Please sign in to comment.