summaryrefslogtreecommitdiff
path: root/internal/typeutils/internaltofrontend.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r--internal/typeutils/internaltofrontend.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 0a79defc7..d5a1dee32 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -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
}