alias Pleroma.{Activity, Repo, Object, Upload, User, Web}
alias Ecto.{Changeset, UUID}
import Ecto.Query
+ require Logger
def insert(map, local \\ true) when is_map(map) do
map = map
|> Map.put_new_lazy("published", &make_date/0)
with %Activity{} = activity <- Activity.get_by_ap_id(map["id"]) do
+ Logger.debug(fn -> "Already have activity, #{activity.id}, not inserting." end)
{:ok, activity}
else _e ->
map = if is_map(map["object"]) do
{:ok, activity, object}
end
- def follow(%User{ap_id: follower_id, local: actor_local}, %User{ap_id: followed_id}, local \\ true) do
+ def follow(%User{ap_id: follower_id, local: actor_local}, %User{ap_id: followed_id}, activity_id \\ nil, local \\ true) do
data = %{
"type" => "Follow",
"actor" => follower_id,
"published" => make_date()
}
+ data = if activity_id, do: Map.put(data, "id", activity_id), else: data
+
with {:ok, activity} <- insert(data, local) do
if actor_local do
Pleroma.Web.Federator.enqueue(:publish, activity)