5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-24 16:41:36 +00:00
matterbridge/vendor/github.com/slack-go/slack/pins.go

95 lines
2.3 KiB
Go
Raw Normal View History

2016-09-05 14:34:37 +00:00
package slack
import (
2017-07-16 12:29:46 +00:00
"context"
2016-09-05 14:34:37 +00:00
"errors"
"net/url"
)
type listPinsResponseFull struct {
Items []Item
Paging `json:"paging"`
SlackResponse
}
// AddPin pins an item in a channel
func (api *Client) AddPin(channel string, item ItemRef) error {
2017-07-16 12:29:46 +00:00
return api.AddPinContext(context.Background(), channel, item)
}
// AddPinContext pins an item in a channel with a custom context
func (api *Client) AddPinContext(ctx context.Context, channel string, item ItemRef) error {
2016-09-05 14:34:37 +00:00
values := url.Values{
"channel": {channel},
2018-08-09 22:38:19 +00:00
"token": {api.token},
2016-09-05 14:34:37 +00:00
}
if item.Timestamp != "" {
2018-08-09 22:38:19 +00:00
values.Set("timestamp", item.Timestamp)
2016-09-05 14:34:37 +00:00
}
if item.File != "" {
2018-08-09 22:38:19 +00:00
values.Set("file", item.File)
2016-09-05 14:34:37 +00:00
}
if item.Comment != "" {
2018-08-09 22:38:19 +00:00
values.Set("file_comment", item.Comment)
2016-09-05 14:34:37 +00:00
}
2018-08-09 22:38:19 +00:00
2016-09-05 14:34:37 +00:00
response := &SlackResponse{}
2019-09-07 20:46:58 +00:00
if err := api.postMethod(ctx, "pins.add", values, response); err != nil {
2016-09-05 14:34:37 +00:00
return err
}
2018-08-09 22:38:19 +00:00
return response.Err()
2016-09-05 14:34:37 +00:00
}
// RemovePin un-pins an item from a channel
func (api *Client) RemovePin(channel string, item ItemRef) error {
2017-07-16 12:29:46 +00:00
return api.RemovePinContext(context.Background(), channel, item)
}
// RemovePinContext un-pins an item from a channel with a custom context
func (api *Client) RemovePinContext(ctx context.Context, channel string, item ItemRef) error {
2016-09-05 14:34:37 +00:00
values := url.Values{
"channel": {channel},
2018-08-09 22:38:19 +00:00
"token": {api.token},
2016-09-05 14:34:37 +00:00
}
if item.Timestamp != "" {
2018-08-09 22:38:19 +00:00
values.Set("timestamp", item.Timestamp)
2016-09-05 14:34:37 +00:00
}
if item.File != "" {
2018-08-09 22:38:19 +00:00
values.Set("file", item.File)
2016-09-05 14:34:37 +00:00
}
if item.Comment != "" {
2018-08-09 22:38:19 +00:00
values.Set("file_comment", item.Comment)
2016-09-05 14:34:37 +00:00
}
2018-08-09 22:38:19 +00:00
2016-09-05 14:34:37 +00:00
response := &SlackResponse{}
2019-09-07 20:46:58 +00:00
if err := api.postMethod(ctx, "pins.remove", values, response); err != nil {
2016-09-05 14:34:37 +00:00
return err
}
2018-08-09 22:38:19 +00:00
return response.Err()
2016-09-05 14:34:37 +00:00
}
// ListPins returns information about the items a user reacted to.
func (api *Client) ListPins(channel string) ([]Item, *Paging, error) {
2017-07-16 12:29:46 +00:00
return api.ListPinsContext(context.Background(), channel)
}
// ListPinsContext returns information about the items a user reacted to with a custom context.
func (api *Client) ListPinsContext(ctx context.Context, channel string) ([]Item, *Paging, error) {
2016-09-05 14:34:37 +00:00
values := url.Values{
"channel": {channel},
2018-08-09 22:38:19 +00:00
"token": {api.token},
2016-09-05 14:34:37 +00:00
}
2018-08-09 22:38:19 +00:00
2016-09-05 14:34:37 +00:00
response := &listPinsResponseFull{}
2019-09-07 20:46:58 +00:00
err := api.postMethod(ctx, "pins.list", values, response)
2016-09-05 14:34:37 +00:00
if err != nil {
return nil, nil, err
}
if !response.Ok {
return nil, nil, errors.New(response.Error)
}
return response.Items, &response.Paging, nil
}