1 defmodule Pleroma.Activity do
3 alias Pleroma.{Repo, Activity, Notification}
8 field(:local, :boolean, default: true)
10 field(:recipients, {:array, :string})
11 field(:recipients_to, {:array, :string})
12 field(:recipients_cc, {:array, :string})
13 has_many(:notifications, Notification, on_delete: :delete_all)
18 def get_by_ap_id(ap_id) do
22 where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id))
28 # Go through these and fix them everywhere.
29 # Wrong name, only returns create activities
30 def all_by_object_ap_id_q(ap_id) do
35 "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
40 where: fragment("(?)->>'type' = 'Create'", activity.data)
44 # Wrong name, returns all.
45 def all_non_create_by_object_ap_id_q(ap_id) do
50 "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
58 # Wrong name plz fix thx
59 def all_by_object_ap_id(ap_id) do
60 Repo.all(all_by_object_ap_id_q(ap_id))
63 def create_activity_by_object_id_query(ap_ids) do
68 "coalesce((?)->'object'->>'id', (?)->>'object') = ANY(?)",
73 where: fragment("(?)->>'type' = 'Create'", activity.data)
77 def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do
78 create_activity_by_object_id_query([ap_id])
82 def get_create_activity_by_object_ap_id(_), do: nil
84 def normalize(obj) when is_map(obj), do: Activity.get_by_ap_id(obj["id"])
85 def normalize(ap_id) when is_binary(ap_id), do: Activity.get_by_ap_id(ap_id)
86 def normalize(_), do: nil