add option to not unfollow on block, and option to not federate outgoing blocks
authorsquidboi <squidboi@waifu.club>
Sat, 9 Jun 2018 00:12:16 +0000 (17:12 -0700)
committersquidboi <squidboi@waifu.club>
Sat, 9 Jun 2018 00:12:16 +0000 (17:12 -0700)
config/config.exs
lib/pleroma/web/activity_pub/activity_pub.ex

index 3292bf29c6d83b1ef3c57969ee2bbdc48b8332b8..dc2b42a8bcda87839e752ab6ebe2fe542f090c59 100644 (file)
@@ -57,7 +57,10 @@ config :pleroma, :instance,
   public: true,
   quarantined_instances: []
 
-config :pleroma, :activitypub, accept_blocks: true
+config :pleroma, :activitypub,
+  accept_blocks: true,
+  unfollow_blocked: true,
+  outgoing_blocks: true
 
 config :pleroma, :mrf_simple,
   media_removal: [],
index 75a71da98bb85f25e91d1fafc0b986d81599f86e..2f7b12f973cbe75b93c5797d5fe2eda0db027716 100644 (file)
@@ -240,17 +240,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     end
   end
 
+  @ap_config Application.get_env(:pleroma, :activitypub)
+  @unfollow_blocked Keyword.get(@ap_config, :unfollow_blocked)
+  @outgoing_blocks Keyword.get(@ap_config, :outgoing_blocks)
+
   def block(blocker, blocked, activity_id \\ nil, local \\ true) do
-    follow_activity = fetch_latest_follow(blocker, blocked)
 
-    if follow_activity do
-      unfollow(blocker, blocked, nil, local)
+    with true <- unfollow_blocked do
+      follow_activity = fetch_latest_follow(blocker, blocked)
+      if follow_activity do
+        unfollow(blocker, blocked, nil, local)
+      end
     end
 
-    with block_data <- make_block_data(blocker, blocked, activity_id),
-         {:ok, activity} <- insert(block_data, local),
-         :ok <- maybe_federate(activity) do
-      {:ok, activity}
+    with true <- outgoing_blocks do
+      with block_data <- make_block_data(blocker, blocked, activity_id),
+           {:ok, activity} <- insert(block_data, local),
+           :ok <- maybe_federate(activity) do
+        {:ok, activity}
+      end
+    else
+      {:ok, nil}
     end
   end