From 89b751e12415992cd681515d47e02a9706a6fb64 Mon Sep 17 00:00:00 2001
From: Thomas Citharel <tcit@tcit.fr>
Date: Tue, 17 Dec 2019 13:36:25 +0100
Subject: [PATCH 1/2] Fix signatures for relay

The plugs were missing

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
---
 lib/mobilizon_web/router.ex | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/mobilizon_web/router.ex b/lib/mobilizon_web/router.ex
index ba42d6588..369a6d789 100644
--- a/lib/mobilizon_web/router.ex
+++ b/lib/mobilizon_web/router.ex
@@ -20,6 +20,8 @@ defmodule MobilizonWeb.Router do
   end
 
   pipeline :relay do
+    plug(MobilizonWeb.HTTPSignaturePlug)
+    plug(MobilizonWeb.Plugs.MappedSignatureToIdentity)
     plug(:accepts, ["activity-json", "json"])
   end
 

From 822a522579ee79027ea29bb4f248c1bd682c7909 Mon Sep 17 00:00:00 2001
From: Thomas Citharel <tcit@tcit.fr>
Date: Tue, 17 Dec 2019 13:36:45 +0100
Subject: [PATCH 2/2] Handle actor or object being AP Public string

Mastodon uses "https://www.w3.org/ns/activitystreams#Public" as object
when sending a `Follow` activity to a relay

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
---
 lib/service/activity_pub/activity_pub.ex | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/service/activity_pub/activity_pub.ex b/lib/service/activity_pub/activity_pub.ex
index 298ba8690..ee8f84793 100644
--- a/lib/service/activity_pub/activity_pub.ex
+++ b/lib/service/activity_pub/activity_pub.ex
@@ -118,7 +118,15 @@ defmodule Mobilizon.Service.ActivityPub do
   Getting an actor from url, eventually creating it
   """
   @spec get_or_fetch_actor_by_url(String.t(), boolean) :: {:ok, Actor.t()} | {:error, String.t()}
-  def get_or_fetch_actor_by_url(url, preload \\ false) do
+  def get_or_fetch_actor_by_url(url, preload \\ false)
+
+  def get_or_fetch_actor_by_url("https://www.w3.org/ns/activitystreams#Public", _preload) do
+    with %Actor{url: url} <- Relay.get_actor() do
+      get_or_fetch_actor_by_url(url)
+    end
+  end
+
+  def get_or_fetch_actor_by_url(url, preload) do
     case Actors.get_actor_by_url(url, preload) do
       {:ok, %Actor{} = actor} ->
         {:ok, actor}