diff options
author | 2024-07-24 13:27:42 +0200 | |
---|---|---|
committer | 2024-07-24 12:27:42 +0100 | |
commit | c9b6220fef01dce80a31436660cd06b4e1db030f (patch) | |
tree | 5fbade865a920a5ea04fdd63763eca1880d60c5d /internal/typeutils/internaltofrontend.go | |
parent | [chore] renames the `GTS` caches to `DB` caches (#3127) (diff) | |
download | gotosocial-c9b6220fef01dce80a31436660cd06b4e1db030f.tar.xz |
[chore] Add interaction filter to complement existing visibility filter (#3111)
* [chore] Add interaction filter to complement existing visibility filter
* pass in ptr to visibility and interaction filters to Processor{} to ensure shared
* use int constants for for match type, cache db calls in filterctx
* function name typo :innocent:
---------
Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r-- | internal/typeutils/internaltofrontend.go | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 29d972e48..cbe746d2f 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -861,7 +861,7 @@ func (c *Converter) statusToAPIFilterResults( for _, account := range otherAccounts { // Is this account visible? - visible, err := c.filter.AccountVisible(ctx, requestingAccount, account) + visible, err := c.visFilter.AccountVisible(ctx, requestingAccount, account) if err != nil { return nil, err } @@ -2382,8 +2382,8 @@ func (c *Converter) ThemesToAPIThemes(themes []*gtsmodel.Theme) []apimodel.Theme func (c *Converter) InteractionPolicyToAPIInteractionPolicy( ctx context.Context, policy *gtsmodel.InteractionPolicy, - _ *gtsmodel.Status, // Used in upcoming PR. - _ *gtsmodel.Account, // Used in upcoming PR. + status *gtsmodel.Status, + requester *gtsmodel.Account, ) (*apimodel.InteractionPolicy, error) { apiPolicy := &apimodel.InteractionPolicy{ CanFavourite: apimodel.PolicyRules{ @@ -2400,6 +2400,75 @@ func (c *Converter) InteractionPolicyToAPIInteractionPolicy( }, } + if status == nil || requester == nil { + // We're done here! + return apiPolicy, nil + } + + // Status and requester are both defined, + // so we can add the "me" Value to the policy + // for each interaction type, if applicable. + + likeable, err := c.intFilter.StatusLikeable(ctx, requester, status) + if err != nil { + err := gtserror.Newf("error checking status likeable by requester: %w", err) + return nil, err + } + + if likeable.Permission == gtsmodel.PolicyPermissionPermitted { + // We can do this! + apiPolicy.CanFavourite.Always = append( + apiPolicy.CanFavourite.Always, + apimodel.PolicyValueMe, + ) + } else if likeable.Permission == gtsmodel.PolicyPermissionWithApproval { + // We can do this with approval. + apiPolicy.CanFavourite.WithApproval = append( + apiPolicy.CanFavourite.WithApproval, + apimodel.PolicyValueMe, + ) + } + + replyable, err := c.intFilter.StatusReplyable(ctx, requester, status) + if err != nil { + err := gtserror.Newf("error checking status replyable by requester: %w", err) + return nil, err + } + + if replyable.Permission == gtsmodel.PolicyPermissionPermitted { + // We can do this! + apiPolicy.CanReply.Always = append( + apiPolicy.CanReply.Always, + apimodel.PolicyValueMe, + ) + } else if replyable.Permission == gtsmodel.PolicyPermissionWithApproval { + // We can do this with approval. + apiPolicy.CanReply.WithApproval = append( + apiPolicy.CanReply.WithApproval, + apimodel.PolicyValueMe, + ) + } + + boostable, err := c.intFilter.StatusBoostable(ctx, requester, status) + if err != nil { + err := gtserror.Newf("error checking status boostable by requester: %w", err) + return nil, err + } + + if boostable.Permission == gtsmodel.PolicyPermissionPermitted { + // We can do this! + apiPolicy.CanReblog.Always = append( + apiPolicy.CanReblog.Always, + apimodel.PolicyValueMe, + ) + } else if boostable.Permission == gtsmodel.PolicyPermissionWithApproval { + // We can do this with approval. + apiPolicy.CanReblog.WithApproval = append( + apiPolicy.CanReblog.WithApproval, + apimodel.PolicyValueMe, + ) + } + return apiPolicy, nil } |