mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix/docs] Poll api fixups + swagger docs (#2345)
This commit is contained in:
@ -1313,8 +1313,10 @@ func (c *Converter) PollToAPIPoll(ctx context.Context, requester *gtsmodel.Accou
|
||||
options []apimodel.PollOption
|
||||
totalVotes int
|
||||
totalVoters int
|
||||
ownChoices []int
|
||||
voted *bool
|
||||
ownChoices *[]int
|
||||
isAuthor bool
|
||||
emojis []apimodel.Emoji
|
||||
)
|
||||
|
||||
// Preallocate a slice of frontend model poll choices.
|
||||
@ -1337,19 +1339,26 @@ func (c *Converter) PollToAPIPoll(ctx context.Context, requester *gtsmodel.Accou
|
||||
|
||||
if vote != nil {
|
||||
// Set choices by requester.
|
||||
ownChoices = vote.Choices
|
||||
ownChoices = &vote.Choices
|
||||
|
||||
// Update default totals in the
|
||||
// case that counts are hidden.
|
||||
totalVotes = len(vote.Choices)
|
||||
totalVoters = 1
|
||||
for _, choice := range ownChoices {
|
||||
for _, choice := range *ownChoices {
|
||||
options[choice].VotesCount++
|
||||
}
|
||||
} else {
|
||||
// Requester is defined but hasn't made
|
||||
// a choice. Init slice to serialize as `[]`.
|
||||
ownChoices = util.Ptr(make([]int, 0))
|
||||
}
|
||||
|
||||
// Check if requester is author of source status.
|
||||
isAuthor = (requester.ID == poll.Status.AccountID)
|
||||
|
||||
// Requester is defined so voted should be defined too.
|
||||
voted = util.Ptr((isAuthor || len(*ownChoices) > 0))
|
||||
}
|
||||
|
||||
if isAuthor || !*poll.HideCounts {
|
||||
@ -1368,6 +1377,11 @@ func (c *Converter) PollToAPIPoll(ctx context.Context, requester *gtsmodel.Accou
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: emojis used in poll options.
|
||||
// For now init to empty slice to serialize as `[]`.
|
||||
// In future inherit from parent status.
|
||||
emojis = make([]apimodel.Emoji, 0)
|
||||
|
||||
return &apimodel.Poll{
|
||||
ID: poll.ID,
|
||||
ExpiresAt: util.FormatISO8601(poll.ExpiresAt),
|
||||
@ -1375,9 +1389,10 @@ func (c *Converter) PollToAPIPoll(ctx context.Context, requester *gtsmodel.Accou
|
||||
Multiple: (*poll.Multiple),
|
||||
VotesCount: totalVotes,
|
||||
VotersCount: totalVoters,
|
||||
Voted: (isAuthor || len(ownChoices) > 0),
|
||||
Voted: voted,
|
||||
OwnVotes: ownChoices,
|
||||
Options: options,
|
||||
Emojis: emojis,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user