forked from AkkomaGang/akkoma
Merge branch 'hotfix/user_unfollow' into 'develop'
[#1177] fixed User.unfollow with synchronization external user See merge request pleroma/pleroma!1579
This commit is contained in:
commit
49ae3191df
4 changed files with 83 additions and 20 deletions
|
@ -53,13 +53,11 @@ def run(["unfollow", target]) do
|
||||||
def run(["list"]) do
|
def run(["list"]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
with %User{} = user <- Relay.get_actor() do
|
with %User{following: following} = _user <- Relay.get_actor() do
|
||||||
user.following
|
following
|
||||||
|> Enum.each(fn entry ->
|
|> Enum.map(fn entry -> URI.parse(entry).host end)
|
||||||
URI.parse(entry)
|
|> Enum.uniq()
|
||||||
|> Map.get(:host)
|
|> Enum.each(&shell_info(&1))
|
||||||
|> shell_info()
|
|
||||||
end)
|
|
||||||
else
|
else
|
||||||
e -> shell_error("Error while fetching relay subscription list: #{inspect(e)}")
|
e -> shell_error("Error while fetching relay subscription list: #{inspect(e)}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -750,6 +750,7 @@ def update_note_count(%User{} = user) do
|
||||||
|> update_and_set_cache()
|
|> update_and_set_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec maybe_fetch_follow_information(User.t()) :: User.t()
|
||||||
def maybe_fetch_follow_information(user) do
|
def maybe_fetch_follow_information(user) do
|
||||||
with {:ok, user} <- fetch_follow_information(user) do
|
with {:ok, user} <- fetch_follow_information(user) do
|
||||||
user
|
user
|
||||||
|
@ -807,9 +808,10 @@ def update_follower_count(%User{} = user) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec maybe_update_following_count(User.t()) :: User.t()
|
||||||
def maybe_update_following_count(%User{local: false} = user) do
|
def maybe_update_following_count(%User{local: false} = user) do
|
||||||
if Pleroma.Config.get([:instance, :external_user_synchronization]) do
|
if Pleroma.Config.get([:instance, :external_user_synchronization]) do
|
||||||
{:ok, maybe_fetch_follow_information(user)}
|
maybe_fetch_follow_information(user)
|
||||||
else
|
else
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,4 +69,27 @@ test "relay is unfollowed" do
|
||||||
assert undo_activity.data["object"] == cancelled_activity.data
|
assert undo_activity.data["object"] == cancelled_activity.data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "mix pleroma.relay list" do
|
||||||
|
test "Prints relay subscription list" do
|
||||||
|
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
|
||||||
|
|
||||||
|
refute_receive {:mix_shell, :info, _}
|
||||||
|
|
||||||
|
Pleroma.Web.ActivityPub.Relay.get_actor()
|
||||||
|
|> Ecto.Changeset.change(
|
||||||
|
following: [
|
||||||
|
"http://test-app.com/user/test1",
|
||||||
|
"http://test-app.com/user/test1",
|
||||||
|
"http://test-app-42.com/user/test1"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|> Pleroma.User.update_and_set_cache()
|
||||||
|
|
||||||
|
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
|
||||||
|
|
||||||
|
assert_receive {:mix_shell, :info, ["test-app.com"]}
|
||||||
|
assert_receive {:mix_shell, :info, ["test-app-42.com"]}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -203,24 +203,64 @@ test "local users do not automatically follow local locked accounts" do
|
||||||
# assert websub
|
# assert websub
|
||||||
# end
|
# end
|
||||||
|
|
||||||
test "unfollow takes a user and another user" do
|
describe "unfollow/2" do
|
||||||
followed = insert(:user)
|
setup do
|
||||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
setting = Pleroma.Config.get([:instance, :external_user_synchronization])
|
||||||
|
|
||||||
{:ok, user, _activity} = User.unfollow(user, followed)
|
on_exit(fn ->
|
||||||
|
Pleroma.Config.put([:instance, :external_user_synchronization], setting)
|
||||||
|
end)
|
||||||
|
|
||||||
user = User.get_cached_by_id(user.id)
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
assert user.following == []
|
test "unfollow with syncronizes external user" do
|
||||||
end
|
Pleroma.Config.put([:instance, :external_user_synchronization], true)
|
||||||
|
|
||||||
test "unfollow doesn't unfollow yourself" do
|
followed =
|
||||||
user = insert(:user)
|
insert(:user,
|
||||||
|
nickname: "fuser1",
|
||||||
|
follower_address: "http://localhost:4001/users/fuser1/followers",
|
||||||
|
following_address: "http://localhost:4001/users/fuser1/following",
|
||||||
|
ap_id: "http://localhost:4001/users/fuser1"
|
||||||
|
)
|
||||||
|
|
||||||
{:error, _} = User.unfollow(user, user)
|
user =
|
||||||
|
insert(:user, %{
|
||||||
|
local: false,
|
||||||
|
nickname: "fuser2",
|
||||||
|
ap_id: "http://localhost:4001/users/fuser2",
|
||||||
|
follower_address: "http://localhost:4001/users/fuser2/followers",
|
||||||
|
following_address: "http://localhost:4001/users/fuser2/following",
|
||||||
|
following: [User.ap_followers(followed)]
|
||||||
|
})
|
||||||
|
|
||||||
user = User.get_cached_by_id(user.id)
|
{:ok, user, _activity} = User.unfollow(user, followed)
|
||||||
assert user.following == [user.ap_id]
|
|
||||||
|
user = User.get_cached_by_id(user.id)
|
||||||
|
|
||||||
|
assert user.following == []
|
||||||
|
end
|
||||||
|
|
||||||
|
test "unfollow takes a user and another user" do
|
||||||
|
followed = insert(:user)
|
||||||
|
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||||
|
|
||||||
|
{:ok, user, _activity} = User.unfollow(user, followed)
|
||||||
|
|
||||||
|
user = User.get_cached_by_id(user.id)
|
||||||
|
|
||||||
|
assert user.following == []
|
||||||
|
end
|
||||||
|
|
||||||
|
test "unfollow doesn't unfollow yourself" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:error, _} = User.unfollow(user, user)
|
||||||
|
|
||||||
|
user = User.get_cached_by_id(user.id)
|
||||||
|
assert user.following == [user.ap_id]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "test if a user is following another user" do
|
test "test if a user is following another user" do
|
||||||
|
|
Loading…
Reference in a new issue