From 2c95b0fab9cfae48ac26f5522c6848199ac7d245 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 13 Feb 2020 15:19:01 -0600 Subject: [PATCH 1/4] Make the sample code actually compile --- docs/configuration/mrf.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/configuration/mrf.md b/docs/configuration/mrf.md index 45be18fc5..c7161ca4e 100644 --- a/docs/configuration/mrf.md +++ b/docs/configuration/mrf.md @@ -74,16 +74,18 @@ As discussed above, the MRF system is a modular system that supports pluggable p For example, here is a sample policy module which rewrites all messages to "new message content": ```elixir -# This is a sample MRF policy which rewrites all Notes to have "new message -# content." defmodule Site.RewritePolicy do - @behavior Pleroma.Web.ActivityPub.MRF + @moduledoc "MRF policy which rewrites all Notes to have 'new message content'." + @behaviour Pleroma.Web.ActivityPub.MRF # Catch messages which contain Note objects with actual data to filter. # Capture the object as `object`, the message content as `content` and the # message itself as `message`. @impl true - def filter(%{"type" => Create", "object" => {"type" => "Note", "content" => content} = object} = message) + def filter( + %{"type" => "Create", "object" => %{"type" => "Note", "content" => content} = object} = + message + ) when is_binary(content) do # Subject / CW is stored as summary instead of `name` like other AS2 objects # because of Mastodon doing it that way. @@ -106,6 +108,13 @@ defmodule Site.RewritePolicy do # Let all other messages through without modifying them. @impl true def filter(message), do: {:ok, message} + + @impl true + def describe do + mrf_sample = Pleroma.Config.get(:mrf_sample) + + {:ok, %{mrf_sample: mrf_sample}} + end end ``` From 88a76d0142075dbd71314b8e601a8d347d2f45e9 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 14 Feb 2020 10:55:18 -0600 Subject: [PATCH 2/4] Update suggested path for location of your custom MRF --- docs/configuration/mrf.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration/mrf.md b/docs/configuration/mrf.md index c7161ca4e..80cfaaa84 100644 --- a/docs/configuration/mrf.md +++ b/docs/configuration/mrf.md @@ -118,7 +118,7 @@ defmodule Site.RewritePolicy do end ``` -If you save this file as `lib/site/mrf/rewrite_policy.ex`, it will be included when you next rebuild Pleroma. You can enable it in the configuration like so: +If you save this file as `lib/pleroma/web/activity_pub/mrf/rewrite_policy.ex`, it will be included when you next rebuild Pleroma. You can enable it in the configuration like so: ``` config :pleroma, :instance, From 6caf6a86c50fe3cb078d89b0f8ebcd7fd707bb23 Mon Sep 17 00:00:00 2001 From: feld Date: Fri, 14 Feb 2020 16:55:52 +0000 Subject: [PATCH 3/4] Apply suggestion to docs/configuration/mrf.md --- docs/configuration/mrf.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/configuration/mrf.md b/docs/configuration/mrf.md index 80cfaaa84..fc13aafc8 100644 --- a/docs/configuration/mrf.md +++ b/docs/configuration/mrf.md @@ -111,9 +111,7 @@ defmodule Site.RewritePolicy do @impl true def describe do - mrf_sample = Pleroma.Config.get(:mrf_sample) - - {:ok, %{mrf_sample: mrf_sample}} + {:ok, %{mrf_sample: %{content: "new message content"}}}` end end ``` From 31749559e178729e9f4c4211294de8d1e3e16516 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 14 Feb 2020 11:04:27 -0600 Subject: [PATCH 4/4] Fix MRF docs further. I don't think anyone has actually tested with the old docs. --- docs/configuration/mrf.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration/mrf.md b/docs/configuration/mrf.md index 80cfaaa84..bc039689a 100644 --- a/docs/configuration/mrf.md +++ b/docs/configuration/mrf.md @@ -74,7 +74,7 @@ As discussed above, the MRF system is a modular system that supports pluggable p For example, here is a sample policy module which rewrites all messages to "new message content": ```elixir -defmodule Site.RewritePolicy do +defmodule Pleroma.Web.ActivityPub.MRF.RewritePolicy do @moduledoc "MRF policy which rewrites all Notes to have 'new message content'." @behaviour Pleroma.Web.ActivityPub.MRF @@ -124,7 +124,7 @@ If you save this file as `lib/pleroma/web/activity_pub/mrf/rewrite_policy.ex`, i config :pleroma, :instance, rewrite_policy: [ Pleroma.Web.ActivityPub.MRF.SimplePolicy, - Site.RewritePolicy + Pleroma.Web.ActivityPub.MRF.RewritePolicy ] ```