diff options
author | 2023-11-08 22:37:35 +0000 | |
---|---|---|
committer | 2023-11-08 23:37:35 +0100 | |
commit | 34d0879c1651d2703f94c1b653227c718aac475f (patch) | |
tree | ed215b9ef2b149238a56ccc988ba599224e1fc04 /internal/processing | |
parent | [feature] add support for polls + receiving federated status edits (#2330) (diff) | |
download | gotosocial-34d0879c1651d2703f94c1b653227c718aac475f.tar.xz |
[bugfix] fix poll vote count responses on client and fedi API vote creation (#2343)
* increment poll votes *before* enqueuing vote to client API worker
* increment vote counts before federating status update after vote in local poll
* improved vote count calculation during backend -> frontend model conversion
Diffstat (limited to 'internal/processing')
-rw-r--r-- | internal/processing/polls/vote.go | 10 | ||||
-rw-r--r-- | internal/processing/workers/fromfediapi.go | 4 |
2 files changed, 9 insertions, 5 deletions
diff --git a/internal/processing/polls/vote.go b/internal/processing/polls/vote.go index 8c8f22225..c4a8a12a4 100644 --- a/internal/processing/polls/vote.go +++ b/internal/processing/polls/vote.go @@ -90,6 +90,11 @@ func (p *Processor) PollVote(ctx context.Context, requester *gtsmodel.Account, p return nil, gtserror.NewErrorInternalError(err) } + // Before enqueuing it, increment the poll + // vote counts on the copy attached to the + // PollVote (that we also later return). + poll.IncrementVotes(choices) + // Enqueue worker task to handle side-effects of user poll vote(s). p.state.Workers.EnqueueClientAPI(ctx, messages.FromClientAPI{ APActivityType: ap.ActivityCreate, @@ -98,11 +103,6 @@ func (p *Processor) PollVote(ctx context.Context, requester *gtsmodel.Account, p OriginAccount: requester, }) - // Before returning the converted poll model, - // increment the vote counts on our local copy - // to get latest, instead of another db query. - poll.IncrementVotes(choices) - // Return converted API model poll. return p.toAPIPoll(ctx, requester, poll) } diff --git a/internal/processing/workers/fromfediapi.go b/internal/processing/workers/fromfediapi.go index 2b0bfa9fa..9558bf8b7 100644 --- a/internal/processing/workers/fromfediapi.go +++ b/internal/processing/workers/fromfediapi.go @@ -233,6 +233,10 @@ func (p *fediAPI) CreatePollVote(ctx context.Context, fMsg messages.FromFediAPI) p.surface.invalidateStatusFromTimelines(ctx, vote.Poll.StatusID) if *status.Local { + // Before federating it, increment the + // poll vote counts on our local copy. + status.Poll.IncrementVotes(vote.Choices) + // These were poll votes in a local status, we need to // federate the updated status model with latest vote counts. if err := p.federate.UpdateStatus(ctx, status); err != nil { |