mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-23 17:54:22 +00:00
fixed User.unfollow with synchronization external user
This commit is contained in:
parent
0f24edcd8d
commit
3315a2a1c3
|
@ -742,6 +742,7 @@ defmodule Pleroma.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
|
||||||
|
@ -799,9 +800,10 @@ defmodule Pleroma.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
|
||||||
|
|
|
@ -192,6 +192,45 @@ defmodule Pleroma.UserTest do
|
||||||
# assert websub
|
# assert websub
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
describe "unfollow/2" do
|
||||||
|
setup do
|
||||||
|
setting = Pleroma.Config.get([:instance, :external_user_synchronization])
|
||||||
|
|
||||||
|
on_exit(fn ->
|
||||||
|
Pleroma.Config.put([:instance, :external_user_synchronization], setting)
|
||||||
|
end)
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
test "unfollow with syncronizes external user" do
|
||||||
|
Pleroma.Config.put([:instance, :external_user_synchronization], true)
|
||||||
|
|
||||||
|
followed =
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
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)]
|
||||||
|
})
|
||||||
|
|
||||||
|
{:ok, user, _activity} = User.unfollow(user, followed)
|
||||||
|
|
||||||
|
user = User.get_cached_by_id(user.id)
|
||||||
|
|
||||||
|
assert user.following == []
|
||||||
|
end
|
||||||
|
|
||||||
test "unfollow takes a user and another user" do
|
test "unfollow takes a user and another user" do
|
||||||
followed = insert(:user)
|
followed = insert(:user)
|
||||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||||
|
@ -211,6 +250,7 @@ defmodule Pleroma.UserTest do
|
||||||
user = User.get_cached_by_id(user.id)
|
user = User.get_cached_by_id(user.id)
|
||||||
assert user.following == [user.ap_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
|
||||||
followed = insert(:user)
|
followed = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue