From 94e336d9d5731c236e17d58f66a6a1678ca148f7 Mon Sep 17 00:00:00 2001 From: Sadposter Date: Sun, 18 Aug 2019 20:29:31 +0100 Subject: [PATCH] clear follow requests when blocking a user --- lib/pleroma/user.ex | 8 ++++++++ test/user_test.exs | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 5c3c8a8a2..829de6e31 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -21,6 +21,7 @@ defmodule Pleroma.User do alias Pleroma.Web alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI.Utils, as: CommonUtils alias Pleroma.Web.OAuth alias Pleroma.Web.OStatus @@ -914,6 +915,13 @@ def block(blocker, %User{ap_id: ap_id} = blocked) do blocker end + # clear any requested follows as well + blocked = + case CommonAPI.reject_follow_request(blocked, blocker) do + {:ok, %User{} = updated_blocked} -> updated_blocked + nil -> blocked + end + blocker = if subscribed_to?(blocked, blocker) do {:ok, blocker} = unsubscribe(blocked, blocker) diff --git a/test/user_test.exs b/test/user_test.exs index b363b322c..23011bdac 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -90,6 +90,17 @@ test "doesn't return already accepted or duplicate follow requests" do assert activity end + test "clears follow requests when requester is blocked" do + followed = insert(:user, %{info: %{locked: true}}) + follower = insert(:user) + + Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => followed.id}) + assert {:ok, [_activity]} = User.get_follow_requests(followed) + + {:ok, _follower} = User.block(followed, follower) + assert {:ok, []} = User.get_follow_requests(followed) + end + test "follow_all follows mutliple users" do user = insert(:user) followed_zero = insert(:user)