aboutsummaryrefslogtreecommitdiff
path: root/service/service.go
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-14 20:19:02 +0000
committerr <r@freesoftwareextremist.com>2019-12-14 20:19:02 +0000
commite129ea922e6cbe8966f9a9f0b1c6c94401516c61 (patch)
tree35be3bc003b787db5898ac1ba8aacca3f944105e /service/service.go
parentea66bd539dec12ef2846c23e505593f9f9d9fac3 (diff)
downloadbloat-e129ea922e6cbe8966f9a9f0b1c6c94401516c61.tar.gz
bloat-e129ea922e6cbe8966f9a9f0b1c6c94401516c61.zip
Add attachments support
Diffstat (limited to 'service/service.go')
-rw-r--r--service/service.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/service/service.go b/service/service.go
index 3bfb163..15dab5d 100644
--- a/service/service.go
+++ b/service/service.go
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
+ "mime/multipart"
"net/http"
"net/url"
"path"
@@ -36,7 +37,7 @@ type Service interface {
UnLike(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
Retweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
UnRetweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
- PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string) (id string, err error)
+ PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error)
}
type service struct {
@@ -292,10 +293,20 @@ func (svc *service) UnRetweet(ctx context.Context, client io.Writer, c *mastodon
return
}
-func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string) (id string, err error) {
+func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error) {
+ var mediaIds []string
+ for _, f := range files {
+ a, err := c.UploadMediaFromMultipartFileHeader(ctx, f)
+ if err != nil {
+ return "", err
+ }
+ mediaIds = append(mediaIds, a.ID)
+ }
+
tweet := &mastodon.Toot{
Status: content,
InReplyToID: replyToID,
+ MediaIDs: mediaIds,
}
s, err := c.PostStatus(ctx, tweet)