summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/db/bundb/relationship.go31
-rw-r--r--internal/processing/account/follow_test.go43
-rw-r--r--internal/typeutils/internaltofrontend_test.go2
3 files changed, 65 insertions, 11 deletions
diff --git a/internal/db/bundb/relationship.go b/internal/db/bundb/relationship.go
index 687e29f81..74167486b 100644
--- a/internal/db/bundb/relationship.go
+++ b/internal/db/bundb/relationship.go
@@ -52,10 +52,30 @@ func (r *relationshipDB) GetRelationship(ctx context.Context, requestingAccount
}
if follow != nil {
- // follow exists so we can fill these fields out...
+ // Follow exists so we can
+ // fill additional fields out.
rel.Following = true
rel.ShowingReblogs = *follow.ShowReblogs
rel.Notifying = *follow.Notify
+ } else {
+ // Follow doesn't exist,
+ // see if follow request does.
+ followReq, err := r.GetFollowRequest(
+ gtscontext.SetBarebones(ctx),
+ requestingAccount,
+ targetAccount,
+ )
+ if err != nil && !errors.Is(err, db.ErrNoEntries) {
+ return nil, gtserror.Newf("error fetching follow request: %w", err)
+ }
+
+ // Follow req exists so we can
+ // fill additional fields out.
+ if followReq != nil {
+ rel.Requested = true
+ rel.ShowingReblogs = *followReq.ShowReblogs
+ rel.Notifying = *followReq.Notify
+ }
}
// check if the target follows the requesting
@@ -67,15 +87,6 @@ func (r *relationshipDB) GetRelationship(ctx context.Context, requestingAccount
return nil, gtserror.Newf("error checking followedBy: %w", err)
}
- // check if requesting has follow requested target
- rel.Requested, err = r.IsFollowRequested(ctx,
- requestingAccount,
- targetAccount,
- )
- if err != nil {
- return nil, gtserror.Newf("error checking requested: %w", err)
- }
-
// check if target has follow requested requesting
rel.RequestedBy, err = r.IsFollowRequested(ctx,
targetAccount,
diff --git a/internal/processing/account/follow_test.go b/internal/processing/account/follow_test.go
index d68d8d065..babba74b1 100644
--- a/internal/processing/account/follow_test.go
+++ b/internal/processing/account/follow_test.go
@@ -23,7 +23,9 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/ap"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
+ "code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/util"
+ "code.superseriousbusiness.org/gotosocial/testrig"
"github.com/stretchr/testify/suite"
)
@@ -93,6 +95,47 @@ func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNotifySetReblogs() {
suite.True(relationship.Notifying)
}
+func (suite *FollowTestSuite) TestUpdateExistingFollowReqChangeNotify() {
+ var (
+ ctx = suite.T().Context()
+ requestingAcct = suite.testAccounts["local_account_1"]
+ targetAcct = suite.testAccounts["remote_account_1"]
+ )
+
+ // Put a follow request in the database as though
+ // local_account_1 has follow requested remote_account_1.
+ followReq := &gtsmodel.FollowRequest{
+ ID: "01F8PY8RHWRQZV038T4E8T9YK8",
+ CreatedAt: testrig.TimeMustParse("2022-05-14T16:21:09+02:00"),
+ UpdatedAt: testrig.TimeMustParse("2022-05-14T16:21:09+02:00"),
+ AccountID: requestingAcct.ID,
+ Account: requestingAcct,
+ TargetAccountID: targetAcct.ID,
+ TargetAccount: targetAcct,
+ ShowReblogs: util.Ptr(true),
+ URI: "https://fossbros-anonymous.io/users/foss_satan/follows/01F8PY8RHWRQZV038T4E8T9YK8",
+ Notify: util.Ptr(false),
+ }
+ if err := suite.state.DB.PutFollowRequest(ctx, followReq); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Change Notify on the follow req.
+ relationship, err := suite.accountProcessor.FollowCreate(
+ ctx,
+ requestingAcct,
+ &apimodel.AccountFollowRequest{
+ ID: targetAcct.ID,
+ Notify: util.Ptr(true),
+ },
+ )
+ if err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ suite.True(relationship.Notifying)
+}
+
func (suite *FollowTestSuite) TestUpdateExistingFollowChangeNothing() {
ctx := suite.T().Context()
requestingAccount := suite.testAccounts["local_account_1"]
diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go
index 7a6a4f50d..12fb534fd 100644
--- a/internal/typeutils/internaltofrontend_test.go
+++ b/internal/typeutils/internaltofrontend_test.go
@@ -2986,7 +2986,7 @@ func (suite *InternalToFrontendTestSuite) TestRelationshipFollowRequested() {
suite.Equal(`{
"id": "01F8MH5NBDF2MV7CTC4Q5128HF",
"following": false,
- "showing_reblogs": false,
+ "showing_reblogs": true,
"notifying": false,
"followed_by": false,
"blocking": false,