From 8de523c8aec19e999334753b5a982fff00d1f44c Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Tue, 21 Mar 2017 09:21:52 +0100 Subject: [PATCH] Basic AP objects. --- lib/pleroma/activity.ex | 9 +++++++++ lib/pleroma/object.ex | 9 +++++++++ lib/pleroma/web/activity_pub/activity_pub.ex | 8 ++++++++ .../20170321074828_create_activity.exs | 14 ++++++++++++++ .../migrations/20170321074832_create_object.exs | 12 ++++++++++++ test/web/activity_pub/activity_pub_test.exs | 17 +++++++++++++++++ 6 files changed, 69 insertions(+) create mode 100644 lib/pleroma/activity.ex create mode 100644 lib/pleroma/object.ex create mode 100644 lib/pleroma/web/activity_pub/activity_pub.ex create mode 100644 priv/repo/migrations/20170321074828_create_activity.exs create mode 100644 priv/repo/migrations/20170321074832_create_object.exs create mode 100644 test/web/activity_pub/activity_pub_test.exs 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