forked from AkkomaGang/akkoma
Merge branch 'mass-follow' into 'develop'
Mass follow See merge request pleroma/pleroma!642
This commit is contained in:
commit
f85d108c41
2 changed files with 31 additions and 4 deletions
|
@ -247,10 +247,7 @@ defp autofollow_users(user) do
|
||||||
)
|
)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
|
||||||
autofollowed_users
|
follow_all(user, autofollowed_users)
|
||||||
|> Enum.reduce({:ok, user}, fn other_user, {:ok, user} ->
|
|
||||||
follow(user, other_user)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)"
|
@doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)"
|
||||||
|
@ -307,6 +304,25 @@ def maybe_follow(%User{} = follower, %User{info: _info} = followed) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc "A mass follow for local users. Ignores blocks and has no side effects"
|
||||||
|
@spec follow_all(User.t(), list(User.t())) :: {atom(), User.t()}
|
||||||
|
def follow_all(follower, followeds) do
|
||||||
|
following =
|
||||||
|
(follower.following ++ Enum.map(followeds, fn %{follower_address: fa} -> fa end))
|
||||||
|
|> Enum.uniq()
|
||||||
|
|
||||||
|
{:ok, follower} =
|
||||||
|
follower
|
||||||
|
|> follow_changeset(%{following: following})
|
||||||
|
|> update_and_set_cache
|
||||||
|
|
||||||
|
Enum.each(followeds, fn followed ->
|
||||||
|
update_follower_count(followed)
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:ok, follower}
|
||||||
|
end
|
||||||
|
|
||||||
def follow(%User{} = follower, %User{info: info} = followed) do
|
def follow(%User{} = follower, %User{info: info} = followed) do
|
||||||
user_config = Application.get_env(:pleroma, :user)
|
user_config = Application.get_env(:pleroma, :user)
|
||||||
deny_follow_blocked = Keyword.get(user_config, :deny_follow_blocked)
|
deny_follow_blocked = Keyword.get(user_config, :deny_follow_blocked)
|
||||||
|
|
|
@ -48,6 +48,17 @@ test "ap_followers returns the followers collection for the user" do
|
||||||
assert expected_followers_collection == User.ap_followers(user)
|
assert expected_followers_collection == User.ap_followers(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "follow_all follows mutliple users" do
|
||||||
|
user = insert(:user)
|
||||||
|
followed_one = insert(:user)
|
||||||
|
followed_two = insert(:user)
|
||||||
|
|
||||||
|
{:ok, user} = User.follow_all(user, [followed_one, followed_two])
|
||||||
|
|
||||||
|
assert User.following?(user, followed_one)
|
||||||
|
assert User.following?(user, followed_two)
|
||||||
|
end
|
||||||
|
|
||||||
test "follow takes a user and another user" do
|
test "follow takes a user and another user" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
followed = insert(:user)
|
followed = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue