summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar tobi <tobi.smethurst@protonmail.com>2025-12-03 19:37:17 +0100
committerLibravatar tobi <tobi.smethurst@protonmail.com>2026-01-22 13:26:54 +0100
commit5ca7f0b20785bac1e17e783b2505260283ef5385 (patch)
treecf85644171d8a78c01913e7038a949bff4598ce6 /internal/processing
parent[bugfix] don't apply visibility / status filtering when requesting your own a... (diff)
downloadgotosocial-5ca7f0b20785bac1e17e783b2505260283ef5385.tar.xz
[bugfix] Remove follow (req) notifications on Follow Undo (#4604)
# 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. Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4590 ## 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/4604 Co-authored-by: tobi <tobi.smethurst@protonmail.com> Co-committed-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/workers/fromclientapi.go14
-rw-r--r--internal/processing/workers/fromfediapi.go14
-rw-r--r--internal/processing/workers/fromfediapi_test.go63
3 files changed, 91 insertions, 0 deletions
diff --git a/internal/processing/workers/fromclientapi.go b/internal/processing/workers/fromclientapi.go
index 75201c7dc..e18f941fa 100644
--- a/internal/processing/workers/fromclientapi.go
+++ b/internal/processing/workers/fromclientapi.go
@@ -871,6 +871,20 @@ func (p *clientAPI) UndoFollow(ctx context.Context, cMsg *messages.FromClientAPI
follow.TargetAccountID,
follow.AccountID,
)
+
+ // Clear any notifications that were
+ // generated by this follow (request).
+ if err := p.state.DB.DeleteNotifications(
+ ctx,
+ []gtsmodel.NotificationType{
+ gtsmodel.NotificationFollow,
+ gtsmodel.NotificationFollowRequest,
+ },
+ follow.TargetAccountID,
+ follow.AccountID,
+ ); err != nil {
+ return gtserror.Newf("db error deleting notifications: %w", err)
+ }
}
if err := p.federate.UndoFollow(ctx, follow); err != nil {
diff --git a/internal/processing/workers/fromfediapi.go b/internal/processing/workers/fromfediapi.go
index b64b8bbec..f6feeb622 100644
--- a/internal/processing/workers/fromfediapi.go
+++ b/internal/processing/workers/fromfediapi.go
@@ -1548,6 +1548,20 @@ func (p *fediAPI) UndoFollow(ctx context.Context, fMsg *messages.FromFediAPI) er
return gtserror.Newf("%T not parseable as *gtsmodel.Follow", fMsg.GTSModel)
}
+ // Clear any notifications that were
+ // generated by this follow (request).
+ if err := p.state.DB.DeleteNotifications(
+ ctx,
+ []gtsmodel.NotificationType{
+ gtsmodel.NotificationFollow,
+ gtsmodel.NotificationFollowRequest,
+ },
+ follow.TargetAccountID,
+ follow.AccountID,
+ ); err != nil {
+ return gtserror.Newf("db error deleting notifications: %w", err)
+ }
+
if follow.Account.IsLocal() {
// Remove posts by target from origin's timelines.
p.surface.removeRelationshipFromTimelines(ctx,
diff --git a/internal/processing/workers/fromfediapi_test.go b/internal/processing/workers/fromfediapi_test.go
index 790c78b70..f683dd9f0 100644
--- a/internal/processing/workers/fromfediapi_test.go
+++ b/internal/processing/workers/fromfediapi_test.go
@@ -738,6 +738,69 @@ func (suite *FromFediAPITestSuite) TestUndoAnnounce() {
}
}
+func (suite *FromFediAPITestSuite) TestUndoFollow() {
+ var (
+ ctx = suite.T().Context()
+ testStructs = testrig.SetupTestStructs(rMediaPath, rTemplatePath)
+ requestingAcct = suite.testAccounts["remote_account_1"]
+ receivingAcct = suite.testAccounts["local_account_1"]
+ )
+ defer testrig.TearDownTestStructs(testStructs)
+
+ // Put a notification in the db as though
+ // remote_account_1 had follow requested local_account_1.
+ notif := &gtsmodel.Notification{
+ ID: "01F8PY8RHWRQZV038T4E8T9YK8",
+ CreatedAt: testrig.TimeMustParse("2022-05-14T16:21:09+02:00"),
+ UpdatedAt: testrig.TimeMustParse("2022-05-14T16:21:09+02:00"),
+ NotificationType: gtsmodel.NotificationFollowRequest,
+ OriginAccountID: "01F8MH5ZK5VRH73AKHQM6Y9VNX",
+ OriginAccount: requestingAcct,
+ TargetAccountID: "01F8MH1H7YV1Z7D2C8K2730QBF",
+ TargetAccount: receivingAcct,
+ }
+ if err := testStructs.State.DB.PutNotification(ctx, notif); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Hold a follow in memory as though remote_account_1
+ // has now undone the follow request.
+ follow := &gtsmodel.Follow{
+ ID: "01F8PY8RHWRQZV038T4E8T9YK8",
+ CreatedAt: testrig.TimeMustParse("2022-05-14T16:21:09+02:00"),
+ UpdatedAt: testrig.TimeMustParse("2022-05-14T16:21:09+02:00"),
+ AccountID: "01F8MH5ZK5VRH73AKHQM6Y9VNX",
+ Account: requestingAcct,
+ TargetAccountID: "01F8MH1H7YV1Z7D2C8K2730QBF",
+ TargetAccount: receivingAcct,
+ ShowReblogs: util.Ptr(true),
+ URI: "https://fossbros-anonymous.io/users/foss_satan/follows/01F8PY8RHWRQZV038T4E8T9YK8",
+ Notify: util.Ptr(false),
+ }
+
+ // Process the undo message, passing the follow.
+ err := testStructs.Processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{
+ APObjectType: ap.ActivityFollow,
+ APActivityType: ap.ActivityUndo,
+ GTSModel: follow,
+ Receiving: receivingAcct,
+ Requesting: requestingAcct,
+ })
+ suite.NoError(err)
+
+ // Wait for side effects to trigger:
+ // the notification should be deleted.
+ if !testrig.WaitFor(func() bool {
+ _, err := testStructs.State.DB.GetNotificationByID(
+ gtscontext.SetBarebones(ctx),
+ notif.ID,
+ )
+ return errors.Is(err, db.ErrNoEntries)
+ }) {
+ suite.FailNow("timed out waiting for notif to be removed")
+ }
+}
+
func (suite *FromFediAPITestSuite) TestUpdateNote() {
var (
ctx = suite.T().Context()