mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-11-15 13:41:24 +00:00
user: do not allow refollowing somebody who has blocked a user
This commit is contained in:
parent
8d2ee70da1
commit
1d88abf2d4
2 changed files with 30 additions and 16 deletions
|
@ -170,25 +170,30 @@ defmodule Pleroma.User do
|
||||||
def follow(%User{} = follower, %User{info: info} = followed) do
|
def follow(%User{} = follower, %User{info: info} = followed) do
|
||||||
ap_followers = followed.follower_address
|
ap_followers = followed.follower_address
|
||||||
|
|
||||||
if following?(follower, followed) or info["deactivated"] do
|
cond do
|
||||||
{:error, "Could not follow user: #{followed.nickname} is already on your list."}
|
following?(follower, followed) or info["deactivated"] ->
|
||||||
else
|
{:error, "Could not follow user: #{followed.nickname} is already on your list."}
|
||||||
if !followed.local && follower.local && !ap_enabled?(followed) do
|
|
||||||
Websub.subscribe(follower, followed)
|
|
||||||
end
|
|
||||||
|
|
||||||
following =
|
blocks?(followed, follower) ->
|
||||||
[ap_followers | follower.following]
|
{:error, "Could not follow user: #{followed.nickname} blocked you."}
|
||||||
|> Enum.uniq()
|
|
||||||
|
true ->
|
||||||
|
if !followed.local && follower.local && !ap_enabled?(followed) do
|
||||||
|
Websub.subscribe(follower, followed)
|
||||||
|
end
|
||||||
|
|
||||||
|
following =
|
||||||
|
[ap_followers | follower.following]
|
||||||
|
|> Enum.uniq()
|
||||||
|
|
||||||
|
follower =
|
||||||
|
follower
|
||||||
|
|> follow_changeset(%{following: following})
|
||||||
|
|> update_and_set_cache
|
||||||
|
|
||||||
|
{:ok, _} = update_follower_count(followed)
|
||||||
|
|
||||||
follower =
|
|
||||||
follower
|
follower
|
||||||
|> follow_changeset(%{following: following})
|
|
||||||
|> update_and_set_cache
|
|
||||||
|
|
||||||
{:ok, _} = update_follower_count(followed)
|
|
||||||
|
|
||||||
follower
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,15 @@ defmodule Pleroma.UserTest do
|
||||||
{:error, _} = User.follow(user, followed)
|
{:error, _} = User.follow(user, followed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "can't follow a user who blocked us" do
|
||||||
|
blocker = insert(:user)
|
||||||
|
blockee = insert(:user)
|
||||||
|
|
||||||
|
{:ok, blocker} = User.block(blocker, blockee)
|
||||||
|
|
||||||
|
{:error, _} = User.follow(blockee, blocker)
|
||||||
|
end
|
||||||
|
|
||||||
# This is a somewhat useless test.
|
# This is a somewhat useless test.
|
||||||
# test "following a remote user will ensure a websub subscription is present" do
|
# test "following a remote user will ensure a websub subscription is present" do
|
||||||
# user = insert(:user)
|
# user = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue