Add support for creating polls

pull/142/head
Rasmus Lindroth 2021-11-05 09:21:53 +01:00 committed by mattn
parent 58c3891813
commit ae6cc11820
2 changed files with 22 additions and 0 deletions

View File

@ -219,6 +219,15 @@ type Toot struct {
SpoilerText string `json:"spoiler_text"`
Visibility string `json:"visibility"`
ScheduledAt *time.Time `json:"scheduled_at,omitempty"`
Poll *TootPoll `json:"poll"`
}
// TootPoll holds information for creating a poll in Toot.
type TootPoll struct {
Options []string `json:"options"`
ExpiresInSeconds int64 `json:"expires_in"`
Multiple bool `json:"multiple"`
HideTotals bool `json:"hide_totals"`
}
// Mention hold information for mention.

View File

@ -349,6 +349,19 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
params.Add("media_ids[]", string(media))
}
}
// Can't use Media and Poll at the same time.
if toot.Poll != nil && toot.Poll.Options != nil && toot.MediaIDs == nil {
for _, opt := range toot.Poll.Options {
params.Add("poll[options][]", string(opt))
}
params.Add("poll[expires_in]", fmt.Sprintf("%d", toot.Poll.ExpiresInSeconds))
if toot.Poll.Multiple {
params.Add("poll[multiple]", "true")
}
if toot.Poll.HideTotals {
params.Add("poll[hide_totals]", "true")
}
}
if toot.Visibility != "" {
params.Set("visibility", fmt.Sprint(toot.Visibility))
}