From 2847fc8f90601c693074a514d8bd0447908bf020 Mon Sep 17 00:00:00 2001 From: squidboi Date: Fri, 8 Jun 2018 17:12:16 -0700 Subject: add option to not unfollow on block, and option to not federate outgoing blocks --- lib/pleroma/web/activity_pub/activity_pub.ex | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lib') 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 @@ 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 -- cgit v1.2.3 From b3580b6971ed539c0d979e2b80631d0dc26e04c8 Mon Sep 17 00:00:00 2001 From: squidboi Date: Fri, 8 Jun 2018 18:29:41 -0700 Subject: add option to not deny follow if blocked (fixed) --- lib/pleroma/user.ex | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 -> -- cgit v1.2.3 From 16d896f526df0a625f7de115228c9a9b8993ccf3 Mon Sep 17 00:00:00 2001 From: squidboi Date: Fri, 8 Jun 2018 19:01:14 -0700 Subject: fixes --- lib/pleroma/user.ex | 8 ++++---- lib/pleroma/web/activity_pub/activity_pub.ex | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do 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 -- cgit v1.2.3 From 8903f1ad4d6bfab519338b53885ccfbbe1797ed7 Mon Sep 17 00:00:00 2001 From: squidboi Date: Fri, 8 Jun 2018 19:07:14 -0700 Subject: more fixes --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do {:ok, activity} end else - {:ok, nil} + _e -> {:ok, nil} end end -- cgit v1.2.3 From 4f9ecfc77a54eef23741c89206b4cbce924f7d76 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sat, 9 Jun 2018 04:28:11 +0000 Subject: formatting --- lib/pleroma/user.ex | 3 ++- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do @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 -- cgit v1.2.3 From 4e099fcfa9eb03cc281453611fa9224c9c040b26 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sat, 23 Jun 2018 14:16:08 -0700 Subject: 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(-) (limited to 'lib') 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ 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 + @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) -- cgit v1.2.3 From f4990283deba2a191e8763a287b5e091fa3c7d05 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sat, 23 Jun 2018 14:27:07 -0700 Subject: 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(-) (limited to 'lib') 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 -- cgit v1.2.3 From c4038ede0729e1998511fa0a21860d7061e31454 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sat, 23 Jun 2018 14:32:00 -0700 Subject: 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(-) (limited to 'lib') 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.User 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do 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) -- cgit v1.2.3 From ea214b8ba65c0911aed6d2b019465272fc77fbc4 Mon Sep 17 00:00:00 2001 From: squidboi Date: Sun, 24 Jun 2018 23:05:44 -0700 Subject: combined outgoing_blocks with statement --- lib/pleroma/web/activity_pub/activity_pub.ex | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib') 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 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub 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 -- cgit v1.2.3