Add support for creating polls
parent
58c3891813
commit
ae6cc11820
|
@ -219,6 +219,15 @@ type Toot struct {
|
||||||
SpoilerText string `json:"spoiler_text"`
|
SpoilerText string `json:"spoiler_text"`
|
||||||
Visibility string `json:"visibility"`
|
Visibility string `json:"visibility"`
|
||||||
ScheduledAt *time.Time `json:"scheduled_at,omitempty"`
|
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.
|
// Mention hold information for mention.
|
||||||
|
|
13
status.go
13
status.go
|
@ -349,6 +349,19 @@ func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) {
|
||||||
params.Add("media_ids[]", string(media))
|
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 != "" {
|
if toot.Visibility != "" {
|
||||||
params.Set("visibility", fmt.Sprint(toot.Visibility))
|
params.Set("visibility", fmt.Sprint(toot.Visibility))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue