diff options
author | 2021-08-25 15:34:33 +0200 | |
---|---|---|
committer | 2021-08-25 15:34:33 +0200 | |
commit | 2dc9fc1626507bb54417fc4a1920b847cafb27a2 (patch) | |
tree | 4ddeac479b923db38090aac8bd9209f3646851c1 /internal/visibility | |
parent | Manually approves followers (#146) (diff) | |
download | gotosocial-2dc9fc1626507bb54417fc4a1920b847cafb27a2.tar.xz |
Pg to bun (#148)
* start moving to bun
* changing more stuff
* more
* and yet more
* tests passing
* seems stable now
* more big changes
* small fix
* little fixes
Diffstat (limited to 'internal/visibility')
-rw-r--r-- | internal/visibility/filter.go | 8 | ||||
-rw-r--r-- | internal/visibility/relevantaccounts.go | 17 | ||||
-rw-r--r-- | internal/visibility/statushometimelineable.go | 11 | ||||
-rw-r--r-- | internal/visibility/statuspublictimelineable.go | 5 | ||||
-rw-r--r-- | internal/visibility/statusvisible.go | 29 |
5 files changed, 38 insertions, 32 deletions
diff --git a/internal/visibility/filter.go b/internal/visibility/filter.go index 2c43fa4ee..644e85b35 100644 --- a/internal/visibility/filter.go +++ b/internal/visibility/filter.go @@ -19,6 +19,8 @@ package visibility import ( + "context" + "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -29,17 +31,17 @@ type Filter interface { // StatusVisible returns true if targetStatus is visible to requestingAccount, based on the // privacy settings of the status, and any blocks/mutes that might exist between the two accounts // or account domains, and other relevant accounts mentioned in or replied to by the status. - StatusVisible(targetStatus *gtsmodel.Status, requestingAccount *gtsmodel.Account) (bool, error) + StatusVisible(ctx context.Context, targetStatus *gtsmodel.Status, requestingAccount *gtsmodel.Account) (bool, error) // StatusHometimelineable returns true if targetStatus should be in the home timeline of the requesting account. // // This function will call StatusVisible internally, so it's not necessary to call it beforehand. - StatusHometimelineable(targetStatus *gtsmodel.Status, requestingAccount *gtsmodel.Account) (bool, error) + StatusHometimelineable(ctx context.Context, targetStatus *gtsmodel.Status, requestingAccount *gtsmodel.Account) (bool, error) // StatusPublictimelineable returns true if targetStatus should be in the public timeline of the requesting account. // // This function will call StatusVisible internally, so it's not necessary to call it beforehand. - StatusPublictimelineable(targetStatus *gtsmodel.Status, timelineOwnerAccount *gtsmodel.Account) (bool, error) + StatusPublictimelineable(ctx context.Context, targetStatus *gtsmodel.Status, timelineOwnerAccount *gtsmodel.Account) (bool, error) } type filter struct { diff --git a/internal/visibility/relevantaccounts.go b/internal/visibility/relevantaccounts.go index 5957d3111..d19d26ff4 100644 --- a/internal/visibility/relevantaccounts.go +++ b/internal/visibility/relevantaccounts.go @@ -19,6 +19,7 @@ package visibility import ( + "context" "errors" "fmt" @@ -41,7 +42,7 @@ type relevantAccounts struct { BoostedMentionedAccounts []*gtsmodel.Account } -func (f *filter) relevantAccounts(status *gtsmodel.Status, getBoosted bool) (*relevantAccounts, error) { +func (f *filter) relevantAccounts(ctx context.Context, status *gtsmodel.Status, getBoosted bool) (*relevantAccounts, error) { relAccts := &relevantAccounts{ MentionedAccounts: []*gtsmodel.Account{}, BoostedMentionedAccounts: []*gtsmodel.Account{}, @@ -77,7 +78,7 @@ func (f *filter) relevantAccounts(status *gtsmodel.Status, getBoosted bool) (*re relAccts.Account = status.Account } else { // it wasn't set, so get it from the db - account, err := f.db.GetAccountByID(status.AccountID) + account, err := f.db.GetAccountByID(ctx, status.AccountID) if err != nil { return nil, fmt.Errorf("relevantAccounts: error getting account with id %s: %s", status.AccountID, err) } @@ -96,7 +97,7 @@ func (f *filter) relevantAccounts(status *gtsmodel.Status, getBoosted bool) (*re relAccts.InReplyToAccount = status.InReplyToAccount } else { // it wasn't set, so get it from the db - inReplyToAccount, err := f.db.GetAccountByID(status.InReplyToAccountID) + inReplyToAccount, err := f.db.GetAccountByID(ctx, status.InReplyToAccountID) if err != nil { return nil, fmt.Errorf("relevantAccounts: error getting inReplyToAccount with id %s: %s", status.InReplyToAccountID, err) } @@ -115,7 +116,7 @@ func (f *filter) relevantAccounts(status *gtsmodel.Status, getBoosted bool) (*re } if !idIn(mID, status.Mentions) { // mention with ID isn't in status.Mentions - mention, err := f.db.GetMention(mID) + mention, err := f.db.GetMention(ctx, mID) if err != nil { return nil, fmt.Errorf("relevantAccounts: error getting mention with id %s: %s", mID, err) } @@ -146,7 +147,7 @@ func (f *filter) relevantAccounts(status *gtsmodel.Status, getBoosted bool) (*re // 4, 5, 6. Boosted status items // get the boosted status if it's not set on the status already if status.BoostOfID != "" && status.BoostOf == nil { - boostedStatus, err := f.db.GetStatusByID(status.BoostOfID) + boostedStatus, err := f.db.GetStatusByID(ctx, status.BoostOfID) if err != nil { return nil, fmt.Errorf("relevantAccounts: error getting boosted status with id %s: %s", status.BoostOfID, err) } @@ -155,7 +156,7 @@ func (f *filter) relevantAccounts(status *gtsmodel.Status, getBoosted bool) (*re if status.BoostOf != nil { // return relevant accounts for the boosted status - boostedRelAccts, err := f.relevantAccounts(status.BoostOf, false) // false because we don't want to recurse + boostedRelAccts, err := f.relevantAccounts(ctx, status.BoostOf, false) // false because we don't want to recurse if err != nil { return nil, fmt.Errorf("relevantAccounts: error getting relevant accounts of boosted status %s: %s", status.BoostOf.ID, err) } @@ -170,7 +171,7 @@ func (f *filter) relevantAccounts(status *gtsmodel.Status, getBoosted bool) (*re // domainBlockedRelevant checks through all relevant accounts attached to a status // to make sure none of them are domain blocked by this instance. -func (f *filter) domainBlockedRelevant(r *relevantAccounts) (bool, error) { +func (f *filter) domainBlockedRelevant(ctx context.Context, r *relevantAccounts) (bool, error) { domains := []string{} if r.Account != nil { @@ -201,7 +202,7 @@ func (f *filter) domainBlockedRelevant(r *relevantAccounts) (bool, error) { } } - return f.db.AreDomainsBlocked(domains) + return f.db.AreDomainsBlocked(ctx, domains) } func idIn(id string, mentions []*gtsmodel.Mention) bool { diff --git a/internal/visibility/statushometimelineable.go b/internal/visibility/statushometimelineable.go index a3ca62fb3..dd0ca079b 100644 --- a/internal/visibility/statushometimelineable.go +++ b/internal/visibility/statushometimelineable.go @@ -19,13 +19,14 @@ package visibility import ( + "context" "fmt" "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (f *filter) StatusHometimelineable(targetStatus *gtsmodel.Status, timelineOwnerAccount *gtsmodel.Account) (bool, error) { +func (f *filter) StatusHometimelineable(ctx context.Context, targetStatus *gtsmodel.Status, timelineOwnerAccount *gtsmodel.Account) (bool, error) { l := f.log.WithFields(logrus.Fields{ "func": "StatusHometimelineable", "statusID": targetStatus.ID, @@ -36,7 +37,7 @@ func (f *filter) StatusHometimelineable(targetStatus *gtsmodel.Status, timelineO return true, nil } - v, err := f.StatusVisible(targetStatus, timelineOwnerAccount) + v, err := f.StatusVisible(ctx, targetStatus, timelineOwnerAccount) if err != nil { return false, fmt.Errorf("StatusHometimelineable: error checking visibility of status with id %s: %s", targetStatus.ID, err) } @@ -63,7 +64,7 @@ func (f *filter) StatusHometimelineable(targetStatus *gtsmodel.Status, timelineO if targetStatus.InReplyToID != "" { // pin the reply to status on to this status if it hasn't been done already if targetStatus.InReplyTo == nil { - rs, err := f.db.GetStatusByID(targetStatus.InReplyToID) + rs, err := f.db.GetStatusByID(ctx, targetStatus.InReplyToID) if err != nil { return false, fmt.Errorf("StatusHometimelineable: error getting replied to status with id %s: %s", targetStatus.InReplyToID, err) } @@ -72,7 +73,7 @@ func (f *filter) StatusHometimelineable(targetStatus *gtsmodel.Status, timelineO // pin the reply to account on to this status if it hasn't been done already if targetStatus.InReplyToAccount == nil { - ra, err := f.db.GetAccountByID(targetStatus.InReplyToAccountID) + ra, err := f.db.GetAccountByID(ctx, targetStatus.InReplyToAccountID) if err != nil { return false, fmt.Errorf("StatusHometimelineable: error getting replied to account with id %s: %s", targetStatus.InReplyToAccountID, err) } @@ -85,7 +86,7 @@ func (f *filter) StatusHometimelineable(targetStatus *gtsmodel.Status, timelineO } // the replied-to account != timelineOwnerAccount, so make sure the timelineOwnerAccount follows the replied-to account - follows, err := f.db.IsFollowing(timelineOwnerAccount, targetStatus.InReplyToAccount) + follows, err := f.db.IsFollowing(ctx, timelineOwnerAccount, targetStatus.InReplyToAccount) if err != nil { return false, fmt.Errorf("StatusHometimelineable: error checking follow from account %s to account %s: %s", timelineOwnerAccount.ID, targetStatus.InReplyToAccountID, err) } diff --git a/internal/visibility/statuspublictimelineable.go b/internal/visibility/statuspublictimelineable.go index f07e06aae..8d0a7aa28 100644 --- a/internal/visibility/statuspublictimelineable.go +++ b/internal/visibility/statuspublictimelineable.go @@ -19,13 +19,14 @@ package visibility import ( + "context" "fmt" "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (f *filter) StatusPublictimelineable(targetStatus *gtsmodel.Status, timelineOwnerAccount *gtsmodel.Account) (bool, error) { +func (f *filter) StatusPublictimelineable(ctx context.Context, targetStatus *gtsmodel.Status, timelineOwnerAccount *gtsmodel.Account) (bool, error) { l := f.log.WithFields(logrus.Fields{ "func": "StatusPublictimelineable", "statusID": targetStatus.ID, @@ -41,7 +42,7 @@ func (f *filter) StatusPublictimelineable(targetStatus *gtsmodel.Status, timelin return true, nil } - v, err := f.StatusVisible(targetStatus, timelineOwnerAccount) + v, err := f.StatusVisible(ctx, targetStatus, timelineOwnerAccount) if err != nil { return false, fmt.Errorf("StatusPublictimelineable: error checking visibility of status with id %s: %s", targetStatus.ID, err) } diff --git a/internal/visibility/statusvisible.go b/internal/visibility/statusvisible.go index 15e545881..5b6fe0c1e 100644 --- a/internal/visibility/statusvisible.go +++ b/internal/visibility/statusvisible.go @@ -19,6 +19,7 @@ package visibility import ( + "context" "errors" "fmt" @@ -28,20 +29,20 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount *gtsmodel.Account) (bool, error) { +func (f *filter) StatusVisible(ctx context.Context, targetStatus *gtsmodel.Status, requestingAccount *gtsmodel.Account) (bool, error) { l := f.log.WithFields(logrus.Fields{ "func": "StatusVisible", "statusID": targetStatus.ID, }) getBoosted := true - relevantAccounts, err := f.relevantAccounts(targetStatus, getBoosted) + relevantAccounts, err := f.relevantAccounts(ctx, targetStatus, getBoosted) if err != nil { l.Debugf("error pulling relevant accounts for status %s: %s", targetStatus.ID, err) return false, fmt.Errorf("StatusVisible: error pulling relevant accounts for status %s: %s", targetStatus.ID, err) } - domainBlocked, err := f.domainBlockedRelevant(relevantAccounts) + domainBlocked, err := f.domainBlockedRelevant(ctx, relevantAccounts) if err != nil { l.Debugf("error checking domain block: %s", err) return false, fmt.Errorf("error checking domain block: %s", err) @@ -67,7 +68,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount // note: we only do this for local users if targetAccount.Domain == "" { targetUser := >smodel.User{} - if err := f.db.GetWhere([]db.Where{{Key: "account_id", Value: targetAccount.ID}}, targetUser); err != nil { + if err := f.db.GetWhere(ctx, []db.Where{{Key: "account_id", Value: targetAccount.ID}}, targetUser); err != nil { l.Debug("target user could not be selected") if err == db.ErrNoEntries { return false, nil @@ -97,7 +98,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount // note: we only do this for local users if requestingAccount.Domain == "" { requestingUser := >smodel.User{} - if err := f.db.GetWhere([]db.Where{{Key: "account_id", Value: requestingAccount.ID}}, requestingUser); err != nil { + if err := f.db.GetWhere(ctx, []db.Where{{Key: "account_id", Value: requestingAccount.ID}}, requestingUser); err != nil { // if the requesting account is local but doesn't have a corresponding user in the db this is a problem l.Debug("requesting user could not be selected") if err == db.ErrNoEntries { @@ -126,7 +127,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount // At this point we have a populated targetAccount, targetStatus, and requestingAccount, so we can check for blocks and whathaveyou // First check if a block exists directly between the target account (which authored the status) and the requesting account. - if blocked, err := f.db.IsBlocked(targetAccount.ID, requestingAccount.ID, true); err != nil { + if blocked, err := f.db.IsBlocked(ctx, targetAccount.ID, requestingAccount.ID, true); err != nil { l.Debugf("something went wrong figuring out if the accounts have a block: %s", err) return false, err } else if blocked { @@ -137,7 +138,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount // status replies to account id if relevantAccounts.InReplyToAccount != nil && relevantAccounts.InReplyToAccount.ID != requestingAccount.ID { - if blocked, err := f.db.IsBlocked(relevantAccounts.InReplyToAccount.ID, requestingAccount.ID, true); err != nil { + if blocked, err := f.db.IsBlocked(ctx, relevantAccounts.InReplyToAccount.ID, requestingAccount.ID, true); err != nil { return false, err } else if blocked { l.Trace("a block exists between requesting account and reply to account") @@ -146,7 +147,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount // check reply to ID if targetStatus.InReplyToID != "" && (targetStatus.Visibility == gtsmodel.VisibilityFollowersOnly || targetStatus.Visibility == gtsmodel.VisibilityDirect) { - followsRepliedAccount, err := f.db.IsFollowing(requestingAccount, relevantAccounts.InReplyToAccount) + followsRepliedAccount, err := f.db.IsFollowing(ctx, requestingAccount, relevantAccounts.InReplyToAccount) if err != nil { return false, err } @@ -159,7 +160,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount // status boosts accounts id if relevantAccounts.BoostedAccount != nil { - if blocked, err := f.db.IsBlocked(relevantAccounts.BoostedAccount.ID, requestingAccount.ID, true); err != nil { + if blocked, err := f.db.IsBlocked(ctx, relevantAccounts.BoostedAccount.ID, requestingAccount.ID, true); err != nil { return false, err } else if blocked { l.Trace("a block exists between requesting account and boosted account") @@ -169,7 +170,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount // status boosts a reply to account id if relevantAccounts.BoostedInReplyToAccount != nil { - if blocked, err := f.db.IsBlocked(relevantAccounts.BoostedInReplyToAccount.ID, requestingAccount.ID, true); err != nil { + if blocked, err := f.db.IsBlocked(ctx, relevantAccounts.BoostedInReplyToAccount.ID, requestingAccount.ID, true); err != nil { return false, err } else if blocked { l.Trace("a block exists between requesting account and boosted reply to account") @@ -182,7 +183,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount if a == nil { continue } - if blocked, err := f.db.IsBlocked(a.ID, requestingAccount.ID, true); err != nil { + if blocked, err := f.db.IsBlocked(ctx, a.ID, requestingAccount.ID, true); err != nil { return false, err } else if blocked { l.Trace("a block exists between requesting account and a mentioned account") @@ -195,7 +196,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount if a == nil { continue } - if blocked, err := f.db.IsBlocked(a.ID, requestingAccount.ID, true); err != nil { + if blocked, err := f.db.IsBlocked(ctx, a.ID, requestingAccount.ID, true); err != nil { return false, err } else if blocked { l.Trace("a block exists between requesting account and a boosted mentioned account") @@ -221,7 +222,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount return true, nil case gtsmodel.VisibilityFollowersOnly: // check one-way follow - follows, err := f.db.IsFollowing(requestingAccount, targetAccount) + follows, err := f.db.IsFollowing(ctx, requestingAccount, targetAccount) if err != nil { return false, err } @@ -232,7 +233,7 @@ func (f *filter) StatusVisible(targetStatus *gtsmodel.Status, requestingAccount return true, nil case gtsmodel.VisibilityMutualsOnly: // check mutual follow - mutuals, err := f.db.IsMutualFollowing(requestingAccount, targetAccount) + mutuals, err := f.db.IsMutualFollowing(ctx, requestingAccount, targetAccount) if err != nil { return false, err } |