|
|
@@ -309,20 +309,21 @@ defmodule Pleroma.User do |
|
|
|
@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() |
|
|
|
followed_addresses = Enum.map(followeds, fn %{follower_address: fa} -> fa end) |
|
|
|
|
|
|
|
q = |
|
|
|
from(u in User, |
|
|
|
where: u.id == ^follower.id, |
|
|
|
update: [set: [following: fragment("array_cat(?, ?)", u.following, ^followed_addresses)]] |
|
|
|
) |
|
|
|
|
|
|
|
{:ok, follower} = |
|
|
|
follower |
|
|
|
|> follow_changeset(%{following: following}) |
|
|
|
|> update_and_set_cache |
|
|
|
{1, [follower]} = Repo.update_all(q, [], returning: true) |
|
|
|
|
|
|
|
Enum.each(followeds, fn followed -> |
|
|
|
update_follower_count(followed) |
|
|
|
end) |
|
|
|
|
|
|
|
{:ok, follower} |
|
|
|
set_cache(follower) |
|
|
|
end |
|
|
|
|
|
|
|
def follow(%User{} = follower, %User{info: info} = followed) do |
|
|
|