Commit bbd0049f authored by lain's avatar lain
Browse files

Respect blocks in mass follow.

parent c5f8df08
Pipeline #7316 passed with stages
in 6 minutes and 28 seconds
......@@ -96,12 +96,6 @@ def ap_followers(%User{} = user) do
def follow_changeset(struct, params \\ %{}) do
|> cast(params, [:following])
|> validate_required([:following])
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
@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 =, fn %{follower_address: fa} -> fa end)
followed_addresses =
|> Enum.reject(fn %{ap_id: ap_id} -> ap_id in end)
|> %{follower_address: fa} -> fa end)
q =
from(u in User,
......@@ -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)
test "follow_all follows mutliple users without duplicating" do
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment