activity.ex 790 Bytes
Newer Older
lain's avatar
lain committed
1
2
defmodule Pleroma.Activity do
  use Ecto.Schema
3
4
  alias Pleroma.{Repo, Activity}
  import Ecto.Query
lain's avatar
lain committed
5
6
7

  schema "activities" do
    field :data, :map
8
    field :local, :boolean, default: true
lain's avatar
lain committed
9
10
11

    timestamps()
  end
12
13
14

  def get_by_ap_id(ap_id) do
    Repo.one(from activity in Activity,
lain's avatar
lain committed
15
      where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id)))
16
17
18
19
  end

  def all_by_object_ap_id(ap_id) do
    Repo.all(from activity in Activity,
lain's avatar
lain committed
20
      where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id)))
21
  end
22
23
24

  def get_create_activity_by_object_ap_id(ap_id) do
    Repo.one(from activity in Activity,
lain's avatar
lain committed
25
26
      where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))
             and fragment("(?)->>'type' = 'Create'", activity.data))
27
  end
lain's avatar
lain committed
28
end