mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-07 17:18:07 -06:00
[bugfix] support endless polls, and misskey's' method of inferring expiry in closed polls (#2349)
This commit is contained in:
parent
ba9d6b467a
commit
deaea100c3
16 changed files with 212 additions and 52 deletions
|
|
@ -737,27 +737,22 @@ func (d *Dereferencer) fetchStatusPoll(ctx context.Context, existing, status *gt
|
|||
// no previous poll, insert new poll!
|
||||
return insertStatusPoll(ctx, status)
|
||||
|
||||
case /*existing.Poll != nil &&*/ status.Poll == nil:
|
||||
case status.Poll == nil:
|
||||
// existing poll has been deleted, remove this.
|
||||
return deleteStatusPoll(ctx, existing.PollID)
|
||||
|
||||
case /*existing.Poll != nil && status.Poll != nil && */
|
||||
!slices.Equal(existing.Poll.Options, status.Poll.Options) ||
|
||||
!existing.Poll.ExpiresAt.Equal(status.Poll.ExpiresAt):
|
||||
case pollChanged(existing.Poll, status.Poll):
|
||||
// poll has changed since original, delete and reinsert new.
|
||||
if err := deleteStatusPoll(ctx, existing.PollID); err != nil {
|
||||
return err
|
||||
}
|
||||
return insertStatusPoll(ctx, status)
|
||||
|
||||
case /*existing.Poll != nil && status.Poll != nil && */
|
||||
!existing.Poll.ClosedAt.Equal(status.Poll.ClosedAt) ||
|
||||
!slices.Equal(existing.Poll.Votes, status.Poll.Votes) ||
|
||||
existing.Poll.Voters != status.Poll.Voters:
|
||||
case pollUpdated(existing.Poll, status.Poll):
|
||||
// Since we last saw it, the poll has updated!
|
||||
// Whether that be stats, or close time.
|
||||
poll := existing.Poll
|
||||
poll.Closing = (!poll.Closed() && status.Poll.Closed())
|
||||
poll.Closing = pollJustClosed(existing.Poll, status.Poll)
|
||||
poll.ClosedAt = status.Poll.ClosedAt
|
||||
poll.Voters = status.Poll.Voters
|
||||
poll.Votes = status.Poll.Votes
|
||||
|
|
|
|||
|
|
@ -17,6 +17,12 @@
|
|||
|
||||
package dereferencing
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
// doOnce wraps a function to only perform it once.
|
||||
func doOnce(fn func()) func() {
|
||||
var once int32
|
||||
|
|
@ -27,3 +33,24 @@ func doOnce(fn func()) func() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pollChanged returns whether a poll has changed in way that
|
||||
// indicates that this should be an entirely new poll. i.e. if
|
||||
// the available options have changed, or the expiry has increased.
|
||||
func pollChanged(existing, latest *gtsmodel.Poll) bool {
|
||||
return !slices.Equal(existing.Options, latest.Options) ||
|
||||
!existing.ExpiresAt.Equal(latest.ExpiresAt)
|
||||
}
|
||||
|
||||
// pollUpdated returns whether a poll has updated, i.e. if the
|
||||
// vote counts have changed, or if it has expired / been closed.
|
||||
func pollUpdated(existing, latest *gtsmodel.Poll) bool {
|
||||
return *existing.Voters != *latest.Voters ||
|
||||
!slices.Equal(existing.Votes, latest.Votes) ||
|
||||
!existing.ClosedAt.Equal(latest.ClosedAt)
|
||||
}
|
||||
|
||||
// pollJustClosed returns whether a poll has *just* closed.
|
||||
func pollJustClosed(existing, latest *gtsmodel.Poll) bool {
|
||||
return existing.ClosedAt.IsZero() && latest.Closed()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue