diff options
| author | 2025-12-03 19:53:59 +0100 | |
|---|---|---|
| committer | 2026-01-22 13:26:59 +0100 | |
| commit | dff7845ac2a41b2acd091a1f4001fd6ea5feeee4 (patch) | |
| tree | 409a97e67222eac21ba8f37e4ece1bda0466167a | |
| parent | [bugfix] Remove follow (req) notifications on Follow Undo (#4604) (diff) | |
| download | gotosocial-dff7845ac2a41b2acd091a1f4001fd6ea5feeee4.tar.xz | |
[bugfix] Check follow req as well as follow when building relationship model (#4605)
# Description
> If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements.
>
> If this is a documentation change, please briefly describe what you've changed and why.
Fixes an issue where you could click the bell on pending follow requests (as is expected), but the little bell would not light up!! Turns out it's because we only checked follows and not follow requests for those fields when building up the relationship API model.
## Checklist
Please put an x inside each checkbox to indicate that you've read and followed it: `[ ]` -> `[x]`
If this is a documentation change, only the first two checkboxes must be filled (you can delete the others if you want).
- [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md).
- [x] I/we have not used so-called 'AI' to create the proposed changes.
- [x] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have performed a self-review of added code.
- [x] I/we have written code that is legible and maintainable by others.
- [x] I/we have commented the added code, particularly in hard-to-understand areas.
- [ ] I/we have made any necessary changes to documentation.
- [x] I/we have added tests that cover new code.
- [x] I/we have run tests and they pass locally with the changes.
- [x] I/we have run `go fmt ./...` and `golangci-lint run`.
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4605
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Co-committed-by: tobi <tobi.smethurst@protonmail.com>
| -rw-r--r-- | internal/db/bundb/relationship.go | 31 | ||||
| -rw-r--r-- | internal/processing/account/follow_test.go | 43 | ||||
| -rw-r--r-- | internal/typeutils/internaltofrontend_test.go | 2 |
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 := >smodel.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, |
