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 @@ def move_following(origin, target) 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 @@ def perform(:follow_import, %User{} = follower, [_ | _] = identifiers) 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 @@ defp try_follow(follower, message) 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 @@ def get_actor, do: User.get_or_create_service_actor_by_ap_id(ap_id(), @nickname)
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 @@ def unblock(blocked, blocker) 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 @@ defp status?(acct) 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 @@ def do_follow(conn, %{"authorization" => %{"name" => _, "password" => _, "id" =>
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 @@ def do_follow(conn, %{"mfa" => %{"code" => code, "token" => token, "id" => id}})
{_, _, {: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 @@ test "disconnect when token is revoked", %{app: app, user: user, token: token} d
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 @@ test "receives private statuses", %{user: reading_user, token: token} 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 @@ test "receives edits", %{user: reading_user, token: token} 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 @@ test "it disables notifications from non-followees" 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 @@ test "it allows notifications from followees" 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 @@ test "it doesn't create duplicate notifications for follow+subscribed users" 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 @@ test "it creates `follow` notification for approved Follow activity" 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 @@ test "it creates `follow_request` notification for pending Follow activity" 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 @@ test "it doesn't create a notification for follow-unfollow-follow chains" 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 @@ test "it doesn't create a notification for follow-unfollow-follow chains" 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 @@ test "it returns notifications when related object is without content and filter
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 @@ test "doesn't count unrelated activities" 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 @@ test "it creates a zip archive with user data" 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 @@ test "returns all pending follow requests" 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 @@ test "doesn't return already accepted or duplicate follow requests" 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 @@ test "doesn't return follow requests for deactivated accounts" 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 @@ test "clears follow requests when requester is blocked" 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 @@ test "it renders the page, if the user has 'hide_followers' set and the request
%{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 @@ test "it renders the page, if the user has 'hide_follows' set and the request is
%{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 @@ test "doesn't return activities from blocked domains" 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 @@ test "it reverts unfollow activity" 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 @@ test "creates an undo activity for the last follow" 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 @@ test "creates an undo activity for a pending follow request" 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 @@ test "has a matching host" 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 @@ test "returns errors when user not found" 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 @@ test "force unfollow when target service is dead" 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 @@ test "creates a notification", %{announce: announce, poster: poster} 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 @@ test "it works for incoming accepts which were pre-accepted" 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 @@ test "it works for incoming accepts which are referenced by IRI only" 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 @@ test "it works for incoming rejects which are referenced by IRI only" 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 @@ test "updates the state of all Follow activities with the same actor and object"
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 @@ test "also updates the state of accepted follows" 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 @@ test "updates the state of the given follow activity" 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 @@ test "instance users do not expose oAuth endpoints" 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 @@ test "sets totalItems to zero when followers are hidden" 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 @@ test "sets correct totalItems when followers are hidden but the follower counter
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 @@ test "sets totalItems to zero when follows are hidden" 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 @@ test "single user", %{admin: admin, conn: conn} 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 @@ test "it posts a poll" 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 @@ test "repeating a status privately" 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 @@ test "remove a reblog mute", %{muter: muter, muted: muted} 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 @@ test "directly follows a non-locked local user" 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 @@ test "also unsubscribes a user" 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 @@ test "cancels a pending follow for a local user" 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 @@ test "cancels a pending follow for a remote user" 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 @@ test "after acceptance, it sets all existing pending follow request states to 'a
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 @@ test "after rejection, it sets all existing pending follow request states to 're
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 @@ test "view pinned private statuses" 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 @@ test "create a note on a user" 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 @@ test "pin account", %{user: user, conn: conn} 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 @@ test "max pinned accounts", %{user: user, conn: conn} 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 @@ test "it respects hide_followers", %{user: user, conn: conn} 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 @@ test "removing user from followers", %{conn: conn, user: user} 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 @@ test "/api/v1/follow_requests works", %{user: user, conn: conn} 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 @@ test "/api/v1/follow_requests/:id/authorize works", %{user: user, conn: conn} 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 @@ test "filters notifications using exclude_types" 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 @@ test "filters notifications using types" 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 @@ test "filtering falls back to include_types" 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 @@ test "doesn't see notifications after muting user with notifications" 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 @@ test "see notifications after muting user without notifications" 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 @@ test "see notifications after muting user with notifications and with_muted para
%{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 @@ test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: bl
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 @@ test "represent a relationship for the user with a pending follow request" 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 @@ test "shows when follows/followers stats are hidden and sets follow/follower cou
}) })
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 @@ test "shows when follows/followers stats are hidden and sets follow/follower cou
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 @@ test "shows when follows/followers are hidden" 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 @@ test "shows zero when no follow requests are pending" 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 @@ test "shows non-zero when follow requests are pending" 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 @@ test "decreases when accepting a follow request" 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 @@ test "decreases when rejecting a follow request" 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 @@ test "shows non-zero when historical unapproved requests are present" 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 @@ test "Reblog notification" 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 @@ test "quoted private post" 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 @@ test "returns a list of pinned accounts", %{conn: conn} 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 @@ test "returns a list of friends having birthday on specified day" 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 @@ test "the list doesn't list friends with hidden birth date" 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 @@ test "fail message sending" 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 @@ test "delete subscription if result send message between 400..500" 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 @@ test "renders title and body for create activity" 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 @@ test "it sends follow activities to the 'user:notification' stream", %{
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 @@ test "it sends follow relationships updates to the 'user' stream", %{
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 @@ test "it sends follow relationships updates to the 'user' stream", %{
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 @@ test "it sends wanted private posts to list", %{user: user_a, token: user_a_toke
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 @@ test "it filters reblog notification for reblog-muted actors", %{
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 @@ test "it send non-reblog notification for reblog-muted actors", %{
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 @@ test "it filters posts from muted threads" 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 @@ test "do not revoke other tokens", %{
%{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 @@ test "revoke all streams for this token", %{
%{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 @@ test "returns error when followee not found", %{conn: conn} 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