forked from AkkomaGang/akkoma
Basic AP objects.
This commit is contained in:
parent
093fd1832d
commit
8de523c8ae
6 changed files with 69 additions and 0 deletions
9
lib/pleroma/activity.ex
Normal file
9
lib/pleroma/activity.ex
Normal file
|
@ -0,0 +1,9 @@
|
|||
defmodule Pleroma.Activity do
|
||||
use Ecto.Schema
|
||||
|
||||
schema "activities" do
|
||||
field :data, :map
|
||||
|
||||
timestamps()
|
||||
end
|
||||
end
|
9
lib/pleroma/object.ex
Normal file
9
lib/pleroma/object.ex
Normal file
|
@ -0,0 +1,9 @@
|
|||
defmodule Pleroma.Object do
|
||||
use Ecto.Schema
|
||||
|
||||
schema "objects" do
|
||||
field :data, :map
|
||||
|
||||
timestamps()
|
||||
end
|
||||
end
|
8
lib/pleroma/web/activity_pub/activity_pub.ex
Normal file
8
lib/pleroma/web/activity_pub/activity_pub.ex
Normal file
|
@ -0,0 +1,8 @@
|
|||
defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Activity
|
||||
|
||||
def insert(map) when is_map(map) do
|
||||
Repo.insert(%Activity{data: map})
|
||||
end
|
||||
end
|
14
priv/repo/migrations/20170321074828_create_activity.exs
Normal file
14
priv/repo/migrations/20170321074828_create_activity.exs
Normal file
|
@ -0,0 +1,14 @@
|
|||
defmodule Pleroma.Repo.Migrations.CreatePleroma.Activity do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:activities) do
|
||||
add :data, :map
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:activities, [:data], using: :gin)
|
||||
|
||||
end
|
||||
end
|
12
priv/repo/migrations/20170321074832_create_object.exs
Normal file
12
priv/repo/migrations/20170321074832_create_object.exs
Normal file
|
@ -0,0 +1,12 @@
|
|||
defmodule Pleroma.Repo.Migrations.CreatePleroma.Object do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:objects) do
|
||||
add :data, :map
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
end
|
||||
end
|
17
test/web/activity_pub/activity_pub_test.exs
Normal file
17
test/web/activity_pub/activity_pub_test.exs
Normal file
|
@ -0,0 +1,17 @@
|
|||
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Activity
|
||||
|
||||
describe "insertion" do
|
||||
test "inserts a given map into the activity database" do
|
||||
data = %{
|
||||
ok: true
|
||||
}
|
||||
|
||||
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
|
||||
assert activity.data == data
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue