From f69d38e455c224c459cd37088698542f541bcd1d Mon Sep 17 00:00:00 2001 From: squidboi Date: Thu, 7 Jun 2018 21:00:57 -0700 Subject: [PATCH 1/6] add mrf for dropping follower-only and direct posts --- .../web/activity_pub/mrf/reject_non_public.ex | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/pleroma/web/activity_pub/mrf/reject_non_public.ex diff --git a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex new file mode 100644 index 000000000..eb9580445 --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex @@ -0,0 +1,33 @@ +defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do + alias Pleroma.User + @behaviour Pleroma.Web.ActivityPub.MRF + + def filter(object) do + if object["type"] == "Create" do + user = User.get_by_ap_id(object["actor"]) + public = "https://www.w3.org/ns/activitystreams#Public" + + #Determine visibility + visibility = + cond do + #Public + public in object["to"] -> "p" + #Unlisted + public in object["cc"] -> "u" + #Followers-only + user.follower_address in object["to"] -> "f" + #Direct + true -> "d" + end + + case visibility do + "p" -> {:ok, object} + "u" -> {:ok, object} + _ -> {:reject, nil} + end + else + {:ok, object} + end + end + +end From 5b9e1f228ae21cc1749914d375bb3644e8048df4 Mon Sep 17 00:00:00 2001 From: squidboi Date: Thu, 7 Jun 2018 21:55:58 -0700 Subject: [PATCH 2/6] formatting --- .../web/activity_pub/mrf/reject_non_public.ex | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex index eb9580445..9719a48d5 100644 --- a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex +++ b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex @@ -20,14 +20,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do true -> "d" end - case visibility do - "p" -> {:ok, object} - "u" -> {:ok, object} - _ -> {:reject, nil} - end + {flag, object_out} = + case visibility do + "p" -> {:ok, object} + "u" -> {:ok, object} + _ -> {:reject, nil} + end + + {flag, object_out} else {:ok, object} end end - end From 990cde74396e0797c16f77978621ccf383846e15 Mon Sep 17 00:00:00 2001 From: squidboi Date: Thu, 7 Jun 2018 22:03:24 -0700 Subject: [PATCH 3/6] more formatting --- .../web/activity_pub/mrf/reject_non_public.ex | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex index 9719a48d5..c1d25f488 100644 --- a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex +++ b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex @@ -10,20 +10,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do #Determine visibility visibility = cond do - #Public - public in object["to"] -> "p" - #Unlisted - public in object["cc"] -> "u" - #Followers-only - user.follower_address in object["to"] -> "f" - #Direct - true -> "d" + public in object["to"] -> "public" + public in object["cc"] -> "unlisted" + user.follower_address in object["to"] -> "followers" + true -> "direct" end {flag, object_out} = case visibility do - "p" -> {:ok, object} - "u" -> {:ok, object} + "public" -> {:ok, object} + "unlisted" -> {:ok, object} _ -> {:reject, nil} end From 82225dfc8dbb7bbcf2c9b70a840e7fa8d425dd50 Mon Sep 17 00:00:00 2001 From: squidboi Date: Thu, 7 Jun 2018 22:10:11 -0700 Subject: [PATCH 4/6] even more formatting --- lib/pleroma/web/activity_pub/mrf/reject_non_public.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex index c1d25f488..e3fcc4447 100644 --- a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex +++ b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex @@ -2,12 +2,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do alias Pleroma.User @behaviour Pleroma.Web.ActivityPub.MRF + @impl true def filter(object) do if object["type"] == "Create" do user = User.get_by_ap_id(object["actor"]) public = "https://www.w3.org/ns/activitystreams#Public" - #Determine visibility + # Determine visibility visibility = cond do public in object["to"] -> "public" From 6e7f91bf8fdc355afe48bccd1ccde3340c514eae Mon Sep 17 00:00:00 2001 From: squidboi Date: Thu, 7 Jun 2018 22:14:39 -0700 Subject: [PATCH 5/6] final format --- .../web/activity_pub/mrf/reject_non_public.ex | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex index e3fcc4447..fe257214e 100644 --- a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex +++ b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex @@ -17,14 +17,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do true -> "direct" end - {flag, object_out} = - case visibility do - "public" -> {:ok, object} - "unlisted" -> {:ok, object} - _ -> {:reject, nil} - end - - {flag, object_out} + case visibility do + "public" -> {:ok, object} + "unlisted" -> {:ok, object} + _ -> {:reject, nil} + end else {:ok, object} end From e2c4013c88c71c31084abe7567a7f3ba81f16bfa Mon Sep 17 00:00:00 2001 From: squidboi Date: Thu, 7 Jun 2018 22:33:50 -0700 Subject: [PATCH 6/6] s/get_by_ap_id/get_cached_by_ap_id/ --- lib/pleroma/web/activity_pub/mrf/reject_non_public.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex index fe257214e..879cbe6de 100644 --- a/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex +++ b/lib/pleroma/web/activity_pub/mrf/reject_non_public.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublic do @impl true def filter(object) do if object["type"] == "Create" do - user = User.get_by_ap_id(object["actor"]) + user = User.get_cached_by_ap_id(object["actor"]) public = "https://www.w3.org/ns/activitystreams#Public" # Determine visibility