defmodule Pleroma.Web.ActivityPub.ActivityPub do
- alias Pleroma.Repo
- alias Pleroma.{Activity, Object, Upload, User}
+ alias Pleroma.{Activity, Repo, Object, Upload, User, Web}
+ alias Ecto.{Changeset, UUID}
import Ecto.Query
def insert(map, local \\ true) when is_map(map) do
end
end
- def like(%User{ap_id: ap_id} = user, %Object{data: %{ "id" => id}} = object) do
+ def like(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, local \\ true) do
cond do
# There's already a like here, so return the original activity.
ap_id in (object.data["likes"] || []) ->
"context" => object.data["context"]
}
- {:ok, activity} = insert(data)
+ {:ok, activity} = insert(data, local)
likes = [ap_id | (object.data["likes"] || [])] |> Enum.uniq
|> Map.put("like_count", length(likes))
|> Map.put("likes", likes)
- changeset = Ecto.Changeset.change(object, data: new_data)
+ changeset = Changeset.change(object, data: new_data)
{:ok, object} = Repo.update(changeset)
update_object_in_activities(object)
relevant_activities = Activity.all_by_object_ap_id(id)
Enum.map(relevant_activities, fn (activity) ->
new_activity_data = activity.data |> Map.put("object", object.data)
- changeset = Ecto.Changeset.change(activity, data: new_activity_data)
+ changeset = Changeset.change(activity, data: new_activity_data)
Repo.update(changeset)
end)
end
|> Map.put("like_count", length(likes))
|> Map.put("likes", likes)
- changeset = Ecto.Changeset.change(object, data: new_data)
+ changeset = Changeset.change(object, data: new_data)
{:ok, object} = Repo.update(changeset)
update_object_in_activities(object)
end
def generate_id(type) do
- "#{Pleroma.Web.base_url()}/#{type}/#{Ecto.UUID.generate}"
+ "#{Web.base_url()}/#{type}/#{UUID.generate}"
end
def fetch_public_activities(opts \\ %{}) do
query
end
- Repo.all(query)
- |> Enum.reverse
+ Enum.reverse(Repo.all(query))
end
def announce(%User{ap_id: ap_id} = user, %Object{data: %{"id" => id}} = object, local \\ true) do
|> Map.put("announcement_count", length(announcements))
|> Map.put("announcements", announcements)
- changeset = Ecto.Changeset.change(object, data: new_data)
+ changeset = Changeset.change(object, data: new_data)
{:ok, object} = Repo.update(changeset)
update_object_in_activities(object)