From 2847fc8f90601c693074a514d8bd0447908bf020 Mon Sep 17 00:00:00 2001 From: squidboi Date: Fri, 8 Jun 2018 17:12:16 -0700 Subject: [PATCH 01/11] add option to not unfollow on block, and option to not federate outgoing blocks --- config/config.exs | 5 +++- lib/pleroma/web/activity_pub/activity_pub.ex | 26 ++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/config/config.exs b/config/config.exs index 3292bf29c..dc2b42a8b 100644 --- a/config/config.exs +++ b/config/config.exs @@ -57,7 +57,10 @@ 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: [], diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 75a71da98..2f7b12f97 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -240,17 +240,27 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru end end - def block(blocker, blocked, activity_id \\ nil, local \\ true) do - follow_activity = fetch_latest_follow(blocker, blocked) + @ap_config Application.get_env(:pleroma, :activitypub) + @unfollow_blocked Keyword.get(@ap_config, :unfollow_blocked) + @outgoing_blocks Keyword.get(@ap_config, :outgoing_blocks) - if follow_activity do - unfollow(blocker, blocked, nil, local) + def block(blocker, blocked, activity_id \\ nil, local \\ true) do + + 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 From e99c73aeba3581a16b58d07658c98588108f254c Mon Sep 17 00:00:00 2001 From: squidboi Date: Fri, 8 Jun 2018 17:47:24 -0700 Subject: [PATCH 02/11] add option to not deny follow if blocked --- config/config.exs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/config.exs b/config/config.exs index dc2b42a8b..ea08a5f71 100644 --- a/config/config.exs +++ b/config/config.exs @@ -62,6 +62,9 @@ unfollow_blocked: true, outgoing_blocks: true +config :pleroma, :activitypub, + deny_follow_blocked: true + config :pleroma, :mrf_simple, media_removal: [], media_nsfw: [], From b3580b6971ed539c0d979e2b80631d0dc26e04c8 Mon Sep 17 00:00:00 2001 From: squidboi Date: Fri, 8 Jun 2018 18:29:41 -0700 Subject: [PATCH 03/11] add option to not deny follow if blocked (fixed) --- config/config.exs | 2 +- lib/pleroma/user.ex | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config/config.exs b/config/config.exs index ea08a5f71..58b17e206 100644 --- a/config/config.exs +++ b/config/config.exs @@ -62,7 +62,7 @@ unfollow_blocked: true, outgoing_blocks: true -config :pleroma, :activitypub, +config :pleroma, :user, deny_follow_blocked: true config :pleroma, :mrf_simple, diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 828370cab..649fe8f6d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -168,6 +168,9 @@ def register_changeset(struct, params \\ %{}) do end end + @user_config Application.get_env(:pleroma, :user) + @deny_follow_blocked Keyword.get(@ap_config, :deny_follow_blocked) + def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do user_info = user_info(followed) @@ -178,7 +181,7 @@ def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do false # if the users are blocking each other, we shouldn't even be here, but check for it anyway - User.blocks?(follower, followed) == true or User.blocks?(followed, follower) == true -> + deny_follow_blocked and (User.blocks?(follower, followed) or User.blocks?(followed, follower)) -> false # if OStatus, then there is no three-way handshake to follow @@ -197,6 +200,9 @@ def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do end end + @user_config Application.get_env(:pleroma, :user) + @deny_follow_blocked Keyword.get(@ap_config, :deny_follow_blocked) + def follow(%User{} = follower, %User{info: info} = followed) do ap_followers = followed.follower_address @@ -204,7 +210,7 @@ def follow(%User{} = follower, %User{info: info} = followed) do following?(follower, followed) or info["deactivated"] -> {:error, "Could not follow user: #{followed.nickname} is already on your list."} - blocks?(followed, follower) -> + deny_follow_blocked and blocks?(followed, follower) -> {:error, "Could not follow user: #{followed.nickname} blocked you."} true -> From 16d896f526df0a625f7de115228c9a9b8993ccf3 Mon Sep 17 00:00:00 2001 From: squidboi Date: Fri, 8 Jun 2018 19:01:14 -0700 Subject: [PATCH 04/11] fixes --- lib/pleroma/user.ex | 8 ++++---- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 649fe8f6d..5e3096172 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -169,7 +169,7 @@ def register_changeset(struct, params \\ %{}) do end @user_config Application.get_env(:pleroma, :user) - @deny_follow_blocked Keyword.get(@ap_config, :deny_follow_blocked) + @deny_follow_blocked Keyword.get(@user_config, :deny_follow_blocked) def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do user_info = user_info(followed) @@ -181,7 +181,7 @@ def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do false # if the users are blocking each other, we shouldn't even be here, but check for it anyway - deny_follow_blocked and (User.blocks?(follower, followed) or User.blocks?(followed, follower)) -> + @deny_follow_blocked and (User.blocks?(follower, followed) or User.blocks?(followed, follower)) -> false # if OStatus, then there is no three-way handshake to follow @@ -201,7 +201,7 @@ def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do end @user_config Application.get_env(:pleroma, :user) - @deny_follow_blocked Keyword.get(@ap_config, :deny_follow_blocked) + @deny_follow_blocked Keyword.get(@user_config, :deny_follow_blocked) def follow(%User{} = follower, %User{info: info} = followed) do ap_followers = followed.follower_address @@ -210,7 +210,7 @@ def follow(%User{} = follower, %User{info: info} = followed) do following?(follower, followed) or info["deactivated"] -> {:error, "Could not follow user: #{followed.nickname} is already on your list."} - deny_follow_blocked and blocks?(followed, follower) -> + @deny_follow_blocked and blocks?(followed, follower) -> {:error, "Could not follow user: #{followed.nickname} blocked you."} true -> diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 2f7b12f97..1cf540f0a 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -246,14 +246,14 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru def block(blocker, blocked, activity_id \\ nil, local \\ true) do - with true <- unfollow_blocked do + with true <- @unfollow_blocked do follow_activity = fetch_latest_follow(blocker, blocked) if follow_activity do unfollow(blocker, blocked, nil, local) end end - with true <- outgoing_blocks do + 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 From 8903f1ad4d6bfab519338b53885ccfbbe1797ed7 Mon Sep 17 00:00:00 2001 From: squidboi Date: Fri, 8 Jun 2018 19:07:14 -0700 Subject: [PATCH 05/11] more fixes --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 1cf540f0a..f213b68ca 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -260,7 +260,7 @@ def block(blocker, blocked, activity_id \\ nil, local \\ true) do {:ok, activity} end else - {:ok, nil} + _e -> {:ok, nil} end end From 4f9ecfc77a54eef23741c89206b4cbce924f7d76 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sat, 9 Jun 2018 04:28:11 +0000 Subject: [PATCH 06/11] formatting --- config/config.exs | 3 +-- lib/pleroma/user.ex | 3 ++- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/config.exs b/config/config.exs index 58b17e206..b8dd867c4 100644 --- a/config/config.exs +++ b/config/config.exs @@ -62,8 +62,7 @@ unfollow_blocked: true, outgoing_blocks: true -config :pleroma, :user, - deny_follow_blocked: true +config :pleroma, :user, deny_follow_blocked: true config :pleroma, :mrf_simple, media_removal: [], diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 5e3096172..dd645b2e5 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -181,7 +181,8 @@ def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do false # if the users are blocking each other, we shouldn't even be here, but check for it anyway - @deny_follow_blocked and (User.blocks?(follower, followed) or User.blocks?(followed, follower)) -> + @deny_follow_blocked and + (User.blocks?(follower, followed) or User.blocks?(followed, follower)) -> false # if OStatus, then there is no three-way handshake to follow diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index f213b68ca..a12bd5b58 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -245,9 +245,9 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru @outgoing_blocks Keyword.get(@ap_config, :outgoing_blocks) def block(blocker, blocked, activity_id \\ nil, local \\ true) do - with true <- @unfollow_blocked do follow_activity = fetch_latest_follow(blocker, blocked) + if follow_activity do unfollow(blocker, blocked, nil, local) end From 63946a6af38642a9b22c5026df5034d9191a8dfe Mon Sep 17 00:00:00 2001 From: squidboi Date: Sat, 16 Jun 2018 16:33:52 -0700 Subject: [PATCH 07/11] added info about block configuration to CONFIGURATION.md --- CONFIGURATION.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 4174dd114..ab0c02211 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -13,6 +13,23 @@ Instead, overload the settings by editing the following files: * `dev.secret.exs`: custom additional configuration for `MIX_ENV=dev` * `prod.secret.exs`: custom additional configuration for `MIX_ENV=prod` +## Block functionality + + config :pleroma, :activitypub, + accept_blocks: true, + unfollow_blocked: true, + outgoing_blocks: true + + config :pleroma, :user, deny_follow_blocked: true + +* `accept_blocks`: whether to accept incoming block activities from + other instances +* `unfollow_blocked`: whether blocks result in people getting + unfollowed +* `outgoing_blocks`: whether to federate blocks to other instances +* `deny_follow_blocked`: whether to disallow following an account that + has blocked the user in question + ## Message Rewrite Filters (MRFs) Modify incoming and outgoing posts. From 4e099fcfa9eb03cc281453611fa9224c9c040b26 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sat, 23 Jun 2018 14:16:08 -0700 Subject: [PATCH 08/11] move configurable module attributes into relevant functions --- lib/pleroma/user.ex | 12 ++++++------ lib/pleroma/web/activity_pub/activity_pub.ex | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1fcec479f..6000e74fc 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -168,10 +168,10 @@ def register_changeset(struct, params \\ %{}) do end end - @user_config Application.get_env(:pleroma, :user) - @deny_follow_blocked Keyword.get(@user_config, :deny_follow_blocked) - def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do + @user_config Application.get_env(:pleroma, :user) + @deny_follow_blocked Keyword.get(@user_config, :deny_follow_blocked) + user_info = user_info(followed) should_direct_follow = @@ -209,10 +209,10 @@ def maybe_follow(%User{} = follower, %User{info: info} = followed) do end end - @user_config Application.get_env(:pleroma, :user) - @deny_follow_blocked Keyword.get(@user_config, :deny_follow_blocked) - def follow(%User{} = follower, %User{info: info} = followed) do + @user_config Application.get_env(:pleroma, :user) + @deny_follow_blocked Keyword.get(@user_config, :deny_follow_blocked) + ap_followers = followed.follower_address cond do diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index b174af7ce..b76edbd8b 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -242,11 +242,11 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru 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 + @ap_config Application.get_env(:pleroma, :activitypub) + @unfollow_blocked Keyword.get(@ap_config, :unfollow_blocked) + @outgoing_blocks Keyword.get(@ap_config, :outgoing_blocks) + with true <- @unfollow_blocked do follow_activity = fetch_latest_follow(blocker, blocked) From f4990283deba2a191e8763a287b5e091fa3c7d05 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sat, 23 Jun 2018 14:27:07 -0700 Subject: [PATCH 09/11] change moved attributes into normal variables --- lib/pleroma/user.ex | 12 ++++++------ lib/pleroma/web/activity_pub/activity_pub.ex | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 6000e74fc..a73b0bdf4 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -169,8 +169,8 @@ def register_changeset(struct, params \\ %{}) do end def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do - @user_config Application.get_env(:pleroma, :user) - @deny_follow_blocked Keyword.get(@user_config, :deny_follow_blocked) + user_config Application.get_env(:pleroma, :user) + deny_follow_blocked Keyword.get(user_config, :deny_follow_blocked) user_info = user_info(followed) @@ -181,7 +181,7 @@ def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do false # if the users are blocking each other, we shouldn't even be here, but check for it anyway - @deny_follow_blocked and + deny_follow_blocked and (User.blocks?(follower, followed) or User.blocks?(followed, follower)) -> false @@ -210,8 +210,8 @@ def maybe_follow(%User{} = follower, %User{info: info} = followed) do end def follow(%User{} = follower, %User{info: info} = followed) do - @user_config Application.get_env(:pleroma, :user) - @deny_follow_blocked Keyword.get(@user_config, :deny_follow_blocked) + user_config Application.get_env(:pleroma, :user) + deny_follow_blocked Keyword.get(user_config, :deny_follow_blocked) ap_followers = followed.follower_address @@ -219,7 +219,7 @@ def follow(%User{} = follower, %User{info: info} = followed) do following?(follower, followed) or info["deactivated"] -> {:error, "Could not follow user: #{followed.nickname} is already on your list."} - @deny_follow_blocked and blocks?(followed, follower) -> + deny_follow_blocked and blocks?(followed, follower) -> {:error, "Could not follow user: #{followed.nickname} blocked you."} true -> diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index b76edbd8b..c9b8961dd 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -243,11 +243,11 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru end def block(blocker, blocked, activity_id \\ nil, local \\ true) do - @ap_config Application.get_env(:pleroma, :activitypub) - @unfollow_blocked Keyword.get(@ap_config, :unfollow_blocked) - @outgoing_blocks Keyword.get(@ap_config, :outgoing_blocks) + ap_config Application.get_env(:pleroma, :activitypub) + unfollow_blocked Keyword.get(ap_config, :unfollow_blocked) + outgoing_blocks Keyword.get(ap_config, :outgoing_blocks) - with true <- @unfollow_blocked do + with true <- unfollow_blocked do follow_activity = fetch_latest_follow(blocker, blocked) if follow_activity do @@ -255,7 +255,7 @@ def block(blocker, blocked, activity_id \\ nil, local \\ true) do end end - with true <- @outgoing_blocks do + 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 From c4038ede0729e1998511fa0a21860d7061e31454 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sat, 23 Jun 2018 14:32:00 -0700 Subject: [PATCH 10/11] fix mind-crushingly dumb syntax error --- lib/pleroma/user.ex | 8 ++++---- lib/pleroma/web/activity_pub/activity_pub.ex | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index a73b0bdf4..c840c8529 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -169,8 +169,8 @@ def register_changeset(struct, params \\ %{}) do end def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do - user_config Application.get_env(:pleroma, :user) - deny_follow_blocked Keyword.get(user_config, :deny_follow_blocked) + user_config = Application.get_env(:pleroma, :user) + deny_follow_blocked = Keyword.get(user_config, :deny_follow_blocked) user_info = user_info(followed) @@ -210,8 +210,8 @@ def maybe_follow(%User{} = follower, %User{info: info} = followed) do end def follow(%User{} = follower, %User{info: info} = followed) do - user_config Application.get_env(:pleroma, :user) - deny_follow_blocked Keyword.get(user_config, :deny_follow_blocked) + user_config = Application.get_env(:pleroma, :user) + deny_follow_blocked = Keyword.get(user_config, :deny_follow_blocked) ap_followers = followed.follower_address diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index c9b8961dd..513b53b30 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -243,9 +243,9 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru end def block(blocker, blocked, activity_id \\ nil, local \\ true) do - ap_config Application.get_env(:pleroma, :activitypub) - unfollow_blocked Keyword.get(ap_config, :unfollow_blocked) - outgoing_blocks Keyword.get(ap_config, :outgoing_blocks) + ap_config = Application.get_env(:pleroma, :activitypub) + unfollow_blocked = Keyword.get(ap_config, :unfollow_blocked) + outgoing_blocks = Keyword.get(ap_config, :outgoing_blocks) with true <- unfollow_blocked do follow_activity = fetch_latest_follow(blocker, blocked) From ea214b8ba65c0911aed6d2b019465272fc77fbc4 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sun, 24 Jun 2018 23:05:44 -0700 Subject: [PATCH 11/11] combined outgoing_blocks with statement --- lib/pleroma/web/activity_pub/activity_pub.ex | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 513b53b30..e3ce5aa04 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -255,12 +255,11 @@ def block(blocker, blocked, activity_id \\ nil, local \\ true) do end end - 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 + with true <- outgoing_blocks, + block_data <- make_block_data(blocker, blocked, activity_id), + {:ok, activity} <- insert(block_data, local), + :ok <- maybe_federate(activity) do + {:ok, activity} else _e -> {:ok, nil} end