bugfix/follow-state #104
3 changed files with 52 additions and 4 deletions
|
@ -487,6 +487,38 @@ def run(["list"]) do
|
||||||
|> Stream.run()
|
|> Stream.run()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run(["fix_follow_state", local_user, remote_user]) do
|
||||||
|
start_pleroma()
|
||||||
|
|
||||||
|
with {:local, %User{} = local} <- {:local, User.get_by_nickname(local_user)},
|
||||||
|
{:remote, %User{} = remote} <- {:remote, User.get_by_nickname(remote_user)},
|
||||||
|
{:follow_data, %{data: %{"state" => request_state}}} <-
|
||||||
|
{:follow_data, Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(local, remote)} do
|
||||||
|
calculated_state = User.following?(local, remote)
|
||||||
|
|
||||||
|
shell_info(
|
||||||
|
"Request state is #{request_state}, vs calculated state of following=#{calculated_state}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if calculated_state == false && request_state == "accept" do
|
||||||
|
shell_info("Discrepancy found, fixing")
|
||||||
|
Pleroma.Web.CommonAPI.reject_follow_request(local, remote)
|
||||||
|
shell_info("Relationship fixed")
|
||||||
|
else
|
||||||
|
shell_info("No discrepancy found")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
{:local, _} ->
|
||||||
|
shell_error("No local user #{local_user}")
|
||||||
|
|
||||||
|
{:remote, _} ->
|
||||||
|
shell_error("No remote user #{remote_user}")
|
||||||
|
|
||||||
|
{:follow_data, _} ->
|
||||||
|
shell_error("No follow data for #{local_user} and #{remote_user}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp set_moderator(user, value) do
|
defp set_moderator(user, value) do
|
||||||
{:ok, user} =
|
{:ok, user} =
|
||||||
user
|
user
|
||||||
|
|
|
@ -1448,13 +1448,19 @@ def block(%User{} = blocker, %User{} = blocked) do
|
||||||
blocker
|
blocker
|
||||||
end
|
end
|
||||||
|
|
||||||
# clear any requested follows as well
|
# clear any requested follows from both sides as well
|
||||||
blocked =
|
blocked =
|
||||||
case CommonAPI.reject_follow_request(blocked, blocker) do
|
case CommonAPI.reject_follow_request(blocked, blocker) do
|
||||||
{:ok, %User{} = updated_blocked} -> updated_blocked
|
{:ok, %User{} = updated_blocked} -> updated_blocked
|
||||||
nil -> blocked
|
nil -> blocked
|
||||||
end
|
end
|
||||||
|
|
||||||
|
blocker =
|
||||||
|
case CommonAPI.reject_follow_request(blocker, blocked) do
|
||||||
|
{:ok, %User{} = updated_blocker} -> updated_blocker
|
||||||
|
nil -> blocker
|
||||||
|
end
|
||||||
|
|
||||||
unsubscribe(blocked, blocker)
|
unsubscribe(blocked, blocker)
|
||||||
|
|
||||||
unfollowing_blocked = Config.get([:activitypub, :unfollow_blocked], true)
|
unfollowing_blocked = Config.get([:activitypub, :unfollow_blocked], true)
|
||||||
|
|
|
@ -61,9 +61,11 @@ test "it posts a poll" do
|
||||||
describe "blocking" do
|
describe "blocking" do
|
||||||
setup do
|
setup do
|
||||||
blocker = insert(:user)
|
blocker = insert(:user)
|
||||||
blocked = insert(:user)
|
blocked = insert(:user, local: false)
|
||||||
User.follow(blocker, blocked)
|
CommonAPI.follow(blocker, blocked)
|
||||||
User.follow(blocked, blocker)
|
CommonAPI.follow(blocked, blocker)
|
||||||
|
CommonAPI.accept_follow_request(blocker, blocked)
|
||||||
|
CommonAPI.accept_follow_request(blocked, blocked)
|
||||||
%{blocker: blocker, blocked: blocked}
|
%{blocker: blocker, blocked: blocked}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -72,6 +74,9 @@ test "it blocks and federates", %{blocker: blocker, blocked: blocked} do
|
||||||
|
|
||||||
with_mock Pleroma.Web.Federator,
|
with_mock Pleroma.Web.Federator,
|
||||||
publish: fn _ -> nil end do
|
publish: fn _ -> nil end do
|
||||||
|
assert User.get_follow_state(blocker, blocked) == :follow_accept
|
||||||
|
refute is_nil(Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(blocker, blocked))
|
||||||
|
|
||||||
assert {:ok, block} = CommonAPI.block(blocker, blocked)
|
assert {:ok, block} = CommonAPI.block(blocker, blocked)
|
||||||
|
|
||||||
assert block.local
|
assert block.local
|
||||||
|
@ -79,6 +84,11 @@ test "it blocks and federates", %{blocker: blocker, blocked: blocked} do
|
||||||
refute User.following?(blocker, blocked)
|
refute User.following?(blocker, blocked)
|
||||||
refute User.following?(blocked, blocker)
|
refute User.following?(blocked, blocker)
|
||||||
|
|
||||||
|
refute User.get_follow_state(blocker, blocked)
|
||||||
|
|
||||||
|
assert %{data: %{"state" => "reject"}} =
|
||||||
|
Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(blocker, blocked)
|
||||||
|
|
||||||
assert called(Pleroma.Web.Federator.publish(block))
|
assert called(Pleroma.Web.Federator.publish(block))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue