Skip to content

Commit

Permalink
[bugfix] Fix minor API issue w/ boosted statuses (superseriousbusines…
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmethurst authored and nyarla committed Jun 19, 2024
1 parent c54aadb commit 3a5785e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
4 changes: 4 additions & 0 deletions internal/api/client/statuses/statusboost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
41 changes: 28 additions & 13 deletions internal/typeutils/internaltofrontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 == "" {
Expand Down
4 changes: 2 additions & 2 deletions internal/typeutils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

type statusInteractions struct {
Faved bool
Favourited bool
Muted bool
Bookmarked bool
Reblogged bool
Expand All @@ -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 {
Expand Down

0 comments on commit 3a5785e

Please sign in to comment.