Fix deletion not deleting relevant actions.
[akkoma] / lib / pleroma / activity.ex
1 defmodule Pleroma.Activity do
2 use Ecto.Schema
3 alias Pleroma.{Repo, Activity}
4 import Ecto.Query
5
6 schema "activities" do
7 field :data, :map
8 field :local, :boolean, default: true
9
10 timestamps()
11 end
12
13 def get_by_ap_id(ap_id) do
14 Repo.one(from activity in Activity,
15 where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)))
16 end
17
18 # Wrong name, only returns create activities
19 def all_by_object_ap_id_q(ap_id) do
20 from activity in Activity,
21 where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))
22 end
23
24 def all_non_create_by_object_ap_id_q(ap_id) do
25 from activity in Activity,
26 where: fragment("(?)->>'object' = ?", activity.data, ^to_string(ap_id))
27 end
28
29 def all_by_object_ap_id(ap_id) do
30 Repo.all(all_by_object_ap_id_q(ap_id))
31 end
32
33 def get_create_activity_by_object_ap_id(ap_id) do
34 Repo.one(from activity in Activity,
35 where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))
36 and fragment("(?)->>'type' = 'Create'", activity.data))
37 end
38 end