update README and hardcode poll options to 20

This commit is contained in:
localhost_frssoft 2023-11-10 18:00:13 +03:00
parent 8dcd6cfdd7
commit 4c0c1c40a8
7 changed files with 76 additions and 2 deletions

View file

@ -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.

View file

@ -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)