From: Roger Braun Date: Tue, 21 Mar 2017 08:21:52 +0000 (+0100) Subject: Basic AP objects. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=8de523c8aec19e999334753b5a982fff00d1f44c;p=akkoma Basic AP objects. --- diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex new file mode 100644 index 000000000..c4efc6283 --- /dev/null +++ b/lib/pleroma/activity.ex @@ -0,0 +1,9 @@ +defmodule Pleroma.Activity do + use Ecto.Schema + + schema "activities" do + field :data, :map + + timestamps() + end +end diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex new file mode 100644 index 000000000..a31f40d07 --- /dev/null +++ b/lib/pleroma/object.ex @@ -0,0 +1,9 @@ +defmodule Pleroma.Object do + use Ecto.Schema + + schema "objects" do + field :data, :map + + timestamps() + end +end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex new file mode 100644 index 000000000..b70f4dbb1 --- /dev/null +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -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 diff --git a/priv/repo/migrations/20170321074828_create_activity.exs b/priv/repo/migrations/20170321074828_create_activity.exs new file mode 100644 index 000000000..6e875ae43 --- /dev/null +++ b/priv/repo/migrations/20170321074828_create_activity.exs @@ -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 diff --git a/priv/repo/migrations/20170321074832_create_object.exs b/priv/repo/migrations/20170321074832_create_object.exs new file mode 100644 index 000000000..b8bd49747 --- /dev/null +++ b/priv/repo/migrations/20170321074832_create_object.exs @@ -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 diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs new file mode 100644 index 000000000..1b4b121b3 --- /dev/null +++ b/test/web/activity_pub/activity_pub_test.exs @@ -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