Commit f97c8e43 authored by lain's avatar lain
Browse files

Add utility functions for objects and activities.

parent 4cac3854
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
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
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment