summaryrefslogtreecommitdiff
path: root/internal/processing/common/status.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-09-23 11:53:42 +0000
committerLibravatar GitHub <noreply@github.com>2024-09-23 11:53:42 +0000
commit4592e290872e0208d03189aea4f410cd47a5dc1d (patch)
tree00df4221fc924e8fdcafc985f33c0395687a711c /internal/processing/common/status.go
parent[chore] header filter improvements (#3329) (diff)
downloadgotosocial-4592e290872e0208d03189aea4f410cd47a5dc1d.tar.xz
[chore] local instance count query caching, improved status context endpoint logging, don't log ErrHideStatus when timelining (#3330)
* ensure that errors checking status visibility / converting aren't dropped * add some more context to error messages * include calling function name in log entries * don't error on timelining hidden status * further code to ignore statusfilter.ErrHideStatus type errors * remove unused error type * add local instance status / domain / user counts * add checks for localhost * rename from InstanceCounts to LocalInstance * improved code comment
Diffstat (limited to 'internal/processing/common/status.go')
-rw-r--r--internal/processing/common/status.go76
1 files changed, 74 insertions, 2 deletions
diff --git a/internal/processing/common/status.go b/internal/processing/common/status.go
index a1d432eb0..dd83a2cc5 100644
--- a/internal/processing/common/status.go
+++ b/internal/processing/common/status.go
@@ -25,6 +25,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing"
statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
+ "github.com/superseriousbusiness/gotosocial/internal/filter/usermute"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
@@ -50,6 +51,7 @@ func (p *Processor) GetTargetStatusBy(
// Fetch the target status from db.
target, err := getTargetFromDB()
if err != nil && !errors.Is(err, db.ErrNoEntries) {
+ err := gtserror.Newf("error getting from db: %w", err)
return nil, false, gtserror.NewErrorInternalError(err)
}
@@ -65,6 +67,7 @@ func (p *Processor) GetTargetStatusBy(
// Check whether target status is visible to requesting account.
visible, err = p.visFilter.StatusVisible(ctx, requester, target)
if err != nil {
+ err := gtserror.Newf("error checking visibility: %w", err)
return nil, false, gtserror.NewErrorInternalError(err)
}
@@ -174,14 +177,83 @@ func (p *Processor) GetAPIStatus(
apiStatus *apimodel.Status,
errWithCode gtserror.WithCode,
) {
- apiStatus, err := p.converter.StatusToAPIStatus(ctx, target, requester, statusfilter.FilterContextNone, nil, nil)
+ apiStatus, err := p.converter.StatusToAPIStatus(ctx,
+ target,
+ requester,
+ statusfilter.FilterContextNone,
+ nil,
+ nil,
+ )
if err != nil {
- err = gtserror.Newf("error converting status: %w", err)
+ err := gtserror.Newf("error converting: %w", err)
return nil, gtserror.NewErrorInternalError(err)
}
return apiStatus, nil
}
+// GetVisibleAPIStatuses converts a slice of statuses to API
+// model statuses, filtering according to visibility to requester
+// along with given filter context, filters and user mutes.
+//
+// Please note that all errors will be logged at ERROR level,
+// but will not be returned. Callers are likely to run into
+// show-stopping errors in the lead-up to this function.
+func (p *Processor) GetVisibleAPIStatuses(
+ ctx context.Context,
+ requester *gtsmodel.Account,
+ statuses []*gtsmodel.Status,
+ filterContext statusfilter.FilterContext,
+ filters []*gtsmodel.Filter,
+ userMutes []*gtsmodel.UserMute,
+) []apimodel.Status {
+
+ // Start new log entry with
+ // the calling function name
+ // as a field in each entry.
+ l := log.WithContext(ctx).
+ WithField("caller", log.Caller(3))
+
+ // Compile mutes to useable user mutes for type converter.
+ compUserMutes := usermute.NewCompiledUserMuteList(userMutes)
+
+ // Iterate filtered statuses for conversion to API model.
+ apiStatuses := make([]apimodel.Status, 0, len(statuses))
+ for _, status := range statuses {
+
+ // Check whether status is visible to requester.
+ visible, err := p.visFilter.StatusVisible(ctx,
+ requester,
+ status,
+ )
+ if err != nil {
+ l.Errorf("error checking visibility: %v", err)
+ continue
+ }
+
+ if !visible {
+ continue
+ }
+
+ // Convert to API status, taking mute / filter into account.
+ apiStatus, err := p.converter.StatusToAPIStatus(ctx,
+ status,
+ requester,
+ filterContext,
+ filters,
+ compUserMutes,
+ )
+ if err != nil && !errors.Is(err, statusfilter.ErrHideStatus) {
+ l.Errorf("error converting: %v", err)
+ continue
+ }
+
+ // Append converted status to return slice.
+ apiStatuses = append(apiStatuses, *apiStatus)
+ }
+
+ return apiStatuses
+}
+
// InvalidateTimelinedStatus is a shortcut function for invalidating the cached
// representation one status in the home timeline and all list timelines of the
// given accountID. It should only be called in cases where a status update