summaryrefslogtreecommitdiff
path: root/internal/db/bundb/relationship_follow_req.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-07-08 16:43:12 +0200
committerLibravatar GitHub <noreply@github.com>2023-07-08 16:43:12 +0200
commitf40bb02f31ca72f1528cf40291e86024509e34d6 (patch)
tree9f68132057fc882a0b733ce037ea46bec0a3627b /internal/db/bundb/relationship_follow_req.go
parent[docs] Clarify how to add a page (#1959) (diff)
downloadgotosocial-f40bb02f31ca72f1528cf40291e86024509e34d6.tar.xz
[bugfix] Delete mutual follow (requests) when receiving block from remote (#1960)
* [bugfix] Delete mutual follow (requests) on block * fix test
Diffstat (limited to 'internal/db/bundb/relationship_follow_req.go')
-rw-r--r--internal/db/bundb/relationship_follow_req.go40
1 files changed, 23 insertions, 17 deletions
diff --git a/internal/db/bundb/relationship_follow_req.go b/internal/db/bundb/relationship_follow_req.go
index c2ac3d2f1..f233bdd58 100644
--- a/internal/db/bundb/relationship_follow_req.go
+++ b/internal/db/bundb/relationship_follow_req.go
@@ -231,36 +231,42 @@ func (r *relationshipDB) AcceptFollowRequest(ctx context.Context, sourceAccountI
}
func (r *relationshipDB) RejectFollowRequest(ctx context.Context, sourceAccountID string, targetAccountID string) db.Error {
+ // Delete follow request first.
+ if err := r.DeleteFollowRequest(ctx, sourceAccountID, targetAccountID); err != nil {
+ return err
+ }
+
+ // Delete follow request notification
+ return r.state.DB.DeleteNotifications(ctx, []string{
+ string(gtsmodel.NotificationFollowRequest),
+ }, targetAccountID, sourceAccountID)
+}
+
+func (r *relationshipDB) DeleteFollowRequest(ctx context.Context, sourceAccountID string, targetAccountID string) error {
defer r.state.Caches.GTS.FollowRequest().Invalidate("AccountID.TargetAccountID", sourceAccountID, targetAccountID)
// Load followreq into cache before attempting a delete,
// as we need it cached in order to trigger the invalidate
// callback. This in turn invalidates others.
- _, err := r.GetFollowRequest(gtscontext.SetBarebones(ctx),
+ follow, err := r.GetFollowRequest(
+ gtscontext.SetBarebones(ctx),
sourceAccountID,
targetAccountID,
)
if err != nil {
+ if errors.Is(err, db.ErrNoEntries) {
+ // Already gone.
+ return nil
+ }
return err
}
- // Attempt to delete follow request.
- if _, err = r.conn.NewDelete().
+ // Finally delete followreq from DB.
+ _, err = r.conn.NewDelete().
Table("follow_requests").
- Where("? = ? AND ? = ?",
- bun.Ident("account_id"),
- sourceAccountID,
- bun.Ident("target_account_id"),
- targetAccountID,
- ).
- Exec(ctx); err != nil {
- return r.conn.ProcessError(err)
- }
-
- // Delete original follow request notification
- return r.state.DB.DeleteNotifications(ctx, []string{
- string(gtsmodel.NotificationFollowRequest),
- }, targetAccountID, sourceAccountID)
+ Where("? = ?", bun.Ident("id"), follow.ID).
+ Exec(ctx)
+ return r.conn.ProcessError(err)
}
func (r *relationshipDB) DeleteFollowRequestByID(ctx context.Context, id string) error {