mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 06:42:25 -05:00
[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
This commit is contained in:
parent
1aa7f70660
commit
fe8d5f2307
29 changed files with 2546 additions and 523 deletions
|
|
@ -66,7 +66,7 @@ var (
|
|||
// causing loads of dereferencing calls.
|
||||
Fresh = util.Ptr(FreshnessWindow(5 * time.Minute))
|
||||
|
||||
// 10 seconds.
|
||||
// 5 seconds.
|
||||
//
|
||||
// Freshest is useful when you want an
|
||||
// immediately up to date model of something
|
||||
|
|
@ -74,7 +74,7 @@ var (
|
|||
//
|
||||
// Be careful using this one; it can cause
|
||||
// lots of unnecessary traffic if used unwisely.
|
||||
Freshest = util.Ptr(FreshnessWindow(10 * time.Second))
|
||||
Freshest = util.Ptr(FreshnessWindow(5 * time.Second))
|
||||
)
|
||||
|
||||
// Dereferencer wraps logic and functionality for doing dereferencing
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue