aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2017-03-21 09:21:52 +0100
committerRoger Braun <roger@rogerbraun.net>2017-03-21 09:21:52 +0100
commit8de523c8aec19e999334753b5a982fff00d1f44c (patch)
treeda09a6e41a579734a5056348dd248e40825a05be
parent093fd1832dd9e8137e28932fe167bcdc7e228366 (diff)
downloadpleroma-8de523c8aec19e999334753b5a982fff00d1f44c.tar.gz
Basic AP objects.
-rw-r--r--lib/pleroma/activity.ex9
-rw-r--r--lib/pleroma/object.ex9
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex8
-rw-r--r--priv/repo/migrations/20170321074828_create_activity.exs14
-rw-r--r--priv/repo/migrations/20170321074832_create_object.exs12
-rw-r--r--test/web/activity_pub/activity_pub_test.exs17
6 files changed, 69 insertions, 0 deletions
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