Add utility functions for objects and activities.
This commit is contained in:
parent
4cac385411
commit
f97c8e4379
|
@ -1,9 +1,21 @@
|
|||
defmodule Pleroma.Activity do
|
||||
use Ecto.Schema
|
||||
alias Pleroma.{Repo, Activity}
|
||||
import Ecto.Query
|
||||
|
||||
schema "activities" do
|
||||
field :data, :map
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def get_by_ap_id(ap_id) do
|
||||
Repo.one(from activity in Activity,
|
||||
where: fragment("? @> ?", activity.data, ^%{id: ap_id}))
|
||||
end
|
||||
|
||||
def all_by_object_ap_id(ap_id) do
|
||||
Repo.all(from activity in Activity,
|
||||
where: fragment("? @> ?", activity.data, ^%{object: %{id: ap_id}}))
|
||||
end
|
||||
end
|
||||
|
|
18
test/activity_test.exs
Normal file
18
test/activity_test.exs
Normal file
|
@ -0,0 +1,18 @@
|
|||
defmodule Pleroma.ActivityTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
test "returns an activity by it's AP id" do
|
||||
activity = insert(:note_activity)
|
||||
found_activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
|
||||
|
||||
assert activity == found_activity
|
||||
end
|
||||
|
||||
test "returns activities by it's objects AP ids" do
|
||||
activity = insert(:note_activity)
|
||||
[found_activity] = Pleroma.Activity.all_by_object_ap_id(activity.data["object"]["id"])
|
||||
|
||||
assert activity == found_activity
|
||||
end
|
||||
end
|
11
test/object_test.exs
Normal file
11
test/object_test.exs
Normal file
|
@ -0,0 +1,11 @@
|
|||
defmodule Pleroma.ObjectTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
test "returns an object by it's AP id" do
|
||||
object = insert(:note)
|
||||
found_object = Pleroma.Object.get_by_ap_id(object.data["id"])
|
||||
|
||||
assert object == found_object
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue