1 defmodule Pleroma.Activity do
3 alias Pleroma.{Repo, Activity, Notification}
8 field(:local, :boolean, default: true)
10 field(:recipients, {:array, :string})
11 has_many(:notifications, Notification, on_delete: :delete_all)
16 def get_by_ap_id(ap_id) do
20 where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id))
26 # Go through these and fix them everywhere.
27 # Wrong name, only returns create activities
28 def all_by_object_ap_id_q(ap_id) do
33 "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
38 where: fragment("(?)->>'type' = 'Create'", activity.data)
42 # Wrong name, returns all.
43 def all_non_create_by_object_ap_id_q(ap_id) do
48 "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
56 # Wrong name plz fix thx
57 def all_by_object_ap_id(ap_id) do
58 Repo.all(all_by_object_ap_id_q(ap_id))
61 def create_activity_by_object_id_query(ap_ids) do
66 "coalesce((?)->'object'->>'id', (?)->>'object') = ANY(?)",
71 where: fragment("(?)->>'type' = 'Create'", activity.data)
75 def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do
76 create_activity_by_object_id_query([ap_id])
80 def get_create_activity_by_object_ap_id(_), do: nil
82 def normalize(obj) when is_map(obj), do: Activity.get_by_ap_id(obj["id"])
83 def normalize(ap_id) when is_binary(ap_id), do: Activity.get_by_ap_id(ap_id)
84 def normalize(_), do: nil