From 4c0c1c40a8d88561b8ddf4a717e0b8014a8a6eff Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Fri, 10 Nov 2023 18:00:13 +0300 Subject: [PATCH] update README and hardcode poll options to 20 --- README | 4 ++++ mastodon/mastodon.go | 9 +++++++++ mastodon/status.go | 13 +++++++++++++ renderer/renderer.go | 10 ++++++++++ service/service.go | 11 ++++++++++- service/transport.go | 16 +++++++++++++++- templates/postform.tmpl | 15 +++++++++++++++ 7 files changed, 76 insertions(+), 2 deletions(-) diff --git a/README b/README index f921586..14261d7 100644 --- a/README +++ b/README @@ -12,6 +12,10 @@ Changes (localhost_custom fork): - visible edited post time - visible quoted post (status in status) - visible profile banner in spoiler +- add schedule status +- add language input form +- add expiry status +- add support for send poll (hardcoded to 20 options) - hide boosts in spoiler - hide NSFW content and attachments in spoiler - some micro visual changes diff --git a/mastodon/mastodon.go b/mastodon/mastodon.go index 9bd00f2..04afeb4 100644 --- a/mastodon/mastodon.go +++ b/mastodon/mastodon.go @@ -213,6 +213,15 @@ type Toot struct { Language string `json:"language"` ExpiresIn int `json:"expires_in"` ScheduledAt string `json:"scheduled_at"` + Poll TootPoll `json:"poll"` +} + +// TootPoll is struct to poll in post status. +type TootPoll struct { + ExpiresIn int `json:"expires_in"` + HideTotals bool `json:"hide_totals"` + Multiple bool `json:"multiple"` + Options []string `json:"options"` } // Mention hold information for mention. diff --git a/mastodon/status.go b/mastodon/status.go index f56ba21..064ffd0 100644 --- a/mastodon/status.go +++ b/mastodon/status.go @@ -13,6 +13,7 @@ import ( "encoding/json" "path" "strings" + "strconv" ) type StatusPleroma struct { @@ -367,7 +368,19 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) { if toot.ScheduledAt != "" { params.Set("scheduled_at", toot.ScheduledAt) } + if len(toot.Poll.Options) > 2 { + for _, option := range toot.Poll.Options { + params.Add("poll[options][]", string(option)) + } + params.Set("poll[expires_in]", strconv.Itoa(toot.Poll.ExpiresIn)) + if toot.Poll.Multiple { + params.Set("poll[multiple]", "true") + } + if toot.Poll.HideTotals { + params.Set("poll[hide_totals]", "true") + } + } 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/renderer/renderer.go b/renderer/renderer.go index 470490e..34046ba 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" "time" + "fmt" "bloat/mastodon" ) @@ -67,6 +68,14 @@ func emojiFilter(content string, emojis []mastodon.Emoji) string { return strings.NewReplacer(replacements...).Replace(content) } +func generatePollOptions() string { + var pollbuilder string + for i := 0; i < 20; i++ { + pollbuilder = pollbuilder + `
` + } + return pollbuilder +} + var quoteRE = regexp.MustCompile("(?mU)(^|> *|\n)(>.*)( +
Poll +
+ + +
+
+ + +
+
+ + +
+
{{GeneratePollOptions | Raw}}
+
{{end}}