diff options
Diffstat (limited to 'vendor/github.com/nlopes/slack/dnd.go')
-rw-r--r-- | vendor/github.com/nlopes/slack/dnd.go | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/vendor/github.com/nlopes/slack/dnd.go b/vendor/github.com/nlopes/slack/dnd.go index ac87758d..4f1b3228 100644 --- a/vendor/github.com/nlopes/slack/dnd.go +++ b/vendor/github.com/nlopes/slack/dnd.go @@ -1,6 +1,7 @@ package slack import ( + "context" "errors" "net/url" "strconv" @@ -35,9 +36,9 @@ type dndTeamInfoResponse struct { SlackResponse } -func dndRequest(path string, values url.Values, debug bool) (*dndResponseFull, error) { +func dndRequest(ctx context.Context, path string, values url.Values, debug bool) (*dndResponseFull, error) { response := &dndResponseFull{} - err := post(path, values, response, debug) + err := post(ctx, path, values, response, debug) if err != nil { return nil, err } @@ -49,12 +50,17 @@ func dndRequest(path string, values url.Values, debug bool) (*dndResponseFull, e // EndDND ends the user's scheduled Do Not Disturb session func (api *Client) EndDND() error { + return api.EndDNDContext(context.Background()) +} + +// EndDNDContext ends the user's scheduled Do Not Disturb session with a custom context +func (api *Client) EndDNDContext(ctx context.Context) error { values := url.Values{ "token": {api.config.token}, } response := &SlackResponse{} - if err := post("dnd.endDnd", values, response, api.debug); err != nil { + if err := post(ctx, "dnd.endDnd", values, response, api.debug); err != nil { return err } if !response.Ok { @@ -65,11 +71,16 @@ func (api *Client) EndDND() error { // EndSnooze ends the current user's snooze mode func (api *Client) EndSnooze() (*DNDStatus, error) { + return api.EndSnoozeContext(context.Background()) +} + +// EndSnoozeContext ends the current user's snooze mode with a custom context +func (api *Client) EndSnoozeContext(ctx context.Context) (*DNDStatus, error) { values := url.Values{ "token": {api.config.token}, } - response, err := dndRequest("dnd.endSnooze", values, api.debug) + response, err := dndRequest(ctx, "dnd.endSnooze", values, api.debug) if err != nil { return nil, err } @@ -78,13 +89,18 @@ func (api *Client) EndSnooze() (*DNDStatus, error) { // GetDNDInfo provides information about a user's current Do Not Disturb settings. func (api *Client) GetDNDInfo(user *string) (*DNDStatus, error) { + return api.GetDNDInfoContext(context.Background(), user) +} + +// GetDNDInfoContext provides information about a user's current Do Not Disturb settings with a custom context. +func (api *Client) GetDNDInfoContext(ctx context.Context, user *string) (*DNDStatus, error) { values := url.Values{ "token": {api.config.token}, } if user != nil { values.Set("user", *user) } - response, err := dndRequest("dnd.info", values, api.debug) + response, err := dndRequest(ctx, "dnd.info", values, api.debug) if err != nil { return nil, err } @@ -93,12 +109,17 @@ func (api *Client) GetDNDInfo(user *string) (*DNDStatus, error) { // GetDNDTeamInfo provides information about a user's current Do Not Disturb settings. func (api *Client) GetDNDTeamInfo(users []string) (map[string]DNDStatus, error) { + return api.GetDNDTeamInfoContext(context.Background(), users) +} + +// GetDNDTeamInfoContext provides information about a user's current Do Not Disturb settings with a custom context. +func (api *Client) GetDNDTeamInfoContext(ctx context.Context, users []string) (map[string]DNDStatus, error) { values := url.Values{ "token": {api.config.token}, "users": {strings.Join(users, ",")}, } response := &dndTeamInfoResponse{} - if err := post("dnd.teamInfo", values, response, api.debug); err != nil { + if err := post(ctx, "dnd.teamInfo", values, response, api.debug); err != nil { return nil, err } if !response.Ok { @@ -111,11 +132,17 @@ func (api *Client) GetDNDTeamInfo(users []string) (map[string]DNDStatus, error) // settings. If a snooze session is not already active for the user, invoking // this method will begin one for the specified duration. func (api *Client) SetSnooze(minutes int) (*DNDStatus, error) { + return api.SetSnoozeContext(context.Background(), minutes) +} + +// SetSnooze adjusts the snooze duration for a user's Do Not Disturb settings with a custom context. +// For more information see the SetSnooze docs +func (api *Client) SetSnoozeContext(ctx context.Context, minutes int) (*DNDStatus, error) { values := url.Values{ "token": {api.config.token}, "num_minutes": {strconv.Itoa(minutes)}, } - response, err := dndRequest("dnd.setSnooze", values, api.debug) + response, err := dndRequest(ctx, "dnd.setSnooze", values, api.debug) if err != nil { return nil, err } |