summaryrefslogtreecommitdiff
path: root/internal/federation/dereferencing/status.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-12-23 17:54:44 +0000
committerLibravatar GitHub <noreply@github.com>2024-12-23 17:54:44 +0000
commitfe8d5f23072c40a407723904eb5c54234879d58a (patch)
treedf80063f3238997de7144932d2d713321164ac1b /internal/federation/dereferencing/status.go
parent[chore] Stub /api/v1/announcements implementation (#3630) (diff)
downloadgotosocial-fe8d5f23072c40a407723904eb5c54234879d58a.tar.xz
[feature] add support for clients editing statuses and fetching status revision history (#3628)
* start adding client support for making status edits and viewing history * modify 'freshest' freshness window to be 5s, add typeutils test for status -> api edits * only populate the status edits when specifically requested * start adding some simple processor status edit tests * add test editing status but adding a poll * test edits appropriately adding poll expiry handlers * finish adding status edit tests * store both new and old revision emojis in status * add code comment * ensure the requester's account is populated before status edits * add code comments for status edit tests * update status edit form swagger comments * remove unused function * fix status source test * add more code comments, move media description check back to media process in status create * fix tests, add necessary form struct tag
Diffstat (limited to 'internal/federation/dereferencing/status.go')
-rw-r--r--internal/federation/dereferencing/status.go26
1 files changed, 22 insertions, 4 deletions
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go
index d19669891..0a75a4802 100644
--- a/internal/federation/dereferencing/status.go
+++ b/internal/federation/dereferencing/status.go
@@ -35,6 +35,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/util"
+ "github.com/superseriousbusiness/gotosocial/internal/util/xslices"
)
// statusFresh returns true if the given status is still
@@ -1000,12 +1001,21 @@ func (d *Dereferencer) fetchStatusEmojis(
// Set latest emojis.
status.Emojis = emojis
- // Iterate over and set changed emoji IDs.
+ // Extract IDs from latest slice of emojis.
status.EmojiIDs = make([]string, len(emojis))
for i, emoji := range emojis {
status.EmojiIDs[i] = emoji.ID
}
+ // Combine both old and new emojis, as statuses.emojis
+ // keeps track of emojis for both old and current edits.
+ status.EmojiIDs = append(status.EmojiIDs, existing.EmojiIDs...)
+ status.Emojis = append(status.Emojis, existing.Emojis...)
+ status.EmojiIDs = xslices.Deduplicate(status.EmojiIDs)
+ status.Emojis = xslices.DeduplicateFunc(status.Emojis,
+ func(e *gtsmodel.Emoji) string { return e.ID },
+ )
+
return true, nil
}
@@ -1118,10 +1128,10 @@ func (d *Dereferencer) handleStatusEdit(
var edited bool
// Preallocate max slice length.
- cols = make([]string, 0, 13)
+ cols = make([]string, 1, 13)
// Always update `fetched_at`.
- cols = append(cols, "fetched_at")
+ cols[0] = "fetched_at"
// Check for edited status content.
if existing.Content != status.Content {
@@ -1187,6 +1197,13 @@ func (d *Dereferencer) handleStatusEdit(
// Attached emojis changed.
cols = append(cols, "emojis") // i.e. EmojiIDs
+ // We specifically store both *new* AND *old* edit
+ // revision emojis in the statuses.emojis column.
+ emojiByID := func(e *gtsmodel.Emoji) string { return e.ID }
+ status.Emojis = append(status.Emojis, existing.Emojis...)
+ status.Emojis = xslices.DeduplicateFunc(status.Emojis, emojiByID)
+ status.EmojiIDs = xslices.Gather(status.EmojiIDs[:0], status.Emojis, emojiByID)
+
// Emojis changed doesn't necessarily
// indicate an edit, it may just not have
// been previously populated properly.
@@ -1230,7 +1247,8 @@ func (d *Dereferencer) handleStatusEdit(
// Poll only set if existing contained them.
edit.PollOptions = existing.Poll.Options
- if !*existing.Poll.HideCounts || pollChanged {
+ if pollChanged || !*existing.Poll.HideCounts ||
+ !existing.Poll.ClosedAt.IsZero() {
// If the counts are allowed to be
// shown, or poll has changed, then
// include poll vote counts in edit.