summaryrefslogtreecommitdiff
path: root/internal/federation/dereferencing/util.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-11-11 10:15:04 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-11 10:15:04 +0000
commitdeaea100c37698893e97cf9cab159a3d220ac3cd (patch)
treef48abc96964652d1701d91c88a00174c8f1b0196 /internal/federation/dereferencing/util.go
parent[feature] Media attachment placeholders (#2331) (diff)
downloadgotosocial-deaea100c37698893e97cf9cab159a3d220ac3cd.tar.xz
[bugfix] support endless polls, and misskey's' method of inferring expiry in closed polls (#2349)
Diffstat (limited to 'internal/federation/dereferencing/util.go')
-rw-r--r--internal/federation/dereferencing/util.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/federation/dereferencing/util.go b/internal/federation/dereferencing/util.go
index e69aeec3b..c37f2d82d 100644
--- a/internal/federation/dereferencing/util.go
+++ b/internal/federation/dereferencing/util.go
@@ -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()
+}