Add actor column to activities.
[akkoma] / lib / pleroma / activity.ex
1 defmodule Pleroma.Activity do
2 use Ecto.Schema
3 alias Pleroma.{Repo, Activity, Notification}
4 import Ecto.Query
5
6 schema "activities" do
7 field :data, :map
8 field :local, :boolean, default: true
9 field :actor, :string
10 has_many :notifications, Notification
11
12 timestamps()
13 end
14
15 def get_by_ap_id(ap_id) do
16 Repo.one(from activity in Activity,
17 where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)))
18 end
19
20 # TODO:
21 # Go through these and fix them everywhere.
22 # Wrong name, only returns create activities
23 def all_by_object_ap_id_q(ap_id) do
24 from activity in Activity,
25 where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)),
26 where: fragment("(?)->>'type' = 'Create'", activity.data)
27 end
28
29 # Wrong name, returns all.
30 def all_non_create_by_object_ap_id_q(ap_id) do
31 from activity in Activity,
32 where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id))
33 end
34
35 # Wrong name plz fix thx
36 def all_by_object_ap_id(ap_id) do
37 Repo.all(all_by_object_ap_id_q(ap_id))
38 end
39
40 def get_create_activity_by_object_ap_id(ap_id) do
41 Repo.one(from activity in Activity,
42 where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)),
43 where: fragment("(?)->>'type' = 'Create'", activity.data))
44 end
45 end