aboutsummaryrefslogtreecommitdiff
path: root/mastodon/status.go
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon/status.go')
-rw-r--r--mastodon/status.go74
1 files changed, 30 insertions, 44 deletions
diff --git a/mastodon/status.go b/mastodon/status.go
index 2fae6ee..34f8727 100644
--- a/mastodon/status.go
+++ b/mastodon/status.go
@@ -1,17 +1,22 @@
package mastodon
import (
+ "bytes"
"context"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
+ "path/filepath"
"time"
)
type StatusPleroma struct {
- InReplyToAccountAcct string `json:"in_reply_to_account_acct"`
+ InReplyToAccountAcct string `json:"in_reply_to_account_acct"`
+ Quote *Status `json:"quote"`
+ QuoteID string `json:"quote_id"`
+ QuoteVisible bool `json:"quote_visible"`
}
type ReplyInfo struct {
@@ -56,7 +61,6 @@ type Status struct {
MediaAttachments []Attachment `json:"media_attachments"`
Mentions []Mention `json:"mentions"`
Tags []Tag `json:"tags"`
- Card *Card `json:"card"`
Application Application `json:"application"`
Language string `json:"language"`
Pinned interface{} `json:"pinned"`
@@ -77,22 +81,6 @@ type Context struct {
Descendants []*Status `json:"descendants"`
}
-// Card hold information for mastodon card.
-type Card struct {
- URL string `json:"url"`
- Title string `json:"title"`
- Description string `json:"description"`
- Image string `json:"image"`
- Type string `json:"type"`
- AuthorName string `json:"author_name"`
- AuthorURL string `json:"author_url"`
- ProviderName string `json:"provider_name"`
- ProviderURL string `json:"provider_url"`
- HTML string `json:"html"`
- Width int64 `json:"width"`
- Height int64 `json:"height"`
-}
-
// GetFavourites return the favorite list of the current user.
func (c *Client) GetFavourites(ctx context.Context, pg *Pagination) ([]*Status, error) {
var statuses []*Status
@@ -123,16 +111,6 @@ func (c *Client) GetStatusContext(ctx context.Context, id string) (*Context, err
return &context, nil
}
-// GetStatusCard return status specified by id.
-func (c *Client) GetStatusCard(ctx context.Context, id string) (*Card, error) {
- var card Card
- err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/statuses/%s/card", id), nil, &card, nil)
- if err != nil {
- return nil, err
- }
- return &card, nil
-}
-
// GetRebloggedBy returns the account list of the user who reblogged the toot of id.
func (c *Client) GetRebloggedBy(ctx context.Context, id string, pg *Pagination) ([]*Account, error) {
var accounts []*Account
@@ -286,6 +264,9 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
if toot.ContentType != "" {
params.Set("content_type", toot.ContentType)
}
+ if toot.QuoteID != "" {
+ params.Set("quote_id", toot.QuoteID)
+ }
var status Status
err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil)
@@ -320,30 +301,35 @@ func (c *Client) Search(ctx context.Context, q string, qType string, limit int,
return &results, nil
}
-// UploadMedia upload a media attachment from a file.
-func (c *Client) UploadMedia(ctx context.Context, file string) (*Attachment, error) {
- var attachment Attachment
- err := c.doAPI(ctx, http.MethodPost, "/api/v1/media", file, &attachment, nil)
+func (c *Client) UploadMediaFromMultipartFileHeader(ctx context.Context, fh *multipart.FileHeader) (*Attachment, error) {
+ f, err := fh.Open()
if err != nil {
return nil, err
}
- return &attachment, nil
-}
+ defer f.Close()
-// UploadMediaFromReader uploads a media attachment from a io.Reader.
-func (c *Client) UploadMediaFromReader(ctx context.Context, reader io.Reader) (*Attachment, error) {
- var attachment Attachment
- err := c.doAPI(ctx, http.MethodPost, "/api/v1/media", reader, &attachment, nil)
+ var buf bytes.Buffer
+ mw := multipart.NewWriter(&buf)
+ fname := filepath.Base(fh.Filename)
+ err = mw.WriteField("description", fname)
if err != nil {
return nil, err
}
- return &attachment, nil
-}
-
-// UploadMediaFromReader uploads a media attachment from a io.Reader.
-func (c *Client) UploadMediaFromMultipartFileHeader(ctx context.Context, fh *multipart.FileHeader) (*Attachment, error) {
+ part, err := mw.CreateFormFile("file", fname)
+ if err != nil {
+ return nil, err
+ }
+ _, err = io.Copy(part, f)
+ if err != nil {
+ return nil, err
+ }
+ err = mw.Close()
+ if err != nil {
+ return nil, err
+ }
+ params := &multipartRequest{Data: &buf, ContentType: mw.FormDataContentType()}
var attachment Attachment
- err := c.doAPI(ctx, http.MethodPost, "/api/v1/media", fh, &attachment, nil)
+ err = c.doAPI(ctx, http.MethodPost, "/api/v1/media", params, &attachment, nil)
if err != nil {
return nil, err
}