activitypub: mrf: tag policy: implement force-unlisted and sandbox
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 4 Feb 2019 15:55:20 +0000 (15:55 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 4 Feb 2019 17:04:05 +0000 (17:04 +0000)
lib/pleroma/web/activity_pub/mrf/tag_policy.ex

index 4d6dc9c9e4fad6f9de4dc7070c10d1f2b606f7b3..e05663371a380525a37e010a220cfd39d30b9310 100644 (file)
@@ -37,6 +37,54 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
     {:ok, message}
   end
 
+  defp process_tag(
+         "mrf_tag:force-unlisted",
+         %{"type" => "Create", "to" => to, "cc" => cc, "actor" => actor} = message
+       ) do
+    user = User.get_cached_by_ap_id(actor)
+
+    if Enum.member?(to, "https://www.w3.org/ns/activitystreams#Public") do
+      to =
+        List.delete(to, "https://www.w3.org/ns/activitystreams#Public") ++ [user.follower_address]
+
+      cc =
+        List.delete(cc, user.follower_address) ++ ["https://www.w3.org/ns/activitystreams#Public"]
+
+      message =
+        message
+        |> Map.put("to", to)
+        |> Map.put("cc", cc)
+
+      {:ok, message}
+    else
+      {:ok, message}
+    end
+  end
+
+  defp process_tag(
+         "mrf_tag:sandbox",
+         %{"type" => "Create", "to" => to, "cc" => cc, "actor" => actor} = message
+       ) do
+    user = User.get_cached_by_ap_id(actor)
+
+    if Enum.member?(to, "https://www.w3.org/ns/activitystreams#Public") or
+         Enum.member?(cc, "https://www.w3.org/ns/activitystreams#Public") do
+      to =
+        List.delete(to, "https://www.w3.org/ns/activitystreams#Public") ++ [user.follower_address]
+
+      cc = List.delete(cc, "https://www.w3.org/ns/activitystreams#Public")
+
+      message =
+        message
+        |> Map.put("to", to)
+        |> Map.put("cc", cc)
+
+      {:ok, message}
+    else
+      {:ok, message}
+    end
+  end
+
   defp process_tag(_, message), do: {:ok, message}
 
   @impl true