From b1c0eca1d82f4a63c7a8c8cadec3cc7d59564cf1 Mon Sep 17 00:00:00 2001 From: kim Date: Mon, 16 Jun 2025 13:12:48 +0200 Subject: [PATCH] [bugfix] improved mute checking for boosted statuses (#4276) This unwraps and follows the boosted status to do a full mute check on the original. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4276 Reviewed-by: tobi Co-authored-by: kim Co-committed-by: kim --- internal/filter/mutes/status.go | 58 +++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/internal/filter/mutes/status.go b/internal/filter/mutes/status.go index e2ef1e5a5..04789d798 100644 --- a/internal/filter/mutes/status.go +++ b/internal/filter/mutes/status.go @@ -232,6 +232,44 @@ func (f *Filter) getStatusRelatedUserMutes( return nil, nil } + // Preallocate a slice of worst possible case no. user mutes. + mutes := make([]*gtsmodel.UserMute, 0, 2+len(status.Mentions)) + + // Check if status is boost. + if status.BoostOfID != "" { + if status.BoostOf == nil { + var err error + + // Ensure original status is loaded on boost. + status.BoostOf, err = f.state.DB.GetStatusByID( + gtscontext.SetBarebones(ctx), + status.BoostOfID, + ) + if err != nil { + return nil, gtserror.Newf("error getting boosted status of %s: %w", status.URI, err) + } + } + + // Look for mute against booster. + mute, err := f.state.DB.GetMute( + gtscontext.SetBarebones(ctx), + requester.ID, + status.AccountID, + ) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + return nil, gtserror.Newf("db error getting status author mute: %w", err) + } + + if mute != nil { + // Append author mute to total. + mutes = append(mutes, mute) + } + + // From here look at details + // for original boosted status. + status = status.BoostOf + } + if !status.MentionsPopulated() { var err error @@ -242,9 +280,6 @@ func (f *Filter) getStatusRelatedUserMutes( } } - // Preallocate a slice of worst possible case no. user mutes. - mutes := make([]*gtsmodel.UserMute, 0, 2+len(status.Mentions)) - // Look for mute against author. mute, err := f.state.DB.GetMute( gtscontext.SetBarebones(ctx), @@ -260,23 +295,6 @@ func (f *Filter) getStatusRelatedUserMutes( mutes = append(mutes, mute) } - if status.BoostOfAccountID != "" { - // Look for mute against boost author. - mute, err := f.state.DB.GetMute( - gtscontext.SetBarebones(ctx), - requester.ID, - status.AccountID, - ) - if err != nil && !errors.Is(err, db.ErrNoEntries) { - return nil, gtserror.Newf("db error getting boost author mute: %w", err) - } - - if mute != nil { - // Append author mute to total. - mutes = append(mutes, mute) - } - } - for _, mention := range status.Mentions { // Look for mute against any target mentions. if mention.TargetAccountID != requester.ID {