diff options
Diffstat (limited to 'internal/processing')
| -rw-r--r-- | internal/processing/workers/fromclientapi.go | 14 | ||||
| -rw-r--r-- | internal/processing/workers/fromfediapi.go | 14 | ||||
| -rw-r--r-- | internal/processing/workers/fromfediapi_test.go | 63 |
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 := >smodel.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 := >smodel.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() |
