diff --git a/mastodon/mastodon.go b/mastodon/mastodon.go
index b3edde5..75e029b 100644
--- a/mastodon/mastodon.go
+++ b/mastodon/mastodon.go
@@ -260,6 +260,7 @@ func (c *Client) GetAccessToken(ctx context.Context) string {
// Toot is struct to post status.
type Toot struct {
+ Edit string `json:"id"`
Status string `json:"status"`
InReplyToID string `json:"in_reply_to_id"`
MediaIDs []string `json:"media_ids"`
diff --git a/mastodon/status.go b/mastodon/status.go
index 2d4fce7..863c9b2 100644
--- a/mastodon/status.go
+++ b/mastodon/status.go
@@ -333,10 +333,16 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
params.Set("content_type", toot.ContentType)
}
var status Status
- err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil)
-
- if err != nil {
- return nil, err
+ if toot.Edit != "" {
+ err := c.doAPI(ctx, http.MethodPut, fmt.Sprintf("/api/v1/statuses/%s", toot.Edit), params, &status, nil)
+ if err != nil {
+ return nil, err
+ }
+ } else {
+ err := c.doAPI(ctx, http.MethodPost, "/api/v1/statuses", params, &status, nil)
+ if err != nil {
+ return nil, err
+ }
}
return &status, nil
}
diff --git a/service/service.go b/service/service.go
index fcc034f..d5ef73f 100644
--- a/service/service.go
+++ b/service/service.go
@@ -986,7 +986,7 @@ func (s *service) Signout(c *client) (err error) {
func (s *service) Post(c *client, content string, replyToID string,
format string, visibility string, isNSFW bool, spoilerText string,
- files []*multipart.FileHeader) (id string, err error) {
+ files []*multipart.FileHeader, edit string) (id string, err error) {
var mediaIDs []string
for _, f := range files {
@@ -1005,6 +1005,7 @@ func (s *service) Post(c *client, content string, replyToID string,
ContentType: format,
Visibility: visibility,
Sensitive: isNSFW,
+ Edit: edit,
}
st, err := c.PostStatus(c.ctx, tweet)
if err != nil {
diff --git a/service/transport.go b/service/transport.go
index eecdaf1..abc6152 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -282,8 +282,9 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
isNSFW := c.r.FormValue("is_nsfw") == "true"
quickReply := c.r.FormValue("quickreply") == "true"
files := c.r.MultipartForm.File["attachments"]
+ edit := c.r.FormValue("edit-status-id")
- id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files)
+ id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit)
if err != nil {
return err
}
diff --git a/templates/postform.tmpl b/templates/postform.tmpl
index 7ee3cac..57a43d4 100644
--- a/templates/postform.tmpl
+++ b/templates/postform.tmpl
@@ -47,6 +47,7 @@
+
{{end}}