summaryrefslogtreecommitdiff
path: root/internal/processing/timeline
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing/timeline')
-rw-r--r--internal/processing/timeline/faved.go3
-rw-r--r--internal/processing/timeline/notification.go35
-rw-r--r--internal/processing/timeline/timeline.go47
-rw-r--r--internal/processing/timeline/timeline_test.go2
4 files changed, 66 insertions, 21 deletions
diff --git a/internal/processing/timeline/faved.go b/internal/processing/timeline/faved.go
index 65b23c702..9218af9c8 100644
--- a/internal/processing/timeline/faved.go
+++ b/internal/processing/timeline/faved.go
@@ -26,7 +26,6 @@ import (
apiutil "code.superseriousbusiness.org/gotosocial/internal/api/util"
"code.superseriousbusiness.org/gotosocial/internal/db"
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
- "code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/log"
"code.superseriousbusiness.org/gotosocial/internal/util"
)
@@ -56,7 +55,7 @@ func (p *Processor) FavedTimelineGet(ctx context.Context, authed *apiutil.Auth,
continue
}
- apiStatus, err := p.converter.StatusToAPIStatus(ctx, s, authed.Account, gtsmodel.FilterContextNone)
+ apiStatus, err := p.converter.StatusToAPIStatus(ctx, s, authed.Account)
if err != nil {
log.Errorf(ctx, "error convering to api status: %v", err)
continue
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)
diff --git a/internal/processing/timeline/timeline.go b/internal/processing/timeline/timeline.go
index 64d33e430..06580b3c7 100644
--- a/internal/processing/timeline/timeline.go
+++ b/internal/processing/timeline/timeline.go
@@ -19,13 +19,13 @@ package timeline
import (
"context"
- "errors"
"net/http"
"net/url"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
timelinepkg "code.superseriousbusiness.org/gotosocial/internal/cache/timeline"
"code.superseriousbusiness.org/gotosocial/internal/filter/mutes"
+ "code.superseriousbusiness.org/gotosocial/internal/filter/status"
"code.superseriousbusiness.org/gotosocial/internal/filter/visibility"
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
@@ -46,18 +46,26 @@ var (
)
type Processor struct {
- state *state.State
- converter *typeutils.Converter
- visFilter *visibility.Filter
- muteFilter *mutes.Filter
+ state *state.State
+ converter *typeutils.Converter
+ visFilter *visibility.Filter
+ muteFilter *mutes.Filter
+ statusFilter *status.Filter
}
-func New(state *state.State, converter *typeutils.Converter, visFilter *visibility.Filter, muteFilter *mutes.Filter) Processor {
+func New(
+ state *state.State,
+ converter *typeutils.Converter,
+ visFilter *visibility.Filter,
+ muteFilter *mutes.Filter,
+ statusFilter *status.Filter,
+) Processor {
return Processor{
- state: state,
- converter: converter,
- visFilter: visFilter,
- muteFilter: muteFilter,
+ state: state,
+ converter: converter,
+ visFilter: visFilter,
+ muteFilter: muteFilter,
+ statusFilter: statusFilter,
}
}
@@ -116,15 +124,30 @@ func (p *Processor) getStatusTimeline(
return nil, nil
}
+ // Check whether this status is filtered by requester in this context.
+ filters, hide, err := p.statusFilter.StatusFilterResultsInContext(ctx,
+ requester,
+ status,
+ filterCtx,
+ )
+ if err != nil {
+ return nil, err
+ } else if hide {
+ return nil, nil
+ }
+
// Finally, pass status to get converted to API model.
apiStatus, err := p.converter.StatusToAPIStatus(ctx,
status,
requester,
- filterCtx,
)
- if err != nil && !errors.Is(err, typeutils.ErrHideStatus) {
+ if err != nil {
return nil, err
}
+
+ // Set any filters on status.
+ apiStatus.Filtered = filters
+
return apiStatus, nil
},
)
diff --git a/internal/processing/timeline/timeline_test.go b/internal/processing/timeline/timeline_test.go
index 01197b767..ce7817df6 100644
--- a/internal/processing/timeline/timeline_test.go
+++ b/internal/processing/timeline/timeline_test.go
@@ -21,6 +21,7 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/admin"
"code.superseriousbusiness.org/gotosocial/internal/db"
"code.superseriousbusiness.org/gotosocial/internal/filter/mutes"
+ "code.superseriousbusiness.org/gotosocial/internal/filter/status"
"code.superseriousbusiness.org/gotosocial/internal/filter/visibility"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/processing/timeline"
@@ -64,6 +65,7 @@ func (suite *TimelineStandardTestSuite) SetupTest() {
typeutils.NewConverter(&suite.state),
visibility.NewFilter(&suite.state),
mutes.NewFilter(&suite.state),
+ status.NewFilter(&suite.state),
)
testrig.StandardDBSetup(suite.db, suite.testAccounts)