[bugfix] poll vote count fixes (#2444)

* don't drop all vote counts if hideCounts is set, refactors poll option extraction slightly

* omit voters_count when not set

* make voters_count a ptr to ensure it is omit unless definitely needed

* handle case of expires_at, voters_count and option.votes_count being nilable

* faster isNil check

* remove omitempty tags since mastodon API marks things as nullable but still sets them in outgoing json
This commit is contained in:
kim 2023-12-12 13:47:07 +00:00 committed by GitHub
commit ac48192562
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 111 additions and 67 deletions

View file

@ -28,7 +28,7 @@ type Poll struct {
ID string `json:"id"`
// When the poll ends. (ISO 8601 Datetime).
ExpiresAt string `json:"expires_at"`
ExpiresAt *string `json:"expires_at"`
// Is the poll currently expired?
Expired bool `json:"expired"`
@ -40,7 +40,7 @@ type Poll struct {
VotesCount int `json:"votes_count"`
// How many unique accounts have voted on a multiple-choice poll.
VotersCount int `json:"voters_count"`
VotersCount *int `json:"voters_count"`
// When called with a user token, has the authorized user voted?
//
@ -68,7 +68,7 @@ type PollOption struct {
Title string `json:"title"`
// The number of received votes for this option.
VotesCount int `json:"votes_count"`
VotesCount *int `json:"votes_count"`
}
// PollRequest models a request to create a poll.