diff options
Diffstat (limited to 'vendor/github.com/nlopes/slack/groups.go')
-rw-r--r-- | vendor/github.com/nlopes/slack/groups.go | 120 |
1 files changed, 101 insertions, 19 deletions
diff --git a/vendor/github.com/nlopes/slack/groups.go b/vendor/github.com/nlopes/slack/groups.go index ec4a3b65..444666dd 100644 --- a/vendor/github.com/nlopes/slack/groups.go +++ b/vendor/github.com/nlopes/slack/groups.go @@ -1,6 +1,7 @@ package slack import ( + "context" "errors" "net/url" "strconv" @@ -27,9 +28,9 @@ type groupResponseFull struct { SlackResponse } -func groupRequest(path string, values url.Values, debug bool) (*groupResponseFull, error) { +func groupRequest(ctx context.Context, path string, values url.Values, debug bool) (*groupResponseFull, error) { response := &groupResponseFull{} - err := post(path, values, response, debug) + err := post(ctx, path, values, response, debug) if err != nil { return nil, err } @@ -41,11 +42,16 @@ func groupRequest(path string, values url.Values, debug bool) (*groupResponseFul // ArchiveGroup archives a private group func (api *Client) ArchiveGroup(group string) error { + return api.ArchiveGroupContext(context.Background(), group) +} + +// ArchiveGroup archives a private group +func (api *Client) ArchiveGroupContext(ctx context.Context, group string) error { values := url.Values{ "token": {api.config.token}, "channel": {group}, } - _, err := groupRequest("groups.archive", values, api.debug) + _, err := groupRequest(ctx, "groups.archive", values, api.debug) if err != nil { return err } @@ -54,11 +60,16 @@ func (api *Client) ArchiveGroup(group string) error { // UnarchiveGroup unarchives a private group func (api *Client) UnarchiveGroup(group string) error { + return api.UnarchiveGroupContext(context.Background(), group) +} + +// UnarchiveGroup unarchives a private group +func (api *Client) UnarchiveGroupContext(ctx context.Context, group string) error { values := url.Values{ "token": {api.config.token}, "channel": {group}, } - _, err := groupRequest("groups.unarchive", values, api.debug) + _, err := groupRequest(ctx, "groups.unarchive", values, api.debug) if err != nil { return err } @@ -67,11 +78,16 @@ func (api *Client) UnarchiveGroup(group string) error { // CreateGroup creates a private group func (api *Client) CreateGroup(group string) (*Group, error) { + return api.CreateGroupContext(context.Background(), group) +} + +// CreateGroup creates a private group +func (api *Client) CreateGroupContext(ctx context.Context, group string) (*Group, error) { values := url.Values{ "token": {api.config.token}, "name": {group}, } - response, err := groupRequest("groups.create", values, api.debug) + response, err := groupRequest(ctx, "groups.create", values, api.debug) if err != nil { return nil, err } @@ -85,11 +101,17 @@ func (api *Client) CreateGroup(group string) (*Group, error) { // 3. Creates a new group with the name of the existing group. // 4. Adds all members of the existing group to the new group. func (api *Client) CreateChildGroup(group string) (*Group, error) { + return api.CreateChildGroupContext(context.Background(), group) +} + +// CreateChildGroup creates a new private group archiving the old one with a custom context +// For more information see CreateChildGroup +func (api *Client) CreateChildGroupContext(ctx context.Context, group string) (*Group, error) { values := url.Values{ "token": {api.config.token}, "channel": {group}, } - response, err := groupRequest("groups.createChild", values, api.debug) + response, err := groupRequest(ctx, "groups.createChild", values, api.debug) if err != nil { return nil, err } @@ -98,11 +120,16 @@ func (api *Client) CreateChildGroup(group string) (*Group, error) { // CloseGroup closes a private group func (api *Client) CloseGroup(group string) (bool, bool, error) { + return api.CloseGroupContext(context.Background(), group) +} + +// CloseGroupContext closes a private group with a custom context +func (api *Client) CloseGroupContext(ctx context.Context, group string) (bool, bool, error) { values := url.Values{ "token": {api.config.token}, "channel": {group}, } - response, err := imRequest("groups.close", values, api.debug) + response, err := imRequest(ctx, "groups.close", values, api.debug) if err != nil { return false, false, err } @@ -111,6 +138,11 @@ func (api *Client) CloseGroup(group string) (bool, bool, error) { // GetGroupHistory fetches all the history for a private group func (api *Client) GetGroupHistory(group string, params HistoryParameters) (*History, error) { + return api.GetGroupHistoryContext(context.Background(), group, params) +} + +// GetGroupHistoryContext fetches all the history for a private group with a custom context +func (api *Client) GetGroupHistoryContext(ctx context.Context, group string, params HistoryParameters) (*History, error) { values := url.Values{ "token": {api.config.token}, "channel": {group}, @@ -138,7 +170,7 @@ func (api *Client) GetGroupHistory(group string, params HistoryParameters) (*His values.Add("unreads", "0") } } - response, err := groupRequest("groups.history", values, api.debug) + response, err := groupRequest(ctx, "groups.history", values, api.debug) if err != nil { return nil, err } @@ -147,12 +179,17 @@ func (api *Client) GetGroupHistory(group string, params HistoryParameters) (*His // InviteUserToGroup invites a specific user to a private group func (api *Client) InviteUserToGroup(group, user string) (*Group, bool, error) { + return api.InviteUserToGroupContext(context.Background(), group, user) +} + +// InviteUserToGroupContext invites a specific user to a private group with a custom context +func (api *Client) InviteUserToGroupContext(ctx context.Context, group, user string) (*Group, bool, error) { values := url.Values{ "token": {api.config.token}, "channel": {group}, "user": {user}, } - response, err := groupRequest("groups.invite", values, api.debug) + response, err := groupRequest(ctx, "groups.invite", values, api.debug) if err != nil { return nil, false, err } @@ -161,11 +198,16 @@ func (api *Client) InviteUserToGroup(group, user string) (*Group, bool, error) { // LeaveGroup makes authenticated user leave the group func (api *Client) LeaveGroup(group string) error { + return api.LeaveGroupContext(context.Background(), group) +} + +// LeaveGroupContext makes authenticated user leave the group with a custom context +func (api *Client) LeaveGroupContext(ctx context.Context, group string) error { values := url.Values{ "token": {api.config.token}, "channel": {group}, } - _, err := groupRequest("groups.leave", values, api.debug) + _, err := groupRequest(ctx, "groups.leave", values, api.debug) if err != nil { return err } @@ -174,12 +216,17 @@ func (api *Client) LeaveGroup(group string) error { // KickUserFromGroup kicks a user from a group func (api *Client) KickUserFromGroup(group, user string) error { + return api.KickUserFromGroupContext(context.Background(), group, user) +} + +// KickUserFromGroupContext kicks a user from a group with a custom context +func (api *Client) KickUserFromGroupContext(ctx context.Context, group, user string) error { values := url.Values{ "token": {api.config.token}, "channel": {group}, "user": {user}, } - _, err := groupRequest("groups.kick", values, api.debug) + _, err := groupRequest(ctx, "groups.kick", values, api.debug) if err != nil { return err } @@ -188,13 +235,18 @@ func (api *Client) KickUserFromGroup(group, user string) error { // GetGroups retrieves all groups func (api *Client) GetGroups(excludeArchived bool) ([]Group, error) { + return api.GetGroupsContext(context.Background(), excludeArchived) +} + +// GetGroupsContext retrieves all groups with a custom context +func (api *Client) GetGroupsContext(ctx context.Context, excludeArchived bool) ([]Group, error) { values := url.Values{ "token": {api.config.token}, } if excludeArchived { values.Add("exclude_archived", "1") } - response, err := groupRequest("groups.list", values, api.debug) + response, err := groupRequest(ctx, "groups.list", values, api.debug) if err != nil { return nil, err } @@ -203,11 +255,16 @@ func (api *Client) GetGroups(excludeArchived bool) ([]Group, error) { // GetGroupInfo retrieves the given group func (api *Client) GetGroupInfo(group string) (*Group, error) { + return api.GetGroupInfoContext(context.Background(), group) +} + +// GetGroupInfoContext retrieves the given group with a custom context +func (api *Client) GetGroupInfoContext(ctx context.Context, group string) (*Group, error) { values := url.Values{ "token": {api.config.token}, "channel": {group}, } - response, err := groupRequest("groups.info", values, api.debug) + response, err := groupRequest(ctx, "groups.info", values, api.debug) if err != nil { return nil, err } @@ -220,12 +277,18 @@ func (api *Client) GetGroupInfo(group string) (*Group, error) { // calls (just one per channel). This is useful for when reading scroll-back history, or following a busy live // channel. A timeout of 5 seconds is a good starting point. Be sure to flush these calls on shutdown/logout. func (api *Client) SetGroupReadMark(group, ts string) error { + return api.SetGroupReadMarkContext(context.Background(), group, ts) +} + +// SetGroupReadMarkContext sets the read mark on a private group with a custom context +// For more details see SetGroupReadMark +func (api *Client) SetGroupReadMarkContext(ctx context.Context, group, ts string) error { values := url.Values{ "token": {api.config.token}, "channel": {group}, "ts": {ts}, } - _, err := groupRequest("groups.mark", values, api.debug) + _, err := groupRequest(ctx, "groups.mark", values, api.debug) if err != nil { return err } @@ -234,11 +297,16 @@ func (api *Client) SetGroupReadMark(group, ts string) error { // OpenGroup opens a private group func (api *Client) OpenGroup(group string) (bool, bool, error) { + return api.OpenGroupContext(context.Background(), group) +} + +// OpenGroupContext opens a private group with a custom context +func (api *Client) OpenGroupContext(ctx context.Context, group string) (bool, bool, error) { values := url.Values{ "token": {api.config.token}, "channel": {group}, } - response, err := groupRequest("groups.open", values, api.debug) + response, err := groupRequest(ctx, "groups.open", values, api.debug) if err != nil { return false, false, err } @@ -249,6 +317,11 @@ func (api *Client) OpenGroup(group string) (bool, bool, error) { // XXX: They return a channel, not a group. What is this crap? :( // Inconsistent api it seems. func (api *Client) RenameGroup(group, name string) (*Channel, error) { + return api.RenameGroupContext(context.Background(), group, name) +} + +// RenameGroupContext renames a group with a custom context +func (api *Client) RenameGroupContext(ctx context.Context, group, name string) (*Channel, error) { values := url.Values{ "token": {api.config.token}, "channel": {group}, @@ -256,22 +329,26 @@ func (api *Client) RenameGroup(group, name string) (*Channel, error) { } // XXX: the created entry in this call returns a string instead of a number // so I may have to do some workaround to solve it. - response, err := groupRequest("groups.rename", values, api.debug) + response, err := groupRequest(ctx, "groups.rename", values, api.debug) if err != nil { return nil, err } return &response.Channel, nil - } // SetGroupPurpose sets the group purpose func (api *Client) SetGroupPurpose(group, purpose string) (string, error) { + return api.SetGroupPurposeContext(context.Background(), group, purpose) +} + +// SetGroupPurposeContext sets the group purpose with a custom context +func (api *Client) SetGroupPurposeContext(ctx context.Context, group, purpose string) (string, error) { values := url.Values{ "token": {api.config.token}, "channel": {group}, "purpose": {purpose}, } - response, err := groupRequest("groups.setPurpose", values, api.debug) + response, err := groupRequest(ctx, "groups.setPurpose", values, api.debug) if err != nil { return "", err } @@ -280,12 +357,17 @@ func (api *Client) SetGroupPurpose(group, purpose string) (string, error) { // SetGroupTopic sets the group topic func (api *Client) SetGroupTopic(group, topic string) (string, error) { + return api.SetGroupTopicContext(context.Background(), group, topic) +} + +// SetGroupTopicContext sets the group topic with a custom context +func (api *Client) SetGroupTopicContext(ctx context.Context, group, topic string) (string, error) { values := url.Values{ "token": {api.config.token}, "channel": {group}, "topic": {topic}, } - response, err := groupRequest("groups.setTopic", values, api.debug) + response, err := groupRequest(ctx, "groups.setTopic", values, api.debug) if err != nil { return "", err } |