Merge branch 'mass-follow-fixes' into 'develop'
User.follow_all: Respect blocks in both directions. See merge request pleroma/pleroma!823
This commit is contained in:
commit
99f955cd9e
|
@ -311,12 +311,12 @@ def maybe_follow(%User{} = follower, %User{info: _info} = followed) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "A mass follow for local users. Respects blocks but does not create activities."
|
@doc "A mass follow for local users. Respects blocks in both directions 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 =
|
followed_addresses =
|
||||||
followeds
|
followeds
|
||||||
|> Enum.reject(fn %{ap_id: ap_id} -> ap_id in follower.info.blocks end)
|
|> Enum.reject(fn followed -> blocks?(follower, followed) || blocks?(followed, follower) end)
|
||||||
|> Enum.map(fn %{follower_address: fa} -> fa end)
|
|> Enum.map(fn %{follower_address: fa} -> fa end)
|
||||||
|
|
||||||
q =
|
q =
|
||||||
|
|
|
@ -55,18 +55,21 @@ test "follow_all follows mutliple users" do
|
||||||
followed_two = insert(:user)
|
followed_two = insert(:user)
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
not_followed = insert(:user)
|
not_followed = insert(:user)
|
||||||
|
reverse_blocked = insert(:user)
|
||||||
|
|
||||||
{:ok, user} = User.block(user, blocked)
|
{:ok, user} = User.block(user, blocked)
|
||||||
|
{:ok, reverse_blocked} = User.block(reverse_blocked, user)
|
||||||
|
|
||||||
{:ok, user} = User.follow(user, followed_zero)
|
{:ok, user} = User.follow(user, followed_zero)
|
||||||
|
|
||||||
{:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked])
|
{:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_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)
|
refute User.following?(user, blocked)
|
||||||
|
refute User.following?(user, reverse_blocked)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "follow_all follows mutliple users without duplicating" do
|
test "follow_all follows mutliple users without duplicating" do
|
||||||
|
|
Loading…
Reference in New Issue