Fix order of args for follow/2

This commit is contained in:
Mark Felder 2024-07-22 19:07:55 -04:00
parent 082319ff48
commit f79a16c062
34 changed files with 119 additions and 119 deletions

View File

@ -199,7 +199,7 @@ defmodule Pleroma.FollowingRelationship do
|> preload([:follower]) |> preload([:follower])
|> Repo.all() |> Repo.all()
|> Enum.map(fn following_relationship -> |> Enum.map(fn following_relationship ->
Pleroma.Web.CommonAPI.follow(following_relationship.follower, target) Pleroma.Web.CommonAPI.follow(target, following_relationship.follower)
Pleroma.Web.CommonAPI.unfollow(following_relationship.follower, origin) Pleroma.Web.CommonAPI.unfollow(following_relationship.follower, origin)
end) end)
|> case do |> case do

View File

@ -46,7 +46,7 @@ defmodule Pleroma.User.Import do
fn identifier -> fn identifier ->
with {:ok, %User{} = followed} <- User.get_or_fetch(identifier), with {:ok, %User{} = followed} <- User.get_or_fetch(identifier),
{:ok, follower, followed} <- User.maybe_direct_follow(follower, followed), {:ok, follower, followed} <- User.maybe_direct_follow(follower, followed),
{:ok, _, _, _} <- CommonAPI.follow(follower, followed) do {:ok, _, _, _} <- CommonAPI.follow(followed, follower) do
followed followed
else else
error -> handle_error(:follow_import, identifier, error) error -> handle_error(:follow_import, identifier, error)

View File

@ -49,7 +49,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do
"#{__MODULE__}: Follow request from #{follower.nickname} to #{user.nickname}" "#{__MODULE__}: Follow request from #{follower.nickname} to #{user.nickname}"
) )
CommonAPI.follow(follower, user) CommonAPI.follow(user, follower)
end end
end) end)

View File

@ -22,7 +22,7 @@ defmodule Pleroma.Web.ActivityPub.Relay do
def follow(target_instance) do def follow(target_instance) do
with %User{} = local_user <- get_actor(), with %User{} = local_user <- get_actor(),
{:ok, %User{} = target_user} <- User.get_or_fetch_by_ap_id(target_instance), {:ok, %User{} = target_user} <- User.get_or_fetch_by_ap_id(target_instance),
{:ok, _, _, activity} <- CommonAPI.follow(local_user, target_user) do {:ok, _, _, activity} <- CommonAPI.follow(target_user, local_user) do
Logger.info("relay: followed instance: #{target_instance}; id=#{activity.data["id"]}") Logger.info("relay: followed instance: #{target_instance}; id=#{activity.data["id"]}")
{:ok, activity} {:ok, activity}
else else

View File

@ -121,7 +121,7 @@ defmodule Pleroma.Web.CommonAPI do
@spec follow(User.t(), User.t()) :: @spec follow(User.t(), User.t()) ::
{:ok, User.t(), User.t(), Activity.t() | Object.t()} | {:error, :rejected} {:ok, User.t(), User.t(), Activity.t() | Object.t()} | {:error, :rejected}
def follow(follower, followed) do def follow(followed, follower) do
timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout]) timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout])
with {:ok, follow_data, _} <- Builder.follow(follower, followed), with {:ok, follow_data, _} <- Builder.follow(follower, followed),

View File

@ -16,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
def follow(follower, followed, params \\ %{}) do def follow(follower, followed, params \\ %{}) do
result = result =
if not User.following?(follower, followed) do if not User.following?(follower, followed) do
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
else else
{:ok, follower, followed, nil} {:ok, follower, followed, nil}
end end

View File

@ -73,7 +73,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowController do
# #
def do_follow(%{assigns: %{user: %User{} = user}} = conn, %{"user" => %{"id" => id}}) do def do_follow(%{assigns: %{user: %User{} = user}} = conn, %{"user" => %{"id" => id}}) do
with {:fetch_user, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)}, with {:fetch_user, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)},
{:ok, _, _, _} <- CommonAPI.follow(user, followee) do {:ok, _, _, _} <- CommonAPI.follow(followee, user) do
redirect(conn, to: "/users/#{followee.id}") redirect(conn, to: "/users/#{followee.id}")
else else
error -> error ->
@ -90,7 +90,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowController do
with {_, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)}, with {_, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)},
{_, {:ok, user}, _} <- {:auth, WrapperAuthenticator.get_user(conn), followee}, {_, {:ok, user}, _} <- {:auth, WrapperAuthenticator.get_user(conn), followee},
{_, _, _, false} <- {:mfa_required, followee, user, MFA.require?(user)}, {_, _, _, false} <- {:mfa_required, followee, user, MFA.require?(user)},
{:ok, _, _, _} <- CommonAPI.follow(user, followee) do {:ok, _, _, _} <- CommonAPI.follow(followee, user) do
redirect(conn, to: "/users/#{followee.id}") redirect(conn, to: "/users/#{followee.id}")
else else
error -> error ->
@ -108,7 +108,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowController do
{_, _, {:ok, %{user: user}}} <- {:mfa_token, followee, MFA.Token.validate(token)}, {_, _, {:ok, %{user: user}}} <- {:mfa_token, followee, MFA.Token.validate(token)},
{_, _, _, {:ok, _}} <- {_, _, _, {:ok, _}} <-
{:verify_mfa_code, followee, token, TOTPAuthenticator.verify(code, user)}, {:verify_mfa_code, followee, token, TOTPAuthenticator.verify(code, user)},
{:ok, _, _, _} <- CommonAPI.follow(user, followee) do {:ok, _, _, _} <- CommonAPI.follow(followee, user) do
redirect(conn, to: "/users/#{followee.id}") redirect(conn, to: "/users/#{followee.id}")
else else
error -> error ->

