Merge branch 'follow-enhancements' into 'develop'

Respect blocks in mass follow.

See merge request pleroma/pleroma!797
This commit is contained in:
kaniini 2019-02-09 21:03:42 +00:00
commit d5fe05c37e
2 changed files with 12 additions and 11 deletions

View file

@ -96,12 +96,6 @@ defmodule Pleroma.User do
"#{ap_id(user)}/followers" "#{ap_id(user)}/followers"
end end
def follow_changeset(struct, params \\ %{}) do
struct
|> cast(params, [:following])
|> validate_required([:following])
end
def user_info(%User{} = user) do def user_info(%User{} = user) do
oneself = if user.local, do: 1, else: 0 oneself = if user.local, do: 1, else: 0
@ -256,8 +250,8 @@ defmodule Pleroma.User do
@doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)" @doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)"
def register(%Ecto.Changeset{} = changeset) do def register(%Ecto.Changeset{} = changeset) do
with {:ok, user} <- Repo.insert(changeset), with {:ok, user} <- Repo.insert(changeset),
{:ok, _} <- try_send_confirmation_email(user), {:ok, user} <- autofollow_users(user),
{:ok, user} <- autofollow_users(user) do {:ok, _} <- try_send_confirmation_email(user) do
{:ok, user} {:ok, user}
end end
end end
@ -307,10 +301,13 @@ defmodule Pleroma.User do
end end
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()} @spec follow_all(User.t(), list(User.t())) :: {atom(), User.t()}
def follow_all(follower, followeds) do 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 = q =
from(u in User, from(u in User,

View file

@ -53,16 +53,20 @@ defmodule Pleroma.UserTest do
followed_zero = insert(:user) followed_zero = insert(:user)
followed_one = insert(:user) followed_one = insert(:user)
followed_two = insert(:user) followed_two = insert(:user)
blocked = insert(:user)
not_followed = insert(:user) not_followed = insert(:user)
{:ok, user} = User.block(user, blocked)
{:ok, user} = User.follow(user, followed_zero) {: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_one)
assert User.following?(user, followed_two) assert User.following?(user, followed_two)
assert User.following?(user, followed_zero) assert User.following?(user, followed_zero)
refute User.following?(user, not_followed) refute User.following?(user, not_followed)
refute User.following?(user, blocked)
end end
test "follow_all follows mutliple users without duplicating" do test "follow_all follows mutliple users without duplicating" do