From 4cd8fb2ddbc4fd2c54a1df5e0b04eb8429fa8d8b Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 9 Nov 2023 23:14:42 +0300 Subject: [PATCH] add expires status and language code --- mastodon/mastodon.go | 2 ++ mastodon/status.go | 7 +++++++ service/service.go | 7 ++++++- service/transport.go | 7 ++++++- templates/postform.tmpl | 2 ++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mastodon/mastodon.go b/mastodon/mastodon.go index 7aafdcf..5138091 100644 --- a/mastodon/mastodon.go +++ b/mastodon/mastodon.go @@ -210,6 +210,8 @@ type Toot struct { SpoilerText string `json:"spoiler_text"` Visibility string `json:"visibility"` ContentType string `json:"content_type"` + Language string `json:"language"` + ExpiresIn int `json:"expires_in"` } // Mention hold information for mention. diff --git a/mastodon/status.go b/mastodon/status.go index 88d2b00..242cb03 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -358,6 +358,13 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) { if toot.ContentType != "" { params.Set("content_type", toot.ContentType) } + if toot.Language != "" { + params.Set("language", toot.Language) + } + if toot.ExpiresIn >= 3600 { + params.Set("expires_in", fmt.Sprint(toot.ExpiresIn)) + } + var status Status if toot.Edit != "" { err := c.doAPI(ctx, http.MethodPut, fmt.Sprintf("/api/v1/statuses/%s", toot.Edit), params, &status, nil) diff --git a/service/service.go b/service/service.go index 7ac5624..8cdae83 100644 --- a/service/service.go +++ b/service/service.go @@ -988,7 +988,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, edit string) (id string, err error) { + files []*multipart.FileHeader, edit string, language string, expiresIn int) (id string, err error) { var mediaIDs []string for _, f := range files { @@ -999,6 +999,8 @@ func (s *service) Post(c *client, content string, replyToID string, mediaIDs = append(mediaIDs, a.ID) } + expiresIn = expiresIn * 3600 + tweet := &mastodon.Toot{ SpoilerText: spoilerText, Status: content, @@ -1008,7 +1010,10 @@ func (s *service) Post(c *client, content string, replyToID string, Visibility: visibility, Sensitive: isNSFW, Edit: edit, + Language: language, + ExpiresIn: expiresIn, // pleroma compatible } + st, err := c.PostStatus(c.ctx, tweet) if err != nil { return diff --git a/service/transport.go b/service/transport.go index 2b579e4..30c5a2b 100644 --- a/service/transport.go +++ b/service/transport.go @@ -314,8 +314,13 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler { quickReply := c.r.FormValue("quickreply") == "true" files := c.r.MultipartForm.File["attachments"] edit := c.r.FormValue("edit-status-id") + language := c.r.FormValue("lang-code") + expiresIn, err := strconv.Atoi(c.r.FormValue("expires-in")) + if err != nil { + return err + } - id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit) + id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit, language, expiresIn) if err != nil { return err } diff --git a/templates/postform.tmpl b/templates/postform.tmpl index 57a43d4..a952fe4 100644 --- a/templates/postform.tmpl +++ b/templates/postform.tmpl @@ -48,6 +48,8 @@ + + {{end}}