Basic AP objects.

This commit is contained in:
Roger Braun 2017-03-21 09:21:52 +01:00
parent 093fd1832d
commit 8de523c8ae
6 changed files with 69 additions and 0 deletions

9
lib/pleroma/activity.ex Normal file
View 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
View File

@ -0,0 +1,9 @@
defmodule Pleroma.Object do
use Ecto.Schema
schema "objects" do
field :data, :map
timestamps()
end
end

View 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

View 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

View 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

View 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