View File

@ -404,7 +404,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
test "receives private statuses", %{user: reading_user, token: token} do test "receives private statuses", %{user: reading_user, token: token} do
user = insert(:user) user = insert(:user)
CommonAPI.follow(reading_user, user) CommonAPI.follow(user, reading_user)
{:ok, _} = start_socket("?stream=user&access_token=#{token.token}") {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
@ -431,7 +431,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
test "receives edits", %{user: reading_user, token: token} do test "receives edits", %{user: reading_user, token: token} do
user = insert(:user) user = insert(:user)
CommonAPI.follow(reading_user, user) CommonAPI.follow(user, reading_user)
{:ok, _} = start_socket("?stream=user&access_token=#{token.token}") {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
@ -459,7 +459,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
test "receives notifications", %{user: reading_user, token: token} do test "receives notifications", %{user: reading_user, token: token} do
user = insert(:user) user = insert(:user)
CommonAPI.follow(reading_user, user) CommonAPI.follow(user, reading_user)
{:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}") {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")

View File

@ -209,7 +209,7 @@ defmodule Pleroma.NotificationTest do
notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true} notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true}
) )
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
{:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"}) {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"})
refute Notification.create_notification(activity, followed) refute Notification.create_notification(activity, followed)
end end
@ -222,7 +222,7 @@ defmodule Pleroma.NotificationTest do
notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true} notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true}
) )
CommonAPI.follow(receiver, poster) CommonAPI.follow(poster, receiver)
{:ok, activity} = CommonAPI.post(poster, %{status: "hey @#{receiver.nickname}"}) {:ok, activity} = CommonAPI.post(poster, %{status: "hey @#{receiver.nickname}"})
assert Notification.create_notification(activity, receiver) assert Notification.create_notification(activity, receiver)
end end
@ -238,7 +238,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user) user = insert(:user)
subscriber = insert(:user) subscriber = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(subscriber, user) {:ok, _, _, _} = CommonAPI.follow(user, subscriber)
User.subscribe(subscriber, user) User.subscribe(subscriber, user)
{:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"}) {:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"})
{:ok, [_notif]} = Notification.create_notifications(status) {:ok, [_notif]} = Notification.create_notifications(status)
@ -309,7 +309,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user) user = insert(:user)
followed_user = insert(:user, is_locked: false) followed_user = insert(:user, is_locked: false)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity} = CommonAPI.follow(followed_user, user)
assert FollowingRelationship.following?(user, followed_user) assert FollowingRelationship.following?(user, followed_user)
assert [notification] = Notification.for_user(followed_user) assert [notification] = Notification.for_user(followed_user)
@ -324,7 +324,7 @@ defmodule Pleroma.NotificationTest do
user = insert(:user) user = insert(:user)
followed_user = insert(:user, is_locked: true) followed_user = insert(:user, is_locked: true)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity} = CommonAPI.follow(followed_user, user)
refute FollowingRelationship.following?(user, followed_user) refute FollowingRelationship.following?(user, followed_user)
assert [notification] = Notification.for_user(followed_user) assert [notification] = Notification.for_user(followed_user)
@ -349,12 +349,12 @@ defmodule Pleroma.NotificationTest do
user = insert(:user) user = insert(:user)
followed_user = insert(:user, is_locked: false) followed_user = insert(:user, is_locked: false)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity} = CommonAPI.follow(followed_user, user)
assert FollowingRelationship.following?(user, followed_user) assert FollowingRelationship.following?(user, followed_user)
assert [notification] = Notification.for_user(followed_user) assert [notification] = Notification.for_user(followed_user)
CommonAPI.unfollow(user, followed_user) CommonAPI.unfollow(user, followed_user)
{:ok, _, _, _activity_dupe} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity_dupe} = CommonAPI.follow(followed_user, user)
notification_id = notification.id notification_id = notification.id
assert [%{id: ^notification_id}] = Notification.for_user(followed_user) assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
@ -363,7 +363,7 @@ defmodule Pleroma.NotificationTest do
test "dismisses the notification on follow request rejection" do test "dismisses the notification on follow request rejection" do
user = insert(:user, is_locked: true) user = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
{:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, _follow_activity} = CommonAPI.follow(user, follower)
assert [_notification] = Notification.for_user(user) assert [_notification] = Notification.for_user(user)
{:ok, _follower} = CommonAPI.reject_follow_request(follower, user) {:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
assert [] = Notification.for_user(user) assert [] = Notification.for_user(user)
@ -1101,7 +1101,7 @@ defmodule Pleroma.NotificationTest do
insert(:filter, user: followed_user, phrase: "test", hide: true) insert(:filter, user: followed_user, phrase: "test", hide: true)
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user) {:ok, _, _, _activity} = CommonAPI.follow(followed_user, user)
refute FollowingRelationship.following?(user, followed_user) refute FollowingRelationship.following?(user, followed_user)
assert [notification] = Notification.for_user(followed_user) assert [notification] = Notification.for_user(followed_user)

View File

@ -73,7 +73,7 @@ defmodule Pleroma.StatsTest do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"}) {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"})
_ = CommonAPI.follow(user, other_user) _ = CommonAPI.follow(other_user, user)
CommonAPI.favorite(activity.id, other_user) CommonAPI.favorite(activity.id, other_user)
CommonAPI.repeat(activity.id, other_user) CommonAPI.repeat(activity.id, other_user)

View File

@ -183,7 +183,7 @@ defmodule Pleroma.User.BackupTest do
Bookmark.create(user.id, status2.id) Bookmark.create(user.id, status2.id)
Bookmark.create(user.id, status3.id) Bookmark.create(user.id, status3.id)
CommonAPI.follow(user, other_user) CommonAPI.follow(other_user, user)
assert {:ok, backup} = user |> Backup.new() |> Repo.insert() assert {:ok, backup} = user |> Backup.new() |> Repo.insert()
assert {:ok, path} = Backup.export(backup, self()) assert {:ok, path} = Backup.export(backup, self())

View File

@ -182,8 +182,8 @@ defmodule Pleroma.UserTest do
locked = insert(:user, is_locked: true) locked = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
CommonAPI.follow(follower, unlocked) CommonAPI.follow(unlocked, follower)
CommonAPI.follow(follower, locked) CommonAPI.follow(locked, follower)
assert [] = User.get_follow_requests(unlocked) assert [] = User.get_follow_requests(unlocked)
assert [activity] = User.get_follow_requests(locked) assert [activity] = User.get_follow_requests(locked)
@ -196,9 +196,9 @@ defmodule Pleroma.UserTest do
pending_follower = insert(:user) pending_follower = insert(:user)
accepted_follower = insert(:user) accepted_follower = insert(:user)
CommonAPI.follow(pending_follower, locked) CommonAPI.follow(locked, pending_follower)
CommonAPI.follow(pending_follower, locked) CommonAPI.follow(locked, pending_follower)
CommonAPI.follow(accepted_follower, locked) CommonAPI.follow(locked, accepted_follower)
Pleroma.FollowingRelationship.update(accepted_follower, locked, :follow_accept) Pleroma.FollowingRelationship.update(accepted_follower, locked, :follow_accept)
@ -209,7 +209,7 @@ defmodule Pleroma.UserTest do
locked = insert(:user, is_locked: true) locked = insert(:user, is_locked: true)
pending_follower = insert(:user, %{is_active: false}) pending_follower = insert(:user, %{is_active: false})
CommonAPI.follow(pending_follower, locked) CommonAPI.follow(locked, pending_follower)
refute pending_follower.is_active refute pending_follower.is_active
assert [] = User.get_follow_requests(locked) assert [] = User.get_follow_requests(locked)
@ -219,7 +219,7 @@ defmodule Pleroma.UserTest do
followed = insert(:user, is_locked: true) followed = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
assert [_activity] = User.get_follow_requests(followed) assert [_activity] = User.get_follow_requests(followed)
{:ok, _user_relationship} = User.block(followed, follower) {:ok, _user_relationship} = User.block(followed, follower)

View File

