diff options
author | 2024-09-23 11:53:42 +0000 | |
---|---|---|
committer | 2024-09-23 11:53:42 +0000 | |
commit | 4592e290872e0208d03189aea4f410cd47a5dc1d (patch) | |
tree | 00df4221fc924e8fdcafc985f33c0395687a711c /internal/filter/visibility/status.go | |
parent | [chore] header filter improvements (#3329) (diff) | |
download | gotosocial-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/filter/visibility/status.go')
-rw-r--r-- | internal/filter/visibility/status.go | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/internal/filter/visibility/status.go b/internal/filter/visibility/status.go index be59e800e..a0f971464 100644 --- a/internal/filter/visibility/status.go +++ b/internal/filter/visibility/status.go @@ -104,18 +104,20 @@ func (f *Filter) isStatusVisible( return false, nil } - if util.PtrOrValue(status.PendingApproval, false) { + if util.PtrOrZero(status.PendingApproval) { // Use a different visibility heuristic // for pending approval statuses. - return f.isPendingStatusVisible(ctx, + return isPendingStatusVisible( requester, status, - ) + ), nil } if requester == nil { // Use a different visibility // heuristic for unauthed requests. - return f.isStatusVisibleUnauthed(ctx, status) + return f.isStatusVisibleUnauthed( + ctx, status, + ) } /* @@ -210,45 +212,42 @@ func (f *Filter) isStatusVisible( } } -func (f *Filter) isPendingStatusVisible( - _ context.Context, - requester *gtsmodel.Account, - status *gtsmodel.Status, -) (bool, error) { +// isPendingStatusVisible returns whether a status pending approval is visible to requester. +func isPendingStatusVisible(requester *gtsmodel.Account, status *gtsmodel.Status) bool { if requester == nil { // Any old tom, dick, and harry can't // see pending-approval statuses, // no matter what their visibility. - return false, nil + return false } if status.AccountID == requester.ID { // This is requester's status, // so they can always see it. - return true, nil + return true } if status.InReplyToAccountID == requester.ID { // This status replies to requester, // so they can always see it (else // they can't approve it). - return true, nil + return true } if status.BoostOfAccountID == requester.ID { // This status boosts requester, // so they can always see it. - return true, nil + return true } - // Nobody else can see this. - return false, nil + // Nobody else + // can see this. + return false } -func (f *Filter) isStatusVisibleUnauthed( - ctx context.Context, - status *gtsmodel.Status, -) (bool, error) { +// isStatusVisibleUnauthed returns whether status is visible without any unauthenticated account. +func (f *Filter) isStatusVisibleUnauthed(ctx context.Context, status *gtsmodel.Status) (bool, error) { + // For remote accounts, only show // Public statuses via the web. if status.Account.IsRemote() { @@ -275,8 +274,7 @@ func (f *Filter) isStatusVisibleUnauthed( } } - webVisibility := status.Account.Settings.WebVisibility - switch webVisibility { + switch webvis := status.Account.Settings.WebVisibility; webvis { // public_only: status must be Public. case gtsmodel.VisibilityPublic: @@ -296,7 +294,7 @@ func (f *Filter) isStatusVisibleUnauthed( default: return false, gtserror.Newf( "unrecognized web visibility for account %s: %s", - status.Account.ID, webVisibility, + status.Account.ID, webvis, ) } } |