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/timeline/notification.go | 35 ++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'internal/processing/timeline/notification.go') diff --git a/internal/processing/timeline/notification.go b/internal/processing/timeline/notification.go index 784b2b824..b17dda8a7 100644 --- a/internal/processing/timeline/notification.go +++ b/internal/processing/timeline/notification.go @@ -31,7 +31,6 @@ import ( "code.superseriousbusiness.org/gotosocial/internal/gtsmodel" "code.superseriousbusiness.org/gotosocial/internal/log" "code.superseriousbusiness.org/gotosocial/internal/paging" - "code.superseriousbusiness.org/gotosocial/internal/typeutils" "code.superseriousbusiness.org/gotosocial/internal/util" ) @@ -93,8 +92,12 @@ func (p *Processor) NotificationsGet( continue } + var filtered []apimodel.FilterResult + if n.Status != nil { - // A status is attached, check whether status muted. + var hide bool + + // Check whether notification status is muted by requester. muted, err = p.muteFilter.StatusNotificationsMuted(ctx, requester, n.Status, @@ -107,16 +110,34 @@ func (p *Processor) NotificationsGet( if muted { continue } + + // Check whether notification status is filtered by requester in notifs. + filtered, hide, err = p.statusFilter.StatusFilterResultsInContext(ctx, + requester, + n.Status, + gtsmodel.FilterContextNotifications, + ) + if err != nil { + log.Errorf(ctx, "error checking status filtering: %v", err) + continue + } + + if hide { + continue + } } - item, err := p.converter.NotificationToAPINotification(ctx, n, true) + item, err := p.converter.NotificationToAPINotification(ctx, n) if err != nil { - if !errors.Is(err, typeutils.ErrHideStatus) { - log.Debugf(ctx, "skipping notification %s because it couldn't be converted to its api representation: %s", n.ID, err) - } continue } + if item.Status != nil { + // Set filter results on status, + // in case any were set above. + item.Status.Filtered = filtered + } + items = append(items, item) } @@ -154,7 +175,7 @@ func (p *Processor) NotificationGet(ctx context.Context, account *gtsmodel.Accou // or mute checking for a notification directly // fetched by ID. only from timelines etc. - apiNotif, err := p.converter.NotificationToAPINotification(ctx, notif, false) + apiNotif, err := p.converter.NotificationToAPINotification(ctx, notif) if err != nil { err := gtserror.Newf("error converting to api model: %w", err) return nil, gtserror.WrapWithCode(http.StatusInternalServerError, err) -- cgit v1.2.3