end
def subscribe(subscriber, %{ap_id: ap_id}) do
- with %User{} = user <- get_or_fetch_by_ap_id(ap_id) do
- info_cng =
- user.info
- |> User.Info.add_to_subscribers(subscriber.ap_id)
+ user_config = Application.get_env(:pleroma, :user)
+ deny_follow_blocked = Keyword.get(user_config, :deny_follow_blocked)
- change(user)
- |> put_embed(:info, info_cng)
- |> update_and_set_cache()
+ with %User{} = subscribed <- get_or_fetch_by_ap_id(ap_id) do
+ blocked = blocks?(subscribed, subscriber) and deny_follow_blocked
+
+ if blocked do
+ {:error, "Could not subscribe: #{subscribed.nickname} is blocking you"}
+ else
+ info_cng =
+ subscribed.info
+ |> User.Info.add_to_subscribers(subscriber.ap_id)
+
+ change(subscribed)
+ |> put_embed(:info, info_cng)
+ |> update_and_set_cache()
+ end
end
end
blocker
end
+ blocker =
+ if subscribed_to?(blocked, blocker) do
+ {:ok, blocker} = unsubscribe(blocked, blocker)
+ blocker
+ else
+ blocker
+ end
+
if following?(blocked, blocker) do
unfollow(blocked, blocker)
end
{:error, _} = User.follow(blockee, blocker)
end
+ test "can't subscribe to a user who blocked us" do
+ blocker = insert(:user)
+ blocked = insert(:user)
+
+ {:ok, blocker} = User.block(blocker, blocked)
+
+ {:error, _} = User.subscribe(blocked, blocker)
+ end
+
test "local users do not automatically follow local locked accounts" do
follower = insert(:user, info: %{locked: true})
followed = insert(:user, info: %{locked: true})
refute User.following?(blocker, blocked)
refute User.following?(blocked, blocker)
end
+
+ test "blocks tear down blocked->blocker subscription relationships" do
+ blocker = insert(:user)
+ blocked = insert(:user)
+
+ {:ok, blocker} = User.subscribe(blocked, blocker)
+
+ assert User.subscribed_to?(blocked, blocker)
+ refute User.subscribed_to?(blocker, blocked)
+
+ {:ok, blocker} = User.block(blocker, blocked)
+
+ assert User.blocks?(blocker, blocked)
+ refute User.subscribed_to?(blocker, blocked)
+ refute User.subscribed_to?(blocked, blocker)
+ end
end
describe "domain blocking" do