@ -1747,7 +1747,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
%{conn: conn} do %{conn: conn} do
user = insert(:user, hide_followers: true) user = insert(:user, hide_followers: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
result = result =
conn conn
@ -1843,7 +1843,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
%{conn: conn} do %{conn: conn} do
user = insert(:user, hide_follows: true) user = insert(:user, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(other_user, user)
result = result =
conn conn

View File

@ -1038,7 +1038,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
refute activity in activities refute activity in activities
followed_user = insert(:user) followed_user = insert(:user)
CommonAPI.follow(user, followed_user) CommonAPI.follow(followed_user, user)
{:ok, repeat_activity} = CommonAPI.repeat(activity.id, followed_user) {:ok, repeat_activity} = CommonAPI.repeat(activity.id, followed_user)
activities = ActivityPub.fetch_activities([], %{blocking_user: user, skip_preload: true}) activities = ActivityPub.fetch_activities([], %{blocking_user: user, skip_preload: true})
@ -1452,7 +1452,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
follower = insert(:user) follower = insert(:user)
followed = insert(:user) followed = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
assert {:error, :reverted} = ActivityPub.unfollow(follower, followed) assert {:error, :reverted} = ActivityPub.unfollow(follower, followed)
@ -1469,7 +1469,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
follower = insert(:user) follower = insert(:user)
followed = insert(:user) followed = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
{:ok, activity} = ActivityPub.unfollow(follower, followed) {:ok, activity} = ActivityPub.unfollow(follower, followed)
assert activity.data["type"] == "Undo" assert activity.data["type"] == "Undo"
@ -1486,7 +1486,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
follower = insert(:user) follower = insert(:user)
followed = insert(:user, %{is_locked: true}) followed = insert(:user, %{is_locked: true})
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
{:ok, activity} = ActivityPub.unfollow(follower, followed) {:ok, activity} = ActivityPub.unfollow(follower, followed)
assert activity.data["type"] == "Undo" assert activity.data["type"] == "Undo"

View File

@ -318,7 +318,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
following_user = insert(:user) following_user = insert(:user)
non_following_user = insert(:user) non_following_user = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(following_user, actor) {:ok, _, _, _} = CommonAPI.follow(actor, following_user)
activity = %{ activity = %{
"actor" => actor.ap_id, "actor" => actor.ap_id,

View File

@ -53,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
test "returns activity" do test "returns activity" do
user = insert(:user) user = insert(:user)
service_actor = Relay.get_actor() service_actor = Relay.get_actor()
CommonAPI.follow(service_actor, user) CommonAPI.follow(user, service_actor)
assert "#{user.ap_id}/followers" in User.following(service_actor) assert "#{user.ap_id}/followers" in User.following(service_actor)
assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id) assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id)
assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay" assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
@ -74,7 +74,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
end) end)
service_actor = Relay.get_actor() service_actor = Relay.get_actor()
CommonAPI.follow(service_actor, user) CommonAPI.follow(user, service_actor)
assert "#{user.ap_id}/followers" in User.following(service_actor) assert "#{user.ap_id}/followers" in User.following(service_actor)
assert Pleroma.Repo.get_by( assert Pleroma.Repo.get_by(

View File

@ -834,7 +834,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
user = insert(:user) user = insert(:user)
followed = insert(:user) followed = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(user, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, user)
{:ok, reject_data, []} = Builder.reject(followed, follow_activity) {:ok, reject_data, []} = Builder.reject(followed, follow_activity)
{:ok, reject, _meta} = ActivityPub.persist(reject_data, local: true) {:ok, reject, _meta} = ActivityPub.persist(reject_data, local: true)

View File

@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
{:ok, follower, followed} = User.follow(follower, followed) {:ok, follower, followed} = User.follow(follower, followed)
assert User.following?(follower, followed) == true assert User.following?(follower, followed) == true
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
accept_data = accept_data =
File.read!("test/fixtures/mastodon-accept-activity.json") File.read!("test/fixtures/mastodon-accept-activity.json")
@ -48,7 +48,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
follower = insert(:user) follower = insert(:user)
followed = insert(:user, is_locked: true) followed = insert(:user, is_locked: true)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
accept_data = accept_data =
File.read!("test/fixtures/mastodon-accept-activity.json") File.read!("test/fixtures/mastodon-accept-activity.json")

View File

@ -36,7 +36,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do
followed = insert(:user, is_locked: true) followed = insert(:user, is_locked: true)
{:ok, follower, followed} = User.follow(follower, followed) {:ok, follower, followed} = User.follow(follower, followed)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower)
assert User.following?(follower, followed) == true assert User.following?(follower, followed) == true

View File

@ -231,8 +231,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
user = insert(:user, is_locked: true) user = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
data = data =
follow_activity_two.data follow_activity_two.data
@ -253,8 +253,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
user = insert(:user) user = insert(:user)
follower = insert(:user) follower = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
{:ok, follow_activity_two} = {:ok, follow_activity_two} =
Utils.update_follow_state_for_all(follow_activity_two, "reject") Utils.update_follow_state_for_all(follow_activity_two, "reject")
@ -269,8 +269,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
user = insert(:user, is_locked: true) user = insert(:user, is_locked: true)
follower = insert(:user) follower = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
data = data =
follow_activity_two.data follow_activity_two.data

View File

@ -138,7 +138,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
test "sets totalItems to zero when followers are hidden" do test "sets totalItems to zero when followers are hidden" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
user = Map.merge(user, %{hide_followers_count: true, hide_followers: true}) user = Map.merge(user, %{hide_followers_count: true, hide_followers: true})
refute UserView.render("followers.json", %{user: user}) |> Map.has_key?("totalItems") refute UserView.render("followers.json", %{user: user}) |> Map.has_key?("totalItems")
@ -147,7 +147,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
test "sets correct totalItems when followers are hidden but the follower counter is not" do test "sets correct totalItems when followers are hidden but the follower counter is not" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
user = Map.merge(user, %{hide_followers_count: false, hide_followers: true}) user = Map.merge(user, %{hide_followers_count: false, hide_followers: true})
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
@ -158,7 +158,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
test "sets totalItems to zero when follows are hidden" do test "sets totalItems to zero when follows are hidden" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
user = Map.merge(user, %{hide_follows_count: true, hide_follows: true}) user = Map.merge(user, %{hide_follows_count: true, hide_follows: true})
assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})
@ -167,7 +167,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
test "sets correct totalItems when follows are hidden but the follow counter is not" do test "sets correct totalItems when follows are hidden but the follow counter is not" do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, _other_user, _activity} = CommonAPI.follow(other_user, user)
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
user = Map.merge(user, %{hide_follows_count: false, hide_follows: true}) user = Map.merge(user, %{hide_follows_count: false, hide_follows: true})
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})

View File

@ -69,8 +69,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
# Create some activities to check they got deleted later # Create some activities to check they got deleted later
follower = insert(:user) follower = insert(:user)
{:ok, _} = CommonAPI.post(user, %{status: "test"}) {:ok, _} = CommonAPI.post(user, %{status: "test"})
{:ok, _, _, _} = CommonAPI.follow(user, follower)
{:ok, _, _, _} = CommonAPI.follow(follower, user) {:ok, _, _, _} = CommonAPI.follow(follower, user)
{:ok, _, _, _} = CommonAPI.follow(user, follower)
user = Repo.get(User, user.id) user = Repo.get(User, user.id)
assert user.note_count == 1 assert user.note_count == 1
assert user.follower_count == 1 assert user.follower_count == 1

View File

@ -80,8 +80,8 @@ defmodule Pleroma.Web.CommonAPITest do
setup do setup do
blocker = insert(:user) blocker = insert(:user)
blocked = insert(:user, local: false) blocked = insert(:user, local: false)
CommonAPI.follow(blocker, blocked)
CommonAPI.follow(blocked, blocker) CommonAPI.follow(blocked, blocker)
CommonAPI.follow(blocker, blocked)
CommonAPI.accept_follow_request(blocker, blocked) CommonAPI.accept_follow_request(blocker, blocked)
CommonAPI.accept_follow_request(blocked, blocked) CommonAPI.accept_follow_request(blocked, blocked)
%{blocker: blocker, blocked: blocked} %{blocker: blocker, blocked: blocked}
@ -955,7 +955,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "author can repeat own private statuses" do test "author can repeat own private statuses" do
author = insert(:user) author = insert(:user)
follower = insert(:user) follower = insert(:user)
CommonAPI.follow(follower, author) CommonAPI.follow(author, follower)
{:ok, activity} = CommonAPI.post(author, %{status: "cofe", visibility: "private"}) {:ok, activity} = CommonAPI.post(author, %{status: "cofe", visibility: "private"})
@ -1420,7 +1420,7 @@ defmodule Pleroma.Web.CommonAPITest do
describe "follow/2" do describe "follow/2" do
test "directly follows a non-locked local user" do test "directly follows a non-locked local user" do
[follower, followed] = insert_pair(:user) [follower, followed] = insert_pair(:user)
{:ok, follower, followed, _} = CommonAPI.follow(follower, followed) {:ok, follower, followed, _} = CommonAPI.follow(followed, follower)
assert User.following?(follower, followed) assert User.following?(follower, followed)
end end
@ -1429,7 +1429,7 @@ defmodule Pleroma.Web.CommonAPITest do
describe "unfollow/2" do describe "unfollow/2" do
test "also unsubscribes a user" do test "also unsubscribes a user" do
[follower, followed] = insert_pair(:user) [follower, followed] = insert_pair(:user)
{:ok, follower, followed, _} = CommonAPI.follow(follower, followed) {:ok, follower, followed, _} = CommonAPI.follow(followed, follower)
{:ok, _subscription} = User.subscribe(follower, followed) {:ok, _subscription} = User.subscribe(follower, followed)
assert User.subscribed_to?(follower, followed) assert User.subscribed_to?(follower, followed)
@ -1441,7 +1441,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "also unpins a user" do test "also unpins a user" do
[follower, followed] = insert_pair(:user) [follower, followed] = insert_pair(:user)
{:ok, follower, followed, _} = CommonAPI.follow(follower, followed) {:ok, follower, followed, _} = CommonAPI.follow(followed, follower)
{:ok, _endorsement} = User.endorse(follower, followed) {:ok, _endorsement} = User.endorse(follower, followed)
assert User.endorses?(follower, followed) assert User.endorses?(follower, followed)
@ -1456,7 +1456,7 @@ defmodule Pleroma.Web.CommonAPITest do
followed = insert(:user, is_locked: true) followed = insert(:user, is_locked: true)
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} = assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
assert User.get_follow_state(follower, followed) == :follow_pending assert User.get_follow_state(follower, followed) == :follow_pending
assert {:ok, follower} = CommonAPI.unfollow(follower, followed) assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
@ -1478,7 +1478,7 @@ defmodule Pleroma.Web.CommonAPITest do
followed = insert(:user, is_locked: true, local: false) followed = insert(:user, is_locked: true, local: false)
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} = assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(follower, followed) CommonAPI.follow(followed, follower)
assert User.get_follow_state(follower, followed) == :follow_pending assert User.get_follow_state(follower, followed) == :follow_pending
assert {:ok, follower} = CommonAPI.unfollow(follower, followed) assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
@ -1502,9 +1502,9 @@ defmodule Pleroma.Web.CommonAPITest do
follower = insert(:user) follower = insert(:user)
follower_two = insert(:user) follower_two = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_three} = CommonAPI.follow(follower_two, user) {:ok, _, _, follow_activity_three} = CommonAPI.follow(user, follower_two)
assert follow_activity.data["state"] == "pending" assert follow_activity.data["state"] == "pending"
assert follow_activity_two.data["state"] == "pending" assert follow_activity_two.data["state"] == "pending"
@ -1522,9 +1522,9 @@ defmodule Pleroma.Web.CommonAPITest do
follower = insert(:user) follower = insert(:user)
follower_two = insert(:user) follower_two = insert(:user)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower)
{:ok, _, _, follow_activity_three} = CommonAPI.follow(follower_two, user) {:ok, _, _, follow_activity_three} = CommonAPI.follow(user, follower_two)
assert follow_activity.data["state"] == "pending" assert follow_activity.data["state"] == "pending"
assert follow_activity_two.data["state"] == "pending" assert follow_activity_two.data["state"] == "pending"

View File

@ -1120,7 +1120,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
# Follow the user, then the pinned status can be seen # Follow the user, then the pinned status can be seen
CommonAPI.follow(reader, user) CommonAPI.follow(user, reader)
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert [%{"id" => ^activity_id, "pinned" => true}] = assert [%{"id" => ^activity_id, "pinned" => true}] =
@ -2118,7 +2118,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
test "pin account", %{user: user, conn: conn} do test "pin account", %{user: user, conn: conn} do
%{id: id1} = other_user1 = insert(:user) %{id: id1} = other_user1 = insert(:user)
CommonAPI.follow(user, other_user1) CommonAPI.follow(other_user1, user)
assert %{"id" => ^id1, "endorsed" => true} = assert %{"id" => ^id1, "endorsed" => true} =
conn conn
@ -2136,7 +2136,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
test "unpin account", %{user: user, conn: conn} do test "unpin account", %{user: user, conn: conn} do
%{id: id1} = other_user1 = insert(:user) %{id: id1} = other_user1 = insert(:user)
CommonAPI.follow(user, other_user1) CommonAPI.follow(other_user1, user)
User.endorse(user, other_user1) User.endorse(user, other_user1)
assert %{"id" => ^id1, "endorsed" => false} = assert %{"id" => ^id1, "endorsed" => false} =
@ -2156,8 +2156,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
%{id: id1} = other_user1 = insert(:user) %{id: id1} = other_user1 = insert(:user)
%{id: id2} = other_user2 = insert(:user) %{id: id2} = other_user2 = insert(:user)
CommonAPI.follow(user, other_user1) CommonAPI.follow(other_user1, user)
CommonAPI.follow(user, other_user2) CommonAPI.follow(other_user2, user)
conn conn
|> put_req_header("content-type", "application/json") |> put_req_header("content-type", "application/json")
@ -2227,7 +2227,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
test "removing user from followers", %{conn: conn, user: user} do test "removing user from followers", %{conn: conn, user: user} do
%{id: other_user_id} = other_user = insert(:user) %{id: other_user_id} = other_user = insert(:user)
CommonAPI.follow(other_user, user) CommonAPI.follow(user, other_user)
assert %{"id" => ^other_user_id, "followed_by" => false} = assert %{"id" => ^other_user_id, "followed_by" => false} =
conn conn
@ -2240,7 +2240,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
test "removing remote user from followers", %{conn: conn, user: user} do test "removing remote user from followers", %{conn: conn, user: user} do
%{id: other_user_id} = other_user = insert(:user, local: false) %{id: other_user_id} = other_user = insert(:user, local: false)
CommonAPI.follow(other_user, user) CommonAPI.follow(user, other_user)
assert User.following?(other_user, user) assert User.following?(other_user, user)

View File

@ -20,7 +20,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
test "/api/v1/follow_requests works", %{user: user, conn: conn} do test "/api/v1/follow_requests works", %{user: user, conn: conn} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, _activity} = CommonAPI.follow(other_user, user) {:ok, _, _, _activity} = CommonAPI.follow(user, other_user)
{:ok, other_user, user} = User.follow(other_user, user, :follow_pending) {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
assert User.following?(other_user, user) == false assert User.following?(other_user, user) == false
@ -34,7 +34,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, _activity} = CommonAPI.follow(other_user, user) {:ok, _, _, _activity} = CommonAPI.follow(user, other_user)
{:ok, other_user, user} = User.follow(other_user, user, :follow_pending) {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
user = User.get_cached_by_id(user.id) user = User.get_cached_by_id(user.id)
@ -56,7 +56,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
test "/api/v1/follow_requests/:id/reject works", %{user: user, conn: conn} do test "/api/v1/follow_requests/:id/reject works", %{user: user, conn: conn} do
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, _activity} = CommonAPI.follow(other_user, user) {:ok, _, _, _activity} = CommonAPI.follow(user, other_user)
user = User.get_cached_by_id(user.id) user = User.get_cached_by_id(user.id)

View File

@ -434,7 +434,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, other_user) {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, other_user)
{:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user) {:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, other_user)
mention_notification_id = get_notification_id_by_activity(mention_activity) mention_notification_id = get_notification_id_by_activity(mention_activity)
favorite_notification_id = get_notification_id_by_activity(favorite_activity) favorite_notification_id = get_notification_id_by_activity(favorite_activity)
@ -472,7 +472,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, other_user) {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, other_user)
{:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user) {:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, other_user)
mention_notification_id = get_notification_id_by_activity(mention_activity) mention_notification_id = get_notification_id_by_activity(mention_activity)
favorite_notification_id = get_notification_id_by_activity(favorite_activity) favorite_notification_id = get_notification_id_by_activity(favorite_activity)
@ -519,7 +519,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
{:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})
{:ok, _activity} = CommonAPI.favorite(create_activity.id, other_user) {:ok, _activity} = CommonAPI.favorite(create_activity.id, other_user)
{:ok, _activity} = CommonAPI.repeat(create_activity.id, other_user) {:ok, _activity} = CommonAPI.repeat(create_activity.id, other_user)
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) {:ok, _, _, follow_activity} = CommonAPI.follow(user, other_user)
follow_notification_id = get_notification_id_by_activity(follow_activity) follow_notification_id = get_notification_id_by_activity(follow_activity)
@ -578,7 +578,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
%{user: user, conn: conn} = oauth_access(["read:notifications"]) %{user: user, conn: conn} = oauth_access(["read:notifications"])
user2 = insert(:user) user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2) {:ok, _, _, _} = CommonAPI.follow(user2, user)
{:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"}) {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
ret_conn = get(conn, "/api/v1/notifications") ret_conn = get(conn, "/api/v1/notifications")
@ -596,7 +596,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
%{user: user, conn: conn} = oauth_access(["read:notifications"]) %{user: user, conn: conn} = oauth_access(["read:notifications"])
user2 = insert(:user) user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2) {:ok, _, _, _} = CommonAPI.follow(user2, user)
{:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"}) {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
ret_conn = get(conn, "/api/v1/notifications") ret_conn = get(conn, "/api/v1/notifications")
@ -614,7 +614,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
%{user: user, conn: conn} = oauth_access(["read:notifications"]) %{user: user, conn: conn} = oauth_access(["read:notifications"])
user2 = insert(:user) user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2) {:ok, _, _, _} = CommonAPI.follow(user2, user)
{:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"}) {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"})
ret_conn = get(conn, "/api/v1/notifications") ret_conn = get(conn, "/api/v1/notifications")

View File

