mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-30 18:32:24 -05:00
[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 😇
---------
Co-authored-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
63fc9b6c3e
commit
c9b6220fef
61 changed files with 1661 additions and 585 deletions
|
|
@ -66,7 +66,7 @@ func (p *Processor) BoostCreate(
|
|||
}
|
||||
|
||||
// Ensure valid boost target for requester.
|
||||
boostable, err := p.filter.StatusBoostable(ctx,
|
||||
policyResult, err := p.intFilter.StatusBoostable(ctx,
|
||||
requester,
|
||||
target,
|
||||
)
|
||||
|
|
@ -75,12 +75,14 @@ func (p *Processor) BoostCreate(
|
|||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
if !boostable {
|
||||
err := gtserror.New("status is not boostable")
|
||||
return nil, gtserror.NewErrorNotFound(err)
|
||||
if policyResult.Forbidden() {
|
||||
const errText = "you do not have permission to boost this status"
|
||||
err := gtserror.New(errText)
|
||||
return nil, gtserror.NewErrorForbidden(err, errText)
|
||||
}
|
||||
|
||||
// Status is visible and boostable.
|
||||
// Status is visible and boostable
|
||||
// (though maybe pending approval).
|
||||
boost, err := p.converter.StatusToBoost(ctx,
|
||||
target,
|
||||
requester,
|
||||
|
|
@ -90,6 +92,29 @@ func (p *Processor) BoostCreate(
|
|||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
// Derive pendingApproval status.
|
||||
var pendingApproval bool
|
||||
switch {
|
||||
case policyResult.WithApproval():
|
||||
// We're allowed to do
|
||||
// this pending approval.
|
||||
pendingApproval = true
|
||||
|
||||
case policyResult.MatchedOnCollection():
|
||||
// We're permitted to do this, but since
|
||||
// we matched due to presence in a followers
|
||||
// or following collection, we should mark
|
||||
// as pending approval and wait for an accept.
|
||||
pendingApproval = true
|
||||
|
||||
case policyResult.Permitted():
|
||||
// We're permitted to do this
|
||||
// based on another kind of match.
|
||||
pendingApproval = false
|
||||
}
|
||||
|
||||
boost.PendingApproval = &pendingApproval
|
||||
|
||||
// Store the new boost.
|
||||
if err := p.state.DB.PutStatus(ctx, boost); err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
|
|
@ -184,7 +209,7 @@ func (p *Processor) StatusBoostedBy(ctx context.Context, requestingAccount *gtsm
|
|||
targetStatus = boostedStatus
|
||||
}
|
||||
|
||||
visible, err := p.filter.StatusVisible(ctx, requestingAccount, targetStatus)
|
||||
visible, err := p.visFilter.StatusVisible(ctx, requestingAccount, targetStatus)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("BoostedBy: error seeing if status %s is visible: %s", targetStatus.ID, err)
|
||||
return nil, gtserror.NewErrorNotFound(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue