From 6a233f6cb24d29d1a571506a7bb1276a4ca0edb1 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Fri, 10 Nov 2023 01:27:22 +0300 Subject: [PATCH] add scheduled status --- mastodon/mastodon.go | 3 ++- mastodon/status.go | 3 +++ service/service.go | 3 ++- service/transport.go | 10 +++++++++- templates/postform.tmpl | 1 + 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mastodon/mastodon.go b/mastodon/mastodon.go index 5138091..9bd00f2 100644 --- a/mastodon/mastodon.go +++ b/mastodon/mastodon.go @@ -211,7 +211,8 @@ type Toot struct { Visibility string `json:"visibility"` ContentType string `json:"content_type"` Language string `json:"language"` - ExpiresIn int `json:"expires_in"` + ExpiresIn int `json:"expires_in"` + ScheduledAt string `json:"scheduled_at"` } // Mention hold information for mention. diff --git a/mastodon/status.go b/mastodon/status.go index 242cb03..f56ba21 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -364,6 +364,9 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) { if toot.ExpiresIn >= 3600 { params.Set("expires_in", fmt.Sprint(toot.ExpiresIn)) } + if toot.ScheduledAt != "" { + params.Set("scheduled_at", toot.ScheduledAt) + } var status Status if toot.Edit != "" { diff --git a/service/service.go b/service/service.go index 8cdae83..8215c6a 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, language string, expiresIn int) (id string, err error) { + files []*multipart.FileHeader, edit string, language string, expiresIn int, scheduledAt string) (id string, err error) { var mediaIDs []string for _, f := range files { @@ -1012,6 +1012,7 @@ func (s *service) Post(c *client, content string, replyToID string, Edit: edit, Language: language, ExpiresIn: expiresIn, // pleroma compatible + ScheduledAt: scheduledAt, } st, err := c.PostStatus(c.ctx, tweet) diff --git a/service/transport.go b/service/transport.go index 30c5a2b..41809f8 100644 --- a/service/transport.go +++ b/service/transport.go @@ -319,8 +319,16 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler { if err != nil { return err } + scheduledAt := c.r.FormValue("scheduled") + if scheduledAt != "" { + scheduled, err := time.Parse("2006-01-02T15:04", scheduledAt) + if err != nil { + return err + } + scheduledAt = string(scheduled.UTC().Format(time.RFC3339)) + } - id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit, language, expiresIn) + id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit, language, expiresIn, scheduledAt) if err != nil { return err } diff --git a/templates/postform.tmpl b/templates/postform.tmpl index a952fe4..964032b 100644 --- a/templates/postform.tmpl +++ b/templates/postform.tmpl @@ -50,6 +50,7 @@ + {{end}}