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
17 Repo.one(from activity in Activity,
18 where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)))
22 # Go through these and fix them everywhere.
23 # Wrong name, only returns create activities
24 def all_by_object_ap_id_q(ap_id) do
25 from activity in Activity,
26 where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)),
27 where: fragment("(?)->>'type' = 'Create'", activity.data)
30 # Wrong name, returns all.
31 def all_non_create_by_object_ap_id_q(ap_id) do
32 from activity in Activity,
33 where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id))
36 # Wrong name plz fix thx
37 def all_by_object_ap_id(ap_id) do
38 Repo.all(all_by_object_ap_id_q(ap_id))
41 def get_create_activity_by_object_ap_id(ap_id) do
42 Repo.one(from activity in Activity,
43 where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)),
44 where: fragment("(?)->>'type' = 'Create'", activity.data))