[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 <kipvandenbos@noreply.codeberg.org>
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
kim 2025-06-16 13:12:48 +02:00 committed by kim
commit b1c0eca1d8

View file

@ -232,20 +232,25 @@ func (f *Filter) getStatusRelatedUserMutes(
return nil, nil return nil, nil
} }
if !status.MentionsPopulated() {
var err error
// Populate status mention objects before further mention checks.
status.Mentions, err = f.state.DB.GetMentions(ctx, status.MentionIDs)
if err != nil {
return nil, gtserror.Newf("error populating status %s mentions: %w", status.URI, err)
}
}
// Preallocate a slice of worst possible case no. user mutes. // Preallocate a slice of worst possible case no. user mutes.
mutes := make([]*gtsmodel.UserMute, 0, 2+len(status.Mentions)) mutes := make([]*gtsmodel.UserMute, 0, 2+len(status.Mentions))
// Look for mute against author. // 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( mute, err := f.state.DB.GetMute(
gtscontext.SetBarebones(ctx), gtscontext.SetBarebones(ctx),
requester.ID, requester.ID,
@ -260,22 +265,35 @@ func (f *Filter) getStatusRelatedUserMutes(
mutes = append(mutes, mute) mutes = append(mutes, mute)
} }
if status.BoostOfAccountID != "" { // From here look at details
// Look for mute against boost author. // for original boosted status.
status = status.BoostOf
}
if !status.MentionsPopulated() {
var err error
// Populate status mention objects before further mention checks.
status.Mentions, err = f.state.DB.GetMentions(ctx, status.MentionIDs)
if err != nil {
return nil, gtserror.Newf("error populating status %s mentions: %w", status.URI, err)
}
}
// Look for mute against author.
mute, err := f.state.DB.GetMute( mute, err := f.state.DB.GetMute(
gtscontext.SetBarebones(ctx), gtscontext.SetBarebones(ctx),
requester.ID, requester.ID,
status.AccountID, status.AccountID,
) )
if err != nil && !errors.Is(err, db.ErrNoEntries) { if err != nil && !errors.Is(err, db.ErrNoEntries) {
return nil, gtserror.Newf("db error getting boost author mute: %w", err) return nil, gtserror.Newf("db error getting status author mute: %w", err)
} }
if mute != nil { if mute != nil {
// Append author mute to total. // Append author mute to total.
mutes = append(mutes, mute) mutes = append(mutes, mute)
} }
}
for _, mention := range status.Mentions { for _, mention := range status.Mentions {
// Look for mute against any target mentions. // Look for mute against any target mentions.