Delete accepted follow request when unfollowing actor

This commit is contained in:
silverpill 2021-12-17 22:32:36 +00:00
parent 8d5cabc08b
commit f785541205

View file

@ -118,17 +118,17 @@ pub async fn unfollow(
", ",
&[&source_id, &target_id], &[&source_id, &target_id],
).await?; ).await?;
if deleted_count == 0 { let relationship_deleted = deleted_count > 0;
// Relationship not found, try to delete follow request // Delete follow request (for remote follows)
let follow_request_deleted = delete_follow_request( let follow_request_deleted = delete_follow_request(
&transaction, &transaction,
source_id, source_id,
target_id, target_id,
).await?; ).await?;
if !follow_request_deleted { if !relationship_deleted && !follow_request_deleted {
return Err(DatabaseError::NotFound("relationship")); return Err(DatabaseError::NotFound("relationship"));
} };
} else { if relationship_deleted {
// Update counters only if relationship exists // Update counters only if relationship exists
update_follower_count(&transaction, target_id, -1).await?; update_follower_count(&transaction, target_id, -1).await?;
update_following_count(&transaction, source_id, -1).await?; update_following_count(&transaction, source_id, -1).await?;