diff options
author | Wim <wim@42.be> | 2019-12-07 22:54:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-07 22:54:36 +0100 |
commit | f43faf15f847ba8c68027f8de4456f9c5092b02d (patch) | |
tree | 8b311b37351f196f54b167f727f0e78768b089c6 /vendor/github.com/nlopes/slack/interactions.go | |
parent | 173a38a37416045958b33fe7c0f68e26880f6e2b (diff) | |
download | matterbridge-msglm-f43faf15f847ba8c68027f8de4456f9c5092b02d.tar.gz matterbridge-msglm-f43faf15f847ba8c68027f8de4456f9c5092b02d.tar.bz2 matterbridge-msglm-f43faf15f847ba8c68027f8de4456f9c5092b02d.zip |
Update slack vendor to master (#958)
Diffstat (limited to 'vendor/github.com/nlopes/slack/interactions.go')
-rw-r--r-- | vendor/github.com/nlopes/slack/interactions.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/github.com/nlopes/slack/interactions.go b/vendor/github.com/nlopes/slack/interactions.go index 5433463d..de1ed370 100644 --- a/vendor/github.com/nlopes/slack/interactions.go +++ b/vendor/github.com/nlopes/slack/interactions.go @@ -1,6 +1,7 @@ package slack import ( + "bytes" "encoding/json" ) @@ -53,6 +54,48 @@ type ActionCallbacks struct { BlockActions []*BlockAction } +// MarshalJSON implements the Marshaller interface in order to combine both +// action callback types back into a single array, like how the api responds. +// This makes Marshaling and Unmarshaling an InteractionCallback symmetrical +func (a ActionCallbacks) MarshalJSON() ([]byte, error) { + count := 0 + length := len(a.AttachmentActions) + len(a.BlockActions) + buffer := bytes.NewBufferString("[") + + f := func(obj interface{}) error { + js, err := json.Marshal(obj) + if err != nil { + return err + } + _, err = buffer.Write(js) + if err != nil { + return err + } + + count++ + if count < length { + _, err = buffer.WriteString(",") + return err + } + return nil + } + + for _, act := range a.AttachmentActions { + err := f(act) + if err != nil { + return nil, err + } + } + for _, blk := range a.BlockActions { + err := f(blk) + if err != nil { + return nil, err + } + } + buffer.WriteString("]") + return buffer.Bytes(), nil +} + // UnmarshalJSON implements the Marshaller interface in order to delegate // marshalling and allow for proper type assertion when decoding the response func (a *ActionCallbacks) UnmarshalJSON(data []byte) error { |