diff options
author | 2025-02-20 10:13:07 +0000 | |
---|---|---|
committer | 2025-02-20 11:13:07 +0100 | |
commit | a03a35a5d6c86ef85d66bae501daaa1cd8c47c2e (patch) | |
tree | 78d745437a15d4db3ea37965fa6a40f5156eb482 /internal/gtsmodel/poll.go | |
parent | [chore] Step minio down to 7.0.85 (#3808) (diff) | |
download | gotosocial-a03a35a5d6c86ef85d66bae501daaa1cd8c47c2e.tar.xz |
[bugfix] update fedi api to support multiple separate votes in same multiple choice poll (#3809)
Diffstat (limited to 'internal/gtsmodel/poll.go')
-rw-r--r-- | internal/gtsmodel/poll.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/internal/gtsmodel/poll.go b/internal/gtsmodel/poll.go index 35a9ddf59..5e48460e6 100644 --- a/internal/gtsmodel/poll.go +++ b/internal/gtsmodel/poll.go @@ -60,8 +60,8 @@ func (p *Poll) Closed() bool { time.Now().After(p.ClosedAt) } -// IncrementVotes increments Poll vote and voter counts for given choices. -func (p *Poll) IncrementVotes(choices []int) { +// IncrementVotes increments Poll vote counts for given choices, and voters if 'isNew' is set. +func (p *Poll) IncrementVotes(choices []int, isNew bool) { if len(choices) == 0 { return } @@ -69,11 +69,13 @@ func (p *Poll) IncrementVotes(choices []int) { for _, choice := range choices { p.Votes[choice]++ } - (*p.Voters)++ + if isNew { + (*p.Voters)++ + } } -// DecrementVotes decrements Poll vote and voter counts for given choices. -func (p *Poll) DecrementVotes(choices []int) { +// DecrementVotes decrements Poll vote counts for given choices, and voters if 'withVoter' is set. +func (p *Poll) DecrementVotes(choices []int, withVoter bool) { if len(choices) == 0 { return } @@ -83,7 +85,8 @@ func (p *Poll) DecrementVotes(choices []int) { p.Votes[choice]-- } } - if (*p.Voters) != 0 { + if (*p.Voters) != 0 && + withVoter { (*p.Voters)-- } } |