From 8cf685fbe949f11772b4901fe4e564e6be545864 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:41:40 +0200 Subject: [PATCH] [bugfix] Fix minor API issue w/ boosted statuses (#2846) --- .../api/client/statuses/statusboost_test.go | 4 ++ internal/typeutils/internaltofrontend.go | 41 +++++++++++++------ internal/typeutils/util.go | 4 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/internal/api/client/statuses/statusboost_test.go b/internal/api/client/statuses/statusboost_test.go index aea0e20e0..ae7c364bf 100644 --- a/internal/api/client/statuses/statusboost_test.go +++ b/internal/api/client/statuses/statusboost_test.go @@ -100,6 +100,8 @@ func (suite *StatusBoostTestSuite) TestPostBoost() { suite.Len(statusReply.Reblog.MediaAttachments, 1) suite.Len(statusReply.Reblog.Tags, 1) suite.Len(statusReply.Reblog.Emojis, 1) + suite.True(statusReply.Reblogged) + suite.True(statusReply.Reblog.Reblogged) suite.Equal("superseriousbusiness", statusReply.Reblog.Application.Name) } @@ -165,6 +167,8 @@ func (suite *StatusBoostTestSuite) TestPostBoostOwnFollowersOnly() { suite.Empty(responseStatus.Reblog.MediaAttachments) suite.Empty(responseStatus.Reblog.Tags) suite.Empty(responseStatus.Reblog.Emojis) + suite.True(responseStatus.Reblogged) + suite.True(responseStatus.Reblog.Reblogged) suite.Equal("really cool gts application", responseStatus.Reblog.Application.Name) } diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 94f2bcda4..fa704a5bb 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -838,14 +838,6 @@ func (c *Converter) statusToFrontend( return nil, gtserror.Newf("error counting faves: %w", err) } - interacts, err := c.interactionsWithStatusForAccount(ctx, s, requestingAccount) - if err != nil { - log.Errorf(ctx, "error getting interactions for status %s for account %s: %v", s.ID, requestingAccount.ID, err) - - // Ensure a non nil object - interacts = &statusInteractions{} - } - apiAttachments, err := c.convertAttachmentsToAPIAttachments(ctx, s.Attachments, s.AttachmentIDs) if err != nil { log.Errorf(ctx, "error converting status attachments: %v", err) @@ -880,11 +872,6 @@ func (c *Converter) statusToFrontend( RepliesCount: repliesCount, ReblogsCount: reblogsCount, FavouritesCount: favesCount, - Favourited: interacts.Faved, - Bookmarked: interacts.Bookmarked, - Muted: interacts.Muted, - Reblogged: interacts.Reblogged, - Pinned: interacts.Pinned, Content: s.Content, Reblog: nil, // Set below. Application: nil, // Set below. @@ -941,6 +928,34 @@ func (c *Converter) statusToFrontend( } } + // Status interactions. + // + // Take from boosted status if set, + // otherwise take from status itself. + if apiStatus.Reblog != nil { + apiStatus.Favourited = apiStatus.Reblog.Favourited + apiStatus.Bookmarked = apiStatus.Reblog.Bookmarked + apiStatus.Muted = apiStatus.Reblog.Muted + apiStatus.Reblogged = apiStatus.Reblog.Reblogged + apiStatus.Pinned = apiStatus.Reblog.Pinned + } else { + interacts, err := c.interactionsWithStatusForAccount(ctx, s, requestingAccount) + if err != nil { + log.Errorf(ctx, + "error getting interactions for status %s for account %s: %v", + s.ID, requestingAccount.ID, err, + ) + + // Ensure non-nil object. + interacts = new(statusInteractions) + } + apiStatus.Favourited = interacts.Favourited + apiStatus.Bookmarked = interacts.Bookmarked + apiStatus.Muted = interacts.Muted + apiStatus.Reblogged = interacts.Reblogged + apiStatus.Pinned = interacts.Pinned + } + // If web URL is empty for whatever // reason, provide AP URI as fallback. if s.URL == "" { diff --git a/internal/typeutils/util.go b/internal/typeutils/util.go index 0b7516d3a..da4109f67 100644 --- a/internal/typeutils/util.go +++ b/internal/typeutils/util.go @@ -36,7 +36,7 @@ import ( ) type statusInteractions struct { - Faved bool + Favourited bool Muted bool Bookmarked bool Reblogged bool @@ -51,7 +51,7 @@ func (c *Converter) interactionsWithStatusForAccount(ctx context.Context, s *gts if err != nil { return nil, fmt.Errorf("error checking if requesting account has faved status: %s", err) } - si.Faved = faved + si.Favourited = faved reblogged, err := c.state.DB.IsStatusBoostedBy(ctx, s.ID, requestingAccount.ID) if err != nil {