From a03a35a5d6c86ef85d66bae501daaa1cd8c47c2e Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Thu, 20 Feb 2025 10:13:07 +0000 Subject: [bugfix] update fedi api to support multiple separate votes in same multiple choice poll (#3809) --- internal/gtsmodel/poll.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'internal/gtsmodel') 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)-- } } -- cgit v1.2.3