From 66e1ec14aa07e115580afc8e1399677f3b54eeda Mon Sep 17 00:00:00 2001 From: kim Date: Fri, 4 Jul 2025 15:30:39 +0200 Subject: [chore] move status filtering from type converter (#4306) This finalizes the moving status filtering out of the type converter, and into its own `./internal/filter/` subpkg :) Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4306 Co-authored-by: kim Co-committed-by: kim --- internal/processing/conversations/update.go | 53 +++++++++++++++++------------ 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'internal/processing/conversations/update.go') diff --git a/internal/processing/conversations/update.go b/internal/processing/conversations/update.go index cf81d6906..21f1cf915 100644 --- a/internal/processing/conversations/update.go +++ b/internal/processing/conversations/update.go @@ -27,7 +27,6 @@ import ( "code.superseriousbusiness.org/gotosocial/internal/gtsmodel" "code.superseriousbusiness.org/gotosocial/internal/id" "code.superseriousbusiness.org/gotosocial/internal/log" - "code.superseriousbusiness.org/gotosocial/internal/typeutils" "code.superseriousbusiness.org/gotosocial/internal/util" ) @@ -158,26 +157,6 @@ func (p *Processor) UpdateConversationsForStatus(ctx context.Context, status *gt continue } - // Convert the conversation to API representation. - apiConversation, err := p.converter.ConversationToAPIConversation(ctx, - conversation, - localAccount, - nil, - ) - if err != nil { - // If the conversation's last status matched a hide filter, skip it. - // If there was another kind of error, log that and skip it anyway. - if !errors.Is(err, typeutils.ErrHideStatus) { - log.Errorf(ctx, - "error converting conversation %s to API representation for account %s: %v", - status.ID, - localAccount.ID, - err, - ) - } - continue - } - // If status was authored by this participant, // don't bother notifying, they already know! if status.AccountID == localAccount.ID { @@ -198,6 +177,38 @@ func (p *Processor) UpdateConversationsForStatus(ctx context.Context, status *gt continue } + // Check whether status if filtered by local participant in context. + filtered, hide, err := p.statusFilter.StatusFilterResultsInContext(ctx, + localAccount, + status, + gtsmodel.FilterContextNotifications, + ) + if err != nil { + log.Errorf(ctx, "error filtering status: %v", err) + continue + } + + if hide { + continue + } + + // Convert the conversation to API representation. + apiConversation, err := p.converter.ConversationToAPIConversation(ctx, + conversation, + localAccount, + ) + if err != nil { + log.Errorf(ctx, "error converting conversation %s to API representation for account %s: %v", + status.ID, + localAccount.ID, + err, + ) + continue + } + + // Set filter results on attached status model. + apiConversation.LastStatus.Filtered = filtered + // Generate a notification, notifications = append(notifications, ConversationNotification{ AccountID: localAccount.ID, -- cgit v1.2.3