diff options
Diffstat (limited to 'vendor/github.com/nlopes/slack/im.go')
-rw-r--r-- | vendor/github.com/nlopes/slack/im.go | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/vendor/github.com/nlopes/slack/im.go b/vendor/github.com/nlopes/slack/im.go index 6fbc39e9..0cbc8d34 100644 --- a/vendor/github.com/nlopes/slack/im.go +++ b/vendor/github.com/nlopes/slack/im.go @@ -1,6 +1,7 @@ package slack import ( + "context" "errors" "net/url" "strconv" @@ -28,9 +29,9 @@ type IM struct { IsUserDeleted bool `json:"is_user_deleted"` } -func imRequest(path string, values url.Values, debug bool) (*imResponseFull, error) { +func imRequest(ctx context.Context, path string, values url.Values, debug bool) (*imResponseFull, error) { response := &imResponseFull{} - err := post(path, values, response, debug) + err := post(ctx, path, values, response, debug) if err != nil { return nil, err } @@ -42,11 +43,16 @@ func imRequest(path string, values url.Values, debug bool) (*imResponseFull, err // CloseIMChannel closes the direct message channel func (api *Client) CloseIMChannel(channel string) (bool, bool, error) { + return api.CloseIMChannelContext(context.Background(), channel) +} + +// CloseIMChannelContext closes the direct message channel with a custom context +func (api *Client) CloseIMChannelContext(ctx context.Context, channel string) (bool, bool, error) { values := url.Values{ "token": {api.config.token}, "channel": {channel}, } - response, err := imRequest("im.close", values, api.debug) + response, err := imRequest(ctx, "im.close", values, api.debug) if err != nil { return false, false, err } @@ -56,11 +62,17 @@ func (api *Client) CloseIMChannel(channel string) (bool, bool, error) { // OpenIMChannel opens a direct message channel to the user provided as argument // Returns some status and the channel ID func (api *Client) OpenIMChannel(user string) (bool, bool, string, error) { + return api.OpenIMChannelContext(context.Background(), user) +} + +// OpenIMChannelContext opens a direct message channel to the user provided as argument with a custom context +// Returns some status and the channel ID +func (api *Client) OpenIMChannelContext(ctx context.Context, user string) (bool, bool, string, error) { values := url.Values{ "token": {api.config.token}, "user": {user}, } - response, err := imRequest("im.open", values, api.debug) + response, err := imRequest(ctx, "im.open", values, api.debug) if err != nil { return false, false, "", err } @@ -69,12 +81,17 @@ func (api *Client) OpenIMChannel(user string) (bool, bool, string, error) { // MarkIMChannel sets the read mark of a direct message channel to a specific point func (api *Client) MarkIMChannel(channel, ts string) (err error) { + return api.MarkIMChannelContext(context.Background(), channel, ts) +} + +// MarkIMChannelContext sets the read mark of a direct message channel to a specific point with a custom context +func (api *Client) MarkIMChannelContext(ctx context.Context, channel, ts string) (err error) { values := url.Values{ "token": {api.config.token}, "channel": {channel}, "ts": {ts}, } - _, err = imRequest("im.mark", values, api.debug) + _, err = imRequest(ctx, "im.mark", values, api.debug) if err != nil { return err } @@ -83,6 +100,11 @@ func (api *Client) MarkIMChannel(channel, ts string) (err error) { // GetIMHistory retrieves the direct message channel history func (api *Client) GetIMHistory(channel string, params HistoryParameters) (*History, error) { + return api.GetIMHistoryContext(context.Background(), channel, params) +} + +// GetIMHistoryContext retrieves the direct message channel history with a custom context +func (api *Client) GetIMHistoryContext(ctx context.Context, channel string, params HistoryParameters) (*History, error) { values := url.Values{ "token": {api.config.token}, "channel": {channel}, @@ -110,7 +132,7 @@ func (api *Client) GetIMHistory(channel string, params HistoryParameters) (*Hist values.Add("unreads", "0") } } - response, err := imRequest("im.history", values, api.debug) + response, err := imRequest(ctx, "im.history", values, api.debug) if err != nil { return nil, err } @@ -119,10 +141,15 @@ func (api *Client) GetIMHistory(channel string, params HistoryParameters) (*Hist // GetIMChannels returns the list of direct message channels func (api *Client) GetIMChannels() ([]IM, error) { + return api.GetIMChannelsContext(context.Background()) +} + +// GetIMChannelsContext returns the list of direct message channels with a custom context +func (api *Client) GetIMChannelsContext(ctx context.Context) ([]IM, error) { values := url.Values{ "token": {api.config.token}, } - response, err := imRequest("im.list", values, api.debug) + response, err := imRequest(ctx, "im.list", values, api.debug) if err != nil { return nil, err } |