From 81ea359a7ce62a0d761b1b0348a1fccf5fe8e106 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 17 Feb 2018 21:57:31 +0100 Subject: [PATCH] ActivityPub: Handle incoming announces. --- lib/pleroma/web/activity_pub/transmogrifier.ex | 10 ++++++++++ test/web/activity_pub/transmogrifier_test.exs | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index c1d7cb3ae..1dc86fa85 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -73,6 +73,16 @@ def handle_incoming(%{"type" => "Like", "object" => object_id, "actor" => actor, end end + def handle_incoming(%{"type" => "Announce", "object" => object_id, "actor" => actor, "id" => id} = data) do + with %User{} = actor <- User.get_or_fetch_by_ap_id(actor), + {:ok, object} <- ActivityPub.fetch_object_from_id(object_id), + {:ok, activity, object} <- ActivityPub.announce(actor, object, id, false) do + {:ok, activity} + else + _e -> :error + end + end + # TODO # Accept # Undo diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 2e7586227..1728360ea 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -62,6 +62,17 @@ test "it works for incoming likes" do assert data["id"] == "http://mastodon.example.org/users/admin#likes/2" assert data["object"] == activity.data["object"]["id"] end + + test "it works for incoming announces" do + data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode! + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["actor"] == "http://mastodon.example.org/users/admin" + assert data["type"] == "Announce" + assert data["id"] == "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity" + assert data["object"] == "http://mastodon.example.org/users/admin/statuses/99541947525187367" + end end describe "prepare outgoing" do