ensure we filter home timeline statuses on local only

This commit is contained in:
kim 2025-04-25 16:09:09 +01:00
commit c92bb83298
5 changed files with 46 additions and 14 deletions

View file

@ -40,6 +40,20 @@ func (p *Processor) HomeTimelineGet(
*apimodel.PageableResponse, *apimodel.PageableResponse,
gtserror.WithCode, gtserror.WithCode,
) { ) {
var pageQuery url.Values
var postFilter func(*gtsmodel.Status) bool
if local {
// Set local = true query.
pageQuery = localOnlyTrue
postFilter = func(s *gtsmodel.Status) bool {
return *s.Local
}
} else {
// Set local = false query.
pageQuery = localOnlyFalse
postFilter = nil
}
return p.getStatusTimeline(ctx, return p.getStatusTimeline(ctx,
// Auth'd // Auth'd
@ -60,19 +74,7 @@ func (p *Processor) HomeTimelineGet(
// page query flag, (this map // page query flag, (this map
// later gets copied before // later gets copied before
// any further usage). // any further usage).
func() url.Values { pageQuery,
var pageQuery url.Values
if local {
// Set local = true query.
pageQuery = localOnlyTrue
} else {
// Set local = false query.
pageQuery = localOnlyFalse
}
return pageQuery
}(),
// Status filter context. // Status filter context.
statusfilter.FilterContextHome, statusfilter.FilterContextHome,
@ -82,7 +84,7 @@ func (p *Processor) HomeTimelineGet(
return p.state.DB.GetHomeTimeline(ctx, requester.ID, pg) return p.state.DB.GetHomeTimeline(ctx, requester.ID, pg)
}, },
// Pre-filtering function, // Filtering function,
// i.e. filter before caching. // i.e. filter before caching.
func(s *gtsmodel.Status) bool { func(s *gtsmodel.Status) bool {
@ -93,5 +95,9 @@ func (p *Processor) HomeTimelineGet(
} }
return !ok return !ok
}, },
// Post filtering funtion,
// i.e. filter after caching.
postFilter,
) )
} }

View file

@ -106,5 +106,9 @@ func (p *Processor) ListTimelineGet(
} }
return !ok return !ok
}, },
// Post filtering funtion,
// i.e. filter after caching.
nil,
) )
} }

View file

@ -97,6 +97,10 @@ func (p *Processor) publicTimelineGet(
} }
return !ok return !ok
}, },
// Post filtering funtion,
// i.e. filter after caching.
nil,
) )
} }
@ -149,5 +153,9 @@ func (p *Processor) localTimelineGet(
} }
return !ok return !ok
}, },
// Post filtering funtion,
// i.e. filter after caching.
nil,
) )
} }

View file

@ -105,6 +105,10 @@ func (p *Processor) TagTimelineGet(
} }
return !ok return !ok
}, },
// Post filtering funtion,
// i.e. filter after caching.
nil,
) )
} }

View file

@ -71,6 +71,7 @@ func (p *Processor) getStatusTimeline(
filterCtx statusfilter.FilterContext, filterCtx statusfilter.FilterContext,
loadPage func(*paging.Page) (statuses []*gtsmodel.Status, err error), loadPage func(*paging.Page) (statuses []*gtsmodel.Status, err error),
filter func(*gtsmodel.Status) (delete bool), filter func(*gtsmodel.Status) (delete bool),
postFilter func(*gtsmodel.Status) (remove bool),
) ( ) (
*apimodel.PageableResponse, *apimodel.PageableResponse,
gtserror.WithCode, gtserror.WithCode,
@ -133,6 +134,15 @@ func (p *Processor) getStatusTimeline(
// Frontend API model preparation function. // Frontend API model preparation function.
func(status *gtsmodel.Status) (*apimodel.Status, error) { func(status *gtsmodel.Status) (*apimodel.Status, error) {
// Check if status needs filtering OUTSIDE of caching stage.
// TODO: this will be moved to separate postFilter hook when
// all filtering has been removed from the type converter.
if postFilter != nil && postFilter(status) {
return nil, nil
}
// Finally, pass status to get converted to API model.
apiStatus, err := p.converter.StatusToAPIStatus(ctx, apiStatus, err := p.converter.StatusToAPIStatus(ctx,
status, status,
requester, requester,