@ -59,7 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
test "returns v2 suggestions excluding followed accounts", %{conn: conn, user: follower} do test "returns v2 suggestions excluding followed accounts", %{conn: conn, user: follower} do
followed = insert(:user, is_suggested: true) followed = insert(:user, is_suggested: true)
{:ok, _, _, _} = CommonAPI.follow(follower, followed) {:ok, _, _, _} = CommonAPI.follow(followed, follower)
res = res =
conn conn

View File

@ -493,7 +493,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
user = insert(:user) user = insert(:user)
other_user = insert(:user, is_locked: true) other_user = insert(:user, is_locked: true)
{:ok, user, other_user, _} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _} = CommonAPI.follow(other_user, user)
user = User.get_cached_by_id(user.id) user = User.get_cached_by_id(user.id)
other_user = User.get_cached_by_id(other_user.id) other_user = User.get_cached_by_id(other_user.id)
@ -547,8 +547,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
}) })
other_user = insert(:user) other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{ assert %{
followers_count: 0, followers_count: 0,
@ -560,8 +560,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
test "shows when follows/followers are hidden" do test "shows when follows/followers are hidden" do
user = insert(:user, hide_followers: true, hide_follows: true) user = insert(:user, hide_followers: true, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{ assert %{
followers_count: 1, followers_count: 1,
@ -573,11 +573,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
test "shows actual follower/following count to the account owner" do test "shows actual follower/following count to the account owner" do
user = insert(:user, hide_followers: true, hide_follows: true) user = insert(:user, hide_followers: true, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user) {:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user)
assert User.following?(user, other_user) assert User.following?(user, other_user)
assert Pleroma.FollowingRelationship.follower_count(other_user) == 1 assert Pleroma.FollowingRelationship.follower_count(other_user) == 1
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{ assert %{
followers_count: 1, followers_count: 1,
@ -684,7 +684,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{follow_requests_count: 0} = assert %{follow_requests_count: 0} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -696,7 +696,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{locked: true, follow_requests_count: 1} = assert %{locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -708,7 +708,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{locked: true, follow_requests_count: 1} = assert %{locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -725,7 +725,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, other_user, user, _activity} = CommonAPI.follow(user, other_user)
assert %{locked: true, follow_requests_count: 1} = assert %{locked: true, follow_requests_count: 1} =
AccountView.render("show.json", %{user: user, for: user}) AccountView.render("show.json", %{user: user, for: user})
@ -742,7 +742,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user}) assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
other_user = insert(:user) other_user = insert(:user)
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user)
{:ok, user} = User.update_and_set_cache(user, %{is_locked: false}) {:ok, user} = User.update_and_set_cache(user, %{is_locked: false})

View File

@ -132,7 +132,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
test "Follow notification" do test "Follow notification" do
follower = insert(:user) follower = insert(:user)
followed = insert(:user) followed = insert(:user)
{:ok, follower, followed, _activity} = CommonAPI.follow(follower, followed) {:ok, follower, followed, _activity} = CommonAPI.follow(followed, follower)
notification = Notification |> Repo.one() |> Repo.preload(:activity) notification = Notification |> Repo.one() |> Repo.preload(:activity)
expected = %{ expected = %{

View File

@ -479,7 +479,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
# After following the user, the quote is rendered # After following the user, the quote is rendered
follower = insert(:user) follower = insert(:user)
CommonAPI.follow(follower, user) CommonAPI.follow(user, follower)
status = StatusView.render("show.json", %{activity: quote_private, for: follower}) status = StatusView.render("show.json", %{activity: quote_private, for: follower})
assert status.pleroma.quote.id == to_string(private.id) assert status.pleroma.quote.id == to_string(private.id)

View File

@ -286,8 +286,8 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
%{id: id2} = user2 = insert(:user) %{id: id2} = user2 = insert(:user)
%{id: id3} = user3 = insert(:user) %{id: id3} = user3 = insert(:user)
CommonAPI.follow(user1, user2) CommonAPI.follow(user2, user1)
CommonAPI.follow(user1, user3) CommonAPI.follow(user3, user1)
User.endorse(user1, user2) User.endorse(user1, user2)
User.endorse(user1, user3) User.endorse(user1, user3)
@ -324,9 +324,9 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
user3 = insert(:user) user3 = insert(:user)
CommonAPI.follow(user, user1) CommonAPI.follow(user1, user)
CommonAPI.follow(user, user2) CommonAPI.follow(user2, user)
CommonAPI.follow(user, user3) CommonAPI.follow(user3, user)
[%{"id" => ^id1}] = [%{"id" => ^id1}] =
conn conn
@ -350,8 +350,8 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
show_birthday: true show_birthday: true
}) })
CommonAPI.follow(user, user1) CommonAPI.follow(user1, user)
CommonAPI.follow(user, user2) CommonAPI.follow(user2, user)
[%{"id" => ^id2}] = [%{"id" => ^id2}] =
conn conn

View File

@ -78,7 +78,7 @@ defmodule Pleroma.Web.Push.ImplTest do
) )
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, activity} = CommonAPI.follow(user, other_user) {:ok, _, _, activity} = CommonAPI.follow(other_user, user)
notif = notif =
insert(:notification, insert(:notification,
@ -103,7 +103,7 @@ defmodule Pleroma.Web.Push.ImplTest do
) )
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, activity} = CommonAPI.follow(user, other_user) {:ok, _, _, activity} = CommonAPI.follow(other_user, user)
notif = notif =
insert(:notification, insert(:notification,
@ -154,7 +154,7 @@ defmodule Pleroma.Web.Push.ImplTest do
test "renders title and body for follow activity" do test "renders title and body for follow activity" do
user = insert(:user, nickname: "Bob") user = insert(:user, nickname: "Bob")
other_user = insert(:user) other_user = insert(:user)
{:ok, _, _, activity} = CommonAPI.follow(user, other_user) {:ok, _, _, activity} = CommonAPI.follow(other_user, user)
object = Object.normalize(activity, fetch: false) object = Object.normalize(activity, fetch: false)
assert Impl.format_body(%{activity: activity, type: "follow"}, user, object) == assert Impl.format_body(%{activity: activity, type: "follow"}, user, object) ==

View File

@ -477,7 +477,7 @@ defmodule Pleroma.Web.StreamerTest do
user2 = insert(:user) user2 = insert(:user)
Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) Streamer.get_topic_and_add_socket("user:notification", user, oauth_token)
{:ok, _follower, _followed, follow_activity} = CommonAPI.follow(user2, user) {:ok, _follower, _followed, follow_activity} = CommonAPI.follow(user, user2)
assert_receive {:render_with_user, _, "notification.json", notif, _} assert_receive {:render_with_user, _, "notification.json", notif, _}
assert notif.activity.id == follow_activity.id assert notif.activity.id == follow_activity.id
@ -493,7 +493,7 @@ defmodule Pleroma.Web.StreamerTest do
other_user_id = other_user.id other_user_id = other_user.id
Streamer.get_topic_and_add_socket("user", user, oauth_token) Streamer.get_topic_and_add_socket("user", user, oauth_token)
{:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(user, other_user) {:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(other_user, user)
assert_receive {:text, event} assert_receive {:text, event}
@ -536,7 +536,7 @@ defmodule Pleroma.Web.StreamerTest do
test "it streams edits in the 'user' stream", %{user: user, token: oauth_token} do test "it streams edits in the 'user' stream", %{user: user, token: oauth_token} do
sender = insert(:user) sender = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, sender) {:ok, _, _, _} = CommonAPI.follow(sender, user)
{:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) {:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
@ -826,7 +826,7 @@ defmodule Pleroma.Web.StreamerTest do
test "it filters muted reblogs", %{user: user1, token: user1_token} do test "it filters muted reblogs", %{user: user1, token: user1_token} do
user2 = insert(:user) user2 = insert(:user)
user3 = insert(:user) user3 = insert(:user)
CommonAPI.follow(user1, user2) CommonAPI.follow(user2, user1)
CommonAPI.hide_reblogs(user1, user2) CommonAPI.hide_reblogs(user1, user2)
{:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"}) {:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"})
@ -842,7 +842,7 @@ defmodule Pleroma.Web.StreamerTest do
token: user1_token token: user1_token
} do } do
user2 = insert(:user) user2 = insert(:user)
CommonAPI.follow(user1, user2) CommonAPI.follow(user2, user1)
CommonAPI.hide_reblogs(user1, user2) CommonAPI.hide_reblogs(user1, user2)
{:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"}) {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
@ -858,7 +858,7 @@ defmodule Pleroma.Web.StreamerTest do
token: user1_token token: user1_token
} do } do
user2 = insert(:user) user2 = insert(:user)
CommonAPI.follow(user1, user2) CommonAPI.follow(user2, user1)
CommonAPI.hide_reblogs(user1, user2) CommonAPI.hide_reblogs(user1, user2)
{:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"}) {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"})
@ -876,7 +876,7 @@ defmodule Pleroma.Web.StreamerTest do
%{user: user2, token: user2_token} = oauth_access(["read"]) %{user: user2, token: user2_token} = oauth_access(["read"])
Streamer.get_topic_and_add_socket("user", user2, user2_token) Streamer.get_topic_and_add_socket("user", user2, user2_token)
{:ok, user2, user, _activity} = CommonAPI.follow(user2, user) {:ok, user2, user, _activity} = CommonAPI.follow(user, user2)
{:ok, activity} = CommonAPI.post(user, %{status: "super hot take"}) {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"})
{:ok, _} = CommonAPI.add_mute(activity, user2) {:ok, _} = CommonAPI.add_mute(activity, user2)
@ -1026,8 +1026,8 @@ defmodule Pleroma.Web.StreamerTest do
%{user: user2, token: user2_token} = oauth_access(["read"]) %{user: user2, token: user2_token} = oauth_access(["read"])
post_user = insert(:user) post_user = insert(:user)
CommonAPI.follow(user, post_user) CommonAPI.follow(post_user, user)
CommonAPI.follow(user2, post_user) CommonAPI.follow(post_user, user2)
tasks = [ tasks = [
Task.async(child_proc.(starter.(user, token), hit)), Task.async(child_proc.(starter.(user, token), hit)),
@ -1058,7 +1058,7 @@ defmodule Pleroma.Web.StreamerTest do
%{user: user, token: token} = oauth_access(["read"]) %{user: user, token: token} = oauth_access(["read"])
post_user = insert(:user) post_user = insert(:user)
CommonAPI.follow(user, post_user) CommonAPI.follow(post_user, user)
tasks = [ tasks = [
Task.async(child_proc.(starter.(user, token), hit)), Task.async(child_proc.(starter.(user, token), hit)),

View File

@ -216,7 +216,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
test "returns success result when user already in followers", %{conn: conn} do test "returns success result when user already in followers", %{conn: conn} do
user = insert(:user) user = insert(:user)
user2 = insert(:user) user2 = insert(:user)
{:ok, _, _, _} = CommonAPI.follow(user, user2) {:ok, _, _, _} = CommonAPI.follow(user2, user)
conn = conn =
conn conn