Replace user.following with Pleroma.FollowingRelationship
This commit is contained in:
parent
2c7ff32e5b
commit
059005ff82
28 changed files with 275 additions and 235 deletions
|
|
@ -39,8 +39,7 @@ defmodule Pleroma.Factory do
|
|||
user
|
||||
| ap_id: User.ap_id(user),
|
||||
follower_address: User.ap_followers(user),
|
||||
following_address: User.ap_following(user),
|
||||
following: [User.ap_id(user)]
|
||||
following_address: User.ap_following(user)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -72,25 +72,25 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
|||
describe "running update_users_following_followers_counts" do
|
||||
test "following and followers count are updated" do
|
||||
[user, user2] = insert_pair(:user)
|
||||
{:ok, %User{following: following, info: info} = user} = User.follow(user, user2)
|
||||
{:ok, %User{info: info} = user} = User.follow(user, user2)
|
||||
|
||||
following = User.following(user)
|
||||
|
||||
assert length(following) == 2
|
||||
assert info.follower_count == 0
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Ecto.Changeset.change(%{following: following ++ following})
|
||||
|> User.change_info(&Ecto.Changeset.change(&1, %{follower_count: 3}))
|
||||
|> Repo.update()
|
||||
|
||||
assert length(user.following) == 4
|
||||
assert user.info.follower_count == 3
|
||||
|
||||
assert :ok == Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"])
|
||||
|
||||
user = User.get_by_id(user.id)
|
||||
|
||||
assert length(user.following) == 2
|
||||
assert length(User.following(user)) == 2
|
||||
assert user.info.follower_count == 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
|
|||
target_user = User.get_cached_by_ap_id(target_instance)
|
||||
follow_activity = Utils.fetch_latest_follow(local_user, target_user)
|
||||
User.follow(local_user, target_user)
|
||||
assert "#{target_instance}/followers" in refresh_record(local_user).following
|
||||
assert "#{target_instance}/followers" in User.following(local_user)
|
||||
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
|
||||
|
||||
cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
|
||||
|
|
@ -68,7 +68,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
|
|||
assert undo_activity.data["type"] == "Undo"
|
||||
assert undo_activity.data["actor"] == local_user.ap_id
|
||||
assert undo_activity.data["object"] == cancelled_activity.data
|
||||
refute "#{target_instance}/followers" in refresh_record(local_user).following
|
||||
refute "#{target_instance}/followers" in User.following(local_user)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -78,20 +78,18 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
|
|||
|
||||
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()
|
||||
relay_user = Relay.get_actor()
|
||||
|
||||
["http://mastodon.example.org/users/admin", "https://mstdn.io/users/mayuutann"]
|
||||
|> Enum.each(fn ap_id ->
|
||||
{:ok, user} = User.get_or_fetch_by_ap_id(ap_id)
|
||||
User.follow(relay_user, user)
|
||||
end)
|
||||
|
||||
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
|
||||
|
||||
assert_receive {:mix_shell, :info, ["test-app.com"]}
|
||||
assert_receive {:mix_shell, :info, ["test-app-42.com"]}
|
||||
assert_receive {:mix_shell, :info, ["mstdn.io"]}
|
||||
assert_receive {:mix_shell, :info, ["mastodon.example.org"]}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -139,7 +139,8 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
|||
describe "running unsubscribe" do
|
||||
test "user is unsubscribed" do
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
user = insert(:user)
|
||||
User.follow(user, followed, "accept")
|
||||
|
||||
Mix.Tasks.Pleroma.User.run(["unsubscribe", user.nickname])
|
||||
|
||||
|
|
@ -154,7 +155,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
|
|||
assert message =~ "Successfully unsubscribed"
|
||||
|
||||
user = User.get_cached_by_nickname(user.nickname)
|
||||
assert Enum.empty?(user.following)
|
||||
assert Enum.empty?(User.get_friends(user))
|
||||
assert user.info.deactivated
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -88,10 +88,9 @@ defmodule Pleroma.UserTest do
|
|||
CommonAPI.follow(pending_follower, locked)
|
||||
CommonAPI.follow(pending_follower, locked)
|
||||
CommonAPI.follow(accepted_follower, locked)
|
||||
User.follow(accepted_follower, locked)
|
||||
Pleroma.FollowingRelationship.update(accepted_follower, locked, "accept")
|
||||
|
||||
assert [activity] = User.get_follow_requests(locked)
|
||||
assert activity
|
||||
assert [^pending_follower] = User.get_follow_requests(locked)
|
||||
end
|
||||
|
||||
test "clears follow requests when requester is blocked" do
|
||||
|
|
@ -136,10 +135,10 @@ defmodule Pleroma.UserTest do
|
|||
followed_two = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow_all(user, [followed_zero, followed_one])
|
||||
assert length(user.following) == 3
|
||||
assert length(User.following(user)) == 3
|
||||
|
||||
{:ok, user} = User.follow_all(user, [followed_one, followed_two])
|
||||
assert length(user.following) == 4
|
||||
assert length(User.following(user)) == 4
|
||||
end
|
||||
|
||||
test "follow takes a user and another user" do
|
||||
|
|
@ -153,7 +152,7 @@ defmodule Pleroma.UserTest do
|
|||
followed = User.get_cached_by_ap_id(followed.ap_id)
|
||||
assert followed.info.follower_count == 1
|
||||
|
||||
assert User.ap_followers(followed) in user.following
|
||||
assert User.ap_followers(followed) in User.following(user)
|
||||
end
|
||||
|
||||
test "can't follow a deactivated users" do
|
||||
|
|
@ -198,7 +197,7 @@ defmodule Pleroma.UserTest do
|
|||
# assert followed.local == false
|
||||
|
||||
# {:ok, user} = User.follow(user, followed)
|
||||
# assert User.ap_followers(followed) in user.following
|
||||
# assert User.ap_followers(followed) in User.following(user)
|
||||
|
||||
# query = from w in WebsubClientSubscription,
|
||||
# where: w.topic == ^followed.info["topic"]
|
||||
|
|
@ -235,26 +234,29 @@ defmodule Pleroma.UserTest do
|
|||
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)]
|
||||
following_address: "http://localhost:4001/users/fuser2/following"
|
||||
})
|
||||
|
||||
{:ok, user} = User.follow(user, followed, "accept")
|
||||
|
||||
{:ok, user, _activity} = User.unfollow(user, followed)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert user.following == []
|
||||
assert User.following(user) == [user.follower_address]
|
||||
end
|
||||
|
||||
test "unfollow takes a user and another user" do
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, followed, "accept")
|
||||
|
||||
assert User.following(user) == [user.follower_address, followed.follower_address]
|
||||
|
||||
{:ok, user, _activity} = User.unfollow(user, followed)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert user.following == []
|
||||
assert User.following(user) == [user.follower_address]
|
||||
end
|
||||
|
||||
test "unfollow doesn't unfollow yourself" do
|
||||
|
|
@ -262,14 +264,14 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
{:error, _} = User.unfollow(user, user)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.following == [user.ap_id]
|
||||
assert User.following(user) == [user.follower_address]
|
||||
end
|
||||
end
|
||||
|
||||
test "test if a user is following another user" do
|
||||
followed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(followed)]})
|
||||
user = insert(:user)
|
||||
User.follow(user, followed, "accept")
|
||||
|
||||
assert User.following?(user, followed)
|
||||
refute User.following?(followed, user)
|
||||
|
|
@ -352,7 +354,7 @@ defmodule Pleroma.UserTest do
|
|||
refute changeset.valid?
|
||||
end
|
||||
|
||||
test "it sets the password_hash, ap_id and following fields" do
|
||||
test "it sets the password_hash and ap_id" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
|
||||
assert changeset.valid?
|
||||
|
|
@ -360,10 +362,6 @@ defmodule Pleroma.UserTest do
|
|||
assert is_binary(changeset.changes[:password_hash])
|
||||
assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
|
||||
|
||||
assert changeset.changes[:following] == [
|
||||
User.ap_followers(%User{nickname: @full_user_data.nickname})
|
||||
]
|
||||
|
||||
assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
|
||||
end
|
||||
|
||||
|
|
@ -671,37 +669,6 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "remove duplicates from following list" do
|
||||
test "it removes duplicates" do
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, %User{following: following} = follower} = User.follow(follower, user)
|
||||
assert length(following) == 2
|
||||
|
||||
{:ok, follower} =
|
||||
follower
|
||||
|> User.update_changeset(%{following: following ++ following})
|
||||
|> Repo.update()
|
||||
|
||||
assert length(follower.following) == 4
|
||||
|
||||
{:ok, follower} = User.remove_duplicated_following(follower)
|
||||
assert length(follower.following) == 2
|
||||
end
|
||||
|
||||
test "it does nothing when following is uniq" do
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, follower} = User.follow(follower, user)
|
||||
assert length(follower.following) == 2
|
||||
|
||||
{:ok, follower} = User.remove_duplicated_following(follower)
|
||||
assert length(follower.following) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "follow_import" do
|
||||
test "it imports user followings from list" do
|
||||
[user1, user2, user3] = insert_list(3, :user)
|
||||
|
|
@ -1010,7 +977,9 @@ defmodule Pleroma.UserTest do
|
|||
assert [activity] == ActivityPub.fetch_public_activities(%{}) |> Repo.preload(:bookmark)
|
||||
|
||||
assert [%{activity | thread_muted?: CommonAPI.thread_muted?(user2, activity)}] ==
|
||||
ActivityPub.fetch_activities([user2.ap_id | user2.following], %{"user" => user2})
|
||||
ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
|
||||
"user" => user2
|
||||
})
|
||||
|
||||
{:ok, _user} = User.deactivate(user)
|
||||
|
||||
|
|
@ -1018,7 +987,9 @@ defmodule Pleroma.UserTest do
|
|||
assert [] == Pleroma.Notification.for_user(user2)
|
||||
|
||||
assert [] ==
|
||||
ActivityPub.fetch_activities([user2.ap_id | user2.following], %{"user" => user2})
|
||||
ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
|
||||
"user" => user2
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -606,7 +606,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
{:ok, announce, _object} = CommonAPI.repeat(activity_three.id, booster)
|
||||
|
||||
[announce_activity] = ActivityPub.fetch_activities([user.ap_id | user.following])
|
||||
[announce_activity] = ActivityPub.fetch_activities([user.ap_id | User.following(user)])
|
||||
|
||||
assert announce_activity.id == announce.id
|
||||
end
|
||||
|
|
@ -1132,7 +1132,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
})
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_activities([user1.ap_id | user1.following])
|
||||
ActivityPub.fetch_activities([user1.ap_id | User.following(user1)])
|
||||
|> Enum.map(fn a -> a.id end)
|
||||
|
||||
private_activity_1 = Activity.get_by_ap_id_with_object(private_activity_1.data["id"])
|
||||
|
|
@ -1142,7 +1142,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert length(activities) == 3
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_activities([user1.ap_id | user1.following], %{"user" => user1})
|
||||
ActivityPub.fetch_activities([user1.ap_id | User.following(user1)], %{"user" => user1})
|
||||
|> Enum.map(fn a -> a.id end)
|
||||
|
||||
assert [public_activity.id, private_activity_1.id] == activities
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
|
||||
|
|
@ -50,14 +51,14 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
service_actor = Relay.get_actor()
|
||||
ActivityPub.follow(service_actor, user)
|
||||
Pleroma.User.follow(service_actor, user)
|
||||
assert "#{user.ap_id}/followers" in refresh_record(service_actor).following
|
||||
assert "#{user.ap_id}/followers" in User.following(service_actor)
|
||||
assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id)
|
||||
assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
|
||||
assert user.ap_id in activity.recipients
|
||||
assert activity.data["type"] == "Undo"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["to"] == [user.ap_id]
|
||||
refute "#{user.ap_id}/followers" in refresh_record(service_actor).following
|
||||
refute "#{user.ap_id}/followers" in User.following(service_actor)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1312,7 +1312,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
|
||||
})
|
||||
|
||||
user_two = insert(:user, %{following: [user.follower_address]})
|
||||
user_two = insert(:user)
|
||||
Pleroma.FollowingRelationship.follow(user_two, user, "accept")
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
|
||||
{:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
|
||||
|
|
@ -1359,8 +1360,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute user.follower_address in unrelated_activity.recipients
|
||||
|
||||
user_two = User.get_cached_by_id(user_two.id)
|
||||
assert user.follower_address in user_two.following
|
||||
refute "..." in user_two.following
|
||||
assert User.following?(user_two, user)
|
||||
refute "..." in User.following(user_two)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -212,7 +212,8 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
|
||||
test "returns true if user following to author" do
|
||||
author = insert(:user)
|
||||
user = insert(:user, following: [author.ap_id])
|
||||
user = insert(:user)
|
||||
Pleroma.User.follow(user, author)
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
|
|
|
|||
|
|
@ -457,7 +457,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, follower)
|
||||
|> assign(:user, User.get_cached_by_id(follower.id))
|
||||
|> post("/api/v1/accounts/#{followed.id}/follow?reblogs=true")
|
||||
|
||||
assert %{"showing_reblogs" => true} = json_response(conn, 200)
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
{:ok, other_user} = User.follow(other_user, user, "pending")
|
||||
|
||||
assert User.following?(other_user, user) == false
|
||||
|
||||
|
|
@ -36,6 +34,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||
{:ok, other_user} = User.follow(other_user, user, "pending")
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
|
|
|
|||
|
|
@ -169,7 +169,8 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
test "it doesn't send to user if recipients invalid and thread containment is enabled" do
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], false)
|
||||
author = insert(:user)
|
||||
user = insert(:user, following: [author.ap_id])
|
||||
user = insert(:user)
|
||||
User.follow(user, author, "accept")
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
|
|
@ -191,7 +192,8 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
test "it sends message if recipients invalid and thread containment is disabled" do
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], true)
|
||||
author = insert(:user)
|
||||
user = insert(:user, following: [author.ap_id])
|
||||
user = insert(:user)
|
||||
User.follow(user, author, "accept")
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
|
|
@ -213,7 +215,8 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], false)
|
||||
author = insert(:user)
|
||||
user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true})
|
||||
user = insert(:user, info: %{skip_thread_containment: true})
|
||||
User.follow(user, author, "accept")
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> response(200)
|
||||
|
||||
assert response =~ "Account followed!"
|
||||
assert user2.follower_address in refresh_record(user).following
|
||||
assert user2.follower_address in User.following(user)
|
||||
end
|
||||
|
||||
test "returns error when user is deactivated", %{conn: conn} do
|
||||
|
|
@ -438,7 +438,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> response(200)
|
||||
|
||||
assert response =~ "Account followed!"
|
||||
assert user2.follower_address in refresh_record(user).following
|
||||
assert user2.follower_address in User.following(user)
|
||||
end
|
||||
|
||||
test "returns error when followee not found", %{conn: conn} do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue