From bbd0049faef310d1ef9f1f04ecceee3fc924249d Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 9 Feb 2019 13:24:23 +0100 Subject: [PATCH 1/2] Respect blocks in mass follow. --- lib/pleroma/user.ex | 13 +++++-------- test/user_test.exs | 6 +++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 33630ac7c..cd7752554 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -96,12 +96,6 @@ def ap_followers(%User{} = user) do "#{ap_id(user)}/followers" end - def follow_changeset(struct, params \\ %{}) do - struct - |> cast(params, [:following]) - |> validate_required([:following]) - end - def user_info(%User{} = user) do oneself = if user.local, do: 1, else: 0 @@ -307,10 +301,13 @@ def maybe_follow(%User{} = follower, %User{info: _info} = followed) do end end - @doc "A mass follow for local users. Ignores blocks and has no side effects" + @doc "A mass follow for local users. Respects blocks but does not create activities." @spec follow_all(User.t(), list(User.t())) :: {atom(), User.t()} def follow_all(follower, followeds) do - followed_addresses = Enum.map(followeds, fn %{follower_address: fa} -> fa end) + followed_addresses = + followeds + |> Enum.reject(fn %{ap_id: ap_id} -> ap_id in follower.info.blocks end) + |> Enum.map(fn %{follower_address: fa} -> fa end) q = from(u in User, diff --git a/test/user_test.exs b/test/user_test.exs index 98d3bc464..523ab1ea4 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -53,16 +53,20 @@ test "follow_all follows mutliple users" do followed_zero = insert(:user) followed_one = insert(:user) followed_two = insert(:user) + blocked = insert(:user) not_followed = insert(:user) + {:ok, user} = User.block(user, blocked) + {:ok, user} = User.follow(user, followed_zero) - {:ok, user} = User.follow_all(user, [followed_one, followed_two]) + {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked]) assert User.following?(user, followed_one) assert User.following?(user, followed_two) assert User.following?(user, followed_zero) refute User.following?(user, not_followed) + refute User.following?(user, blocked) end test "follow_all follows mutliple users without duplicating" do From 563f04e81bdda320b5a872be63c106fdfa5f42a6 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 9 Feb 2019 13:39:57 +0100 Subject: [PATCH 2/2] Do autofollow first. --- lib/pleroma/user.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index cd7752554..361034887 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -250,8 +250,8 @@ defp autofollow_users(user) do @doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)" def register(%Ecto.Changeset{} = changeset) do with {:ok, user} <- Repo.insert(changeset), - {:ok, _} <- try_send_confirmation_email(user), - {:ok, user} <- autofollow_users(user) do + {:ok, user} <- autofollow_users(user), + {:ok, _} <- try_send_confirmation_email(user) do {:ok, user} end end