From 3a79f060bb06ff862270eae67a59e98651f3f2d7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 15:11:38 -0400 Subject: [PATCH 01/15] Add missing type --- lib/pleroma/conversation/participation.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pleroma/conversation/participation.ex b/lib/pleroma/conversation/participation.ex index 4ed93e5bd..5d3344cc5 100644 --- a/lib/pleroma/conversation/participation.ex +++ b/lib/pleroma/conversation/participation.ex @@ -12,6 +12,8 @@ defmodule Pleroma.Conversation.Participation do import Ecto.Changeset import Ecto.Query + @type t :: %__MODULE__{} + schema "conversation_participations" do belongs_to(:user, User, type: FlakeId.Ecto.CompatType) belongs_to(:conversation, Conversation) From b1d33483310df3b5b5a4570ffc33f55b2eeca9b6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 15:12:34 -0400 Subject: [PATCH 02/15] Annotate public functions with typespecs and mark some functions as private --- lib/pleroma/web/common_api.ex | 48 ++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 36e7efd8d..411acf8fb 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -26,6 +26,7 @@ defmodule Pleroma.Web.CommonAPI do require Pleroma.Constants require Logger + @spec block(User.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()} def block(blocker, blocked) do with {:ok, block_data, _} <- Builder.block(blocker, blocked), {:ok, block, _} <- Pipeline.common_pipeline(block_data, local: true) do @@ -33,6 +34,8 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec post_chat_message(User.t(), User.t(), String.t(), list()) :: + {:ok, Activity.t()} | {:error, any()} def post_chat_message(%User{} = user, %User{} = recipient, content, opts \\ []) do with maybe_attachment <- opts[:media_id] && Object.get_by_id(opts[:media_id]), :ok <- validate_chat_attachment_attribution(maybe_attachment, user), @@ -96,6 +99,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec unblock(User.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()} def unblock(blocker, blocked) do with {_, %Activity{} = block} <- {:fetch_block, Utils.fetch_latest_block(blocker, blocked)}, {:ok, unblock_data, _} <- Builder.undo(blocker, block), @@ -115,6 +119,8 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec follow(User.t(), User.t()) :: + {:ok, User.t(), User.t(), Activity.t() | Object.t()} | {:error, :rejected} def follow(follower, followed) do timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout]) @@ -129,6 +135,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec unfollow(User.t(), User.t()) :: {:ok, User.t()} | {:error, any()} def unfollow(follower, unfollowed) do with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed), {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed), @@ -138,6 +145,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec accept_follow_request(User.t(), User.t()) :: {:ok, User.t()} | {:error, any()} def accept_follow_request(follower, followed) do with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), {:ok, accept_data, _} <- Builder.accept(followed, follow_activity), @@ -146,6 +154,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec reject_follow_request(User.t(), User.t()) :: {:ok, User.t()} | {:error, any()} | nil def reject_follow_request(follower, followed) do with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed), {:ok, reject_data, _} <- Builder.reject(followed, follow_activity), @@ -154,6 +163,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec delete(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()} def delete(activity_id, user) do with {_, %Activity{data: %{"object" => _, "type" => "Create"}} = activity} <- {:find_activity, Activity.get_by_id(activity_id, filter: [])}, @@ -203,6 +213,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec repeat(String.t(), User.t(), map()) :: {:ok, Activity.t()} | {:error, any()} def repeat(id, user, params \\ %{}) do with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(id), object = %Object{} <- Object.normalize(activity, fetch: false), @@ -220,6 +231,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec unrepeat(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()} def unrepeat(id, user) do with {_, %Activity{data: %{"type" => "Create"}} = activity} <- {:find_activity, Activity.get_by_id(id)}, @@ -235,7 +247,7 @@ defmodule Pleroma.Web.CommonAPI do end end - @spec favorite(User.t(), binary()) :: {:ok, Activity.t() | :already_liked} | {:error, any()} + @spec favorite(User.t(), String.t()) :: {:ok, Activity.t()} | {:error, any()} def favorite(%User{} = user, id) do case favorite_helper(user, id) do {:ok, _} = res -> @@ -250,7 +262,7 @@ defmodule Pleroma.Web.CommonAPI do end end - def favorite_helper(user, id) do + defp favorite_helper(user, id) do with {_, %Activity{object: object}} <- {:find_object, Activity.get_by_id_with_object(id)}, {_, {:ok, like_object, meta}} <- {:build_object, Builder.like(user, object)}, {_, {:ok, %Activity{} = activity, _meta}} <- @@ -273,6 +285,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec unfavorite(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()} def unfavorite(id, user) do with {_, %Activity{data: %{"type" => "Create"}} = activity} <- {:find_activity, Activity.get_by_id(id)}, @@ -288,6 +301,8 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec react_with_emoji(String.t(), User.t(), String.t()) :: + {:ok, Activity.t()} | {:error, any()} def react_with_emoji(id, user, emoji) do with %Activity{} = activity <- Activity.get_by_id(id), object <- Object.normalize(activity, fetch: false), @@ -300,6 +315,8 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec unreact_with_emoji(String.t(), User.t(), String.t()) :: + {:ok, Activity.t()} | {:error, any()} def unreact_with_emoji(id, user, emoji) do with %Activity{} = reaction_activity <- Utils.get_latest_reaction(id, user, emoji), {_, {:ok, _}} <- {:cancel_jobs, maybe_cancel_jobs(reaction_activity)}, @@ -312,6 +329,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec vote(User.t(), Object.t(), list()) :: {:ok, list(), Object.t()} | {:error, any()} def vote(user, %{data: %{"type" => "Question"}} = object, choices) do with :ok <- validate_not_author(object, user), :ok <- validate_existing_votes(user, object), @@ -373,14 +391,16 @@ defmodule Pleroma.Web.CommonAPI do end end - def public_announce?(_, %{visibility: visibility}) - when visibility in ~w{public unlisted private direct}, - do: visibility in ~w(public unlisted) + defp public_announce?(_, %{visibility: visibility}) + when visibility in ~w{public unlisted private direct}, + do: visibility in ~w(public unlisted) - def public_announce?(object, _) do + defp public_announce?(object, _) do Visibility.public?(object) end + @spec get_visibility(map(), map() | nil, Participation.t() | nil) :: + {String.t() | nil, String.t() | nil} def get_visibility(_, _, %Participation{}), do: {"direct", "direct"} def get_visibility(%{visibility: visibility}, in_reply_to, _) @@ -399,6 +419,7 @@ defmodule Pleroma.Web.CommonAPI do def get_visibility(_, in_reply_to, _), do: {"public", get_replied_to_visibility(in_reply_to)} + @spec get_replied_to_visibility(Activity.t() | nil) :: String.t() | nil def get_replied_to_visibility(nil), do: nil def get_replied_to_visibility(activity) do @@ -407,6 +428,8 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec check_expiry_date({:ok, nil | integer()} | String.t()) :: + {:ok, boolean() | nil} | {:error, String.t()} def check_expiry_date({:ok, nil} = res), do: res def check_expiry_date({:ok, in_seconds}) do @@ -424,18 +447,21 @@ defmodule Pleroma.Web.CommonAPI do |> check_expiry_date() end + @spec listen(User.t(), map()) :: {:ok, Activity.t()} | {:error, any()} def listen(user, data) do with {:ok, draft} <- ActivityDraft.listen(user, data) do ActivityPub.listen(draft.changes) end end + @spec post(User.t(), map()) :: {:ok, Activity.t()} | {:error, any()} def post(user, %{status: _} = data) do with {:ok, draft} <- ActivityDraft.create(user, data) do ActivityPub.create(draft.changes, draft.preview?) end end + @spec update(User.t(), Activity.t(), map()) :: {:ok, Activity.t()} | {:error, any()} def update(user, orig_activity, changes) do with orig_object <- Object.normalize(orig_activity), {:ok, new_object} <- make_update_data(user, orig_object, changes), @@ -526,6 +552,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec add_mute(User.t(), Activity.t(), map()) :: {:ok, Activity.t()} | {:error, any()} def add_mute(user, activity, params \\ %{}) do expires_in = Map.get(params, :expires_in, 0) @@ -545,6 +572,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec remove_mute(User.t(), Activity.t()) :: {:ok, Activity.t()} | {:error, any()} def remove_mute(%User{} = user, %Activity{} = activity) do ThreadMute.remove_mute(user.id, activity.data["context"]) {:ok, activity} @@ -564,6 +592,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec thread_muted?(User.t(), Activity.t()) :: boolean() def thread_muted?(%User{id: user_id}, %{data: %{"context" => context}}) when is_binary(context) do ThreadMute.exists?(user_id, context) @@ -571,6 +600,7 @@ defmodule Pleroma.Web.CommonAPI do def thread_muted?(_, _), do: false + @spec report(User.t(), map()) :: {:ok, Activity.t()} | {:error, any()} def report(user, data) do with {:ok, account} <- get_reported_account(data.account_id), {:ok, {content_html, _, _}} <- make_report_content_html(data[:comment]), @@ -604,6 +634,8 @@ defmodule Pleroma.Web.CommonAPI do |> Enum.filter(&Rule.exists?/1) end + @spec update_report_state(String.t() | [String.t()], String.t()) :: + {:ok, any()} | {:error, any()} def update_report_state(activity_ids, state) when is_list(activity_ids) do case Utils.update_report_state(activity_ids, state) do :ok -> {:ok, activity_ids} @@ -619,6 +651,7 @@ defmodule Pleroma.Web.CommonAPI do end end + @spec update_activity_scope(String.t(), map()) :: {:ok, any()} | {:error, any()} def update_activity_scope(activity_id, opts \\ %{}) do with %Activity{} = activity <- Activity.get_by_id_with_object(activity_id), {:ok, activity} <- toggle_sensitive(activity, opts) do @@ -652,14 +685,17 @@ defmodule Pleroma.Web.CommonAPI do defp set_visibility(activity, _), do: {:ok, activity} + @spec hide_reblogs(User.t(), User.t()) :: {:ok, any()} | {:error, any()} def hide_reblogs(%User{} = user, %User{} = target) do UserRelationship.create_reblog_mute(user, target) end + @spec show_reblogs(User.t(), User.t()) :: {:ok, any()} | {:error, any()} def show_reblogs(%User{} = user, %User{} = target) do UserRelationship.delete_reblog_mute(user, target) end + @spec get_user(String.t(), boolean()) :: User.t() | nil def get_user(ap_id, fake_record_fallback \\ true) do cond do user = User.get_cached_by_ap_id(ap_id) -> From 7e37882cf7c8a12f13c9525fe70e286d2101af46 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 17:19:31 -0400 Subject: [PATCH 03/15] Fix order of args for favorite/2 --- lib/pleroma/web/common_api.ex | 4 ++-- .../controllers/status_controller.ex | 2 +- test/mix/tasks/pleroma/database_test.exs | 6 ++--- test/pleroma/activity_test.exs | 2 +- .../notification_backfill_test.exs | 2 +- test/pleroma/notification_test.exs | 12 +++++----- test/pleroma/object_test.exs | 2 +- test/pleroma/resilience_test.exs | 4 ++-- test/pleroma/stats_test.exs | 2 +- test/pleroma/user/backup_test.exs | 10 ++++---- test/pleroma/user_test.exs | 4 ++-- .../activity_pub_controller_test.exs | 2 +- .../web/activity_pub/activity_pub_test.exs | 16 ++++++------- .../like_validation_test.exs | 2 +- .../object_validators/undo_handling_test.exs | 2 +- .../activity_pub/side_effects/delete_test.exs | 2 +- .../web/activity_pub/side_effects_test.exs | 2 +- test/pleroma/web/activity_pub/utils_test.exs | 6 ++--- .../activity_pub/views/object_view_test.exs | 2 +- test/pleroma/web/common_api_test.exs | 18 +++++++------- .../notification_controller_test.exs | 16 ++++++------- .../controllers/status_controller_test.exs | 24 +++++++++---------- .../views/notification_view_test.exs | 4 ++-- .../web/o_status/o_status_controller_test.exs | 2 +- .../controllers/account_controller_test.exs | 16 ++++++------- test/pleroma/web/push/impl_test.exs | 6 ++--- test/pleroma/web/streamer_test.exs | 10 ++++---- 27 files changed, 90 insertions(+), 90 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 411acf8fb..f8a03680a 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -247,8 +247,8 @@ defmodule Pleroma.Web.CommonAPI do end end - @spec favorite(User.t(), String.t()) :: {:ok, Activity.t()} | {:error, any()} - def favorite(%User{} = user, id) do + @spec favorite(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()} + def favorite(id, %User{} = user) do case favorite_helper(user, id) do {:ok, _} = res -> res diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 83e1bee54..80386dc45 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -357,7 +357,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do conn, _ ) do - with {:ok, _fav} <- CommonAPI.favorite(user, activity_id), + with {:ok, _fav} <- CommonAPI.favorite(activity_id, user), %Activity{} = activity <- Activity.get_by_id(activity_id) do try_render(conn, "show.json", activity: activity, for: user, as: :activity) end diff --git a/test/mix/tasks/pleroma/database_test.exs b/test/mix/tasks/pleroma/database_test.exs index d773038cb..a51a3bf3d 100644 --- a/test/mix/tasks/pleroma/database_test.exs +++ b/test/mix/tasks/pleroma/database_test.exs @@ -251,7 +251,7 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do |> Repo.update!() {:ok, old_favourite_activity} = - CommonAPI.favorite(remote_user2, old_remote_post_activity.id) + CommonAPI.favorite(old_remote_post_activity.id, remote_user2) old_favourite_activity |> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date}) @@ -302,7 +302,7 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do |> Ecto.Changeset.change(%{local: false, updated_at: old_insert_date}) |> Repo.update!() - {:ok, old_favourite_activity} = CommonAPI.favorite(local_user, old_remote_post3_activity.id) + {:ok, old_favourite_activity} = CommonAPI.favorite(old_remote_post3_activity.id, local_user) old_favourite_activity |> Ecto.Changeset.change(%{local: true, updated_at: old_insert_date}) @@ -586,7 +586,7 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do {:ok, %{id: id, object: object}} = CommonAPI.post(user, %{status: "test"}) {:ok, %{object: object2}} = CommonAPI.post(user, %{status: "test test"}) - CommonAPI.favorite(user2, id) + CommonAPI.favorite(id, user2) likes = %{ "first" => diff --git a/test/pleroma/activity_test.exs b/test/pleroma/activity_test.exs index 67943d879..62d07b1ee 100644 --- a/test/pleroma/activity_test.exs +++ b/test/pleroma/activity_test.exs @@ -249,7 +249,7 @@ defmodule Pleroma.ActivityTest do {:ok, %{id: id, object: %{data: %{"id" => obj_id}}}} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"}) - Pleroma.Web.CommonAPI.favorite(another, id) + Pleroma.Web.CommonAPI.favorite(id, another) assert obj_id |> Pleroma.Activity.Queries.by_object_id() diff --git a/test/pleroma/migration_helper/notification_backfill_test.exs b/test/pleroma/migration_helper/notification_backfill_test.exs index 6d47bb6a8..2797cfb2c 100644 --- a/test/pleroma/migration_helper/notification_backfill_test.exs +++ b/test/pleroma/migration_helper/notification_backfill_test.exs @@ -21,7 +21,7 @@ defmodule Pleroma.MigrationHelper.NotificationBackfillTest do {:ok, post} = CommonAPI.post(user, %{status: "yeah, @#{other_user.nickname}"}) {:ok, chat} = CommonAPI.post_chat_message(user, other_user, "yo") {:ok, react} = CommonAPI.react_with_emoji(post.id, other_user, "☕") - {:ok, like} = CommonAPI.favorite(other_user, post.id) + {:ok, like} = CommonAPI.favorite(post.id, other_user) {:ok, react_2} = CommonAPI.react_with_emoji(post.id, other_user, "☕") data = diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 21bea4c3f..e9923cb56 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -295,7 +295,7 @@ defmodule Pleroma.NotificationTest do insert(:filter, user: user, phrase: "tesla", hide: true) {:ok, activity_one} = CommonAPI.post(user, %{status: "wow tesla"}) - {:ok, activity_two} = CommonAPI.favorite(other_user, activity_one.id) + {:ok, activity_two} = CommonAPI.favorite(activity_one.id, other_user) {:ok, [notification]} = Notification.create_notifications(activity_two) @@ -617,7 +617,7 @@ defmodule Pleroma.NotificationTest do status: "hey @#{other_user.nickname}!" }) - {:ok, activity_two} = CommonAPI.favorite(third_user, activity_one.id) + {:ok, activity_two} = CommonAPI.favorite(activity_one.id, third_user) enabled_receivers = Notification.get_notified_from_activity(activity_two) @@ -768,7 +768,7 @@ defmodule Pleroma.NotificationTest do assert Enum.empty?(Notification.for_user(user)) - {:ok, _} = CommonAPI.favorite(other_user, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, other_user) assert length(Notification.for_user(user)) == 1 @@ -785,7 +785,7 @@ defmodule Pleroma.NotificationTest do assert Enum.empty?(Notification.for_user(user)) - {:ok, _} = CommonAPI.favorite(other_user, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, other_user) assert length(Notification.for_user(user)) == 1 @@ -840,7 +840,7 @@ defmodule Pleroma.NotificationTest do assert Enum.empty?(Notification.for_user(user)) - {:error, :not_found} = CommonAPI.favorite(other_user, activity.id) + {:error, :not_found} = CommonAPI.favorite(activity.id, other_user) assert Enum.empty?(Notification.for_user(user)) end @@ -1090,7 +1090,7 @@ defmodule Pleroma.NotificationTest do another_user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "Give me my cofe!"}) - {:ok, _} = CommonAPI.favorite(another_user, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, another_user) assert length(Notification.for_user(user)) == 1 end diff --git a/test/pleroma/object_test.exs b/test/pleroma/object_test.exs index 2025d93e4..48d4d86eb 100644 --- a/test/pleroma/object_test.exs +++ b/test/pleroma/object_test.exs @@ -403,7 +403,7 @@ defmodule Pleroma.ObjectTest do user = insert(:user) activity = Activity.get_create_by_object_ap_id(object.data["id"]) - {:ok, activity} = CommonAPI.favorite(user, activity.id) + {:ok, activity} = CommonAPI.favorite(activity.id, user) object = Object.get_by_ap_id(activity.data["object"]) assert object.data["like_count"] == 1 diff --git a/test/pleroma/resilience_test.exs b/test/pleroma/resilience_test.exs index 9dc5d0dd6..0c4195fa8 100644 --- a/test/pleroma/resilience_test.exs +++ b/test/pleroma/resilience_test.exs @@ -18,7 +18,7 @@ defmodule Pleroma.ResilienceTest do other_user = insert(:user) {:ok, post_one} = CommonAPI.post(user, %{status: "Here is a post"}) - {:ok, like} = CommonAPI.favorite(other_user, post_one.id) + {:ok, like} = CommonAPI.favorite(post_one.id, other_user) %{ user: user, @@ -90,7 +90,7 @@ defmodule Pleroma.ResilienceTest do |> json_response(200) # Favoriting again doesn't hurt - {:ok, _like_two} = CommonAPI.favorite(other_user, post.id) + {:ok, _like_two} = CommonAPI.favorite(post.id, other_user) post = Repo.get(Activity, post.id) diff --git a/test/pleroma/stats_test.exs b/test/pleroma/stats_test.exs index 37a085afc..a04bed28e 100644 --- a/test/pleroma/stats_test.exs +++ b/test/pleroma/stats_test.exs @@ -74,7 +74,7 @@ defmodule Pleroma.StatsTest do other_user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{visibility: "public", status: "hey"}) _ = CommonAPI.follow(user, other_user) - CommonAPI.favorite(other_user, activity.id) + CommonAPI.favorite(activity.id, other_user) CommonAPI.repeat(activity.id, other_user) assert %{"direct" => 0, "private" => 0, "public" => 1, "unlisted" => 0} = diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs index 753e35982..fbde7fde8 100644 --- a/test/pleroma/user/backup_test.exs +++ b/test/pleroma/user/backup_test.exs @@ -177,8 +177,8 @@ defmodule Pleroma.User.BackupTest do {:ok, %{object: %{data: %{"id" => id3}}} = status3} = CommonAPI.post(user, %{status: "status3"}) - CommonAPI.favorite(user, status1.id) - CommonAPI.favorite(user, status2.id) + CommonAPI.favorite(status1.id, user) + CommonAPI.favorite(status2.id, user) Bookmark.create(user.id, status2.id) Bookmark.create(user.id, status3.id) @@ -283,7 +283,7 @@ defmodule Pleroma.User.BackupTest do Enum.map(1..120, fn i -> {:ok, status} = CommonAPI.post(user, %{status: "status #{i}"}) - CommonAPI.favorite(user, status.id) + CommonAPI.favorite(status.id, user) Bookmark.create(user.id, status.id) end) @@ -337,8 +337,8 @@ defmodule Pleroma.User.BackupTest do {:ok, status1} = CommonAPI.post(user, %{status: "status1"}) {:ok, status2} = CommonAPI.post(user, %{status: "status2"}) {:ok, status3} = CommonAPI.post(user, %{status: "status3"}) - CommonAPI.favorite(user, status1.id) - CommonAPI.favorite(user, status2.id) + CommonAPI.favorite(status1.id, user) + CommonAPI.favorite(status2.id, user) Bookmark.create(user.id, status2.id) Bookmark.create(user.id, status3.id) diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 78018fedc..2dc1b839d 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -1691,8 +1691,8 @@ defmodule Pleroma.UserTest do object_two = insert(:note, user: follower) activity_two = insert(:note_activity, user: follower, note: object_two) - {:ok, like} = CommonAPI.favorite(user, activity_two.id) - {:ok, like_two} = CommonAPI.favorite(follower, activity.id) + {:ok, like} = CommonAPI.favorite(activity_two.id, user) + {:ok, like_two} = CommonAPI.favorite(activity.id, follower) {:ok, repeat} = CommonAPI.repeat(activity_two.id, user) {:ok, job} = User.delete(user) diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs index 043efeda1..cc67b72d2 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -1224,7 +1224,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do note = insert(:note_activity, user: reported_user) - Pleroma.Web.CommonAPI.favorite(another, note.id) + Pleroma.Web.CommonAPI.favorite(note.id, another) mock_json_body = "test/fixtures/mastodon/application_actor.json" diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index c3c59df35..2fc1f3520 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -1854,14 +1854,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do {:ok, a4} = CommonAPI.post(user2, %{status: "Agent Smith "}) {:ok, a5} = CommonAPI.post(user1, %{status: "Red or Blue "}) - {:ok, _} = CommonAPI.favorite(user, a4.id) - {:ok, _} = CommonAPI.favorite(other_user, a3.id) - {:ok, _} = CommonAPI.favorite(user, a3.id) - {:ok, _} = CommonAPI.favorite(other_user, a5.id) - {:ok, _} = CommonAPI.favorite(user, a5.id) - {:ok, _} = CommonAPI.favorite(other_user, a4.id) - {:ok, _} = CommonAPI.favorite(user, a1.id) - {:ok, _} = CommonAPI.favorite(other_user, a1.id) + {:ok, _} = CommonAPI.favorite(a4.id, user) + {:ok, _} = CommonAPI.favorite(a3.id, other_user) + {:ok, _} = CommonAPI.favorite(a3.id, user) + {:ok, _} = CommonAPI.favorite(a5.id, other_user) + {:ok, _} = CommonAPI.favorite(a5.id, user) + {:ok, _} = CommonAPI.favorite(a4.id, other_user) + {:ok, _} = CommonAPI.favorite(a1.id, user) + {:ok, _} = CommonAPI.favorite(a1.id, other_user) result = ActivityPub.fetch_favourites(user) assert Enum.map(result, & &1.id) == [a1.id, a5.id, a3.id, a4.id] diff --git a/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs index ebc181a6d..620173119 100644 --- a/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs @@ -94,7 +94,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do user: user, post_activity: post_activity } do - _like = CommonAPI.favorite(user, post_activity.id) + _like = CommonAPI.favorite(post_activity.id, user) refute LikeValidator.cast_and_validate(valid_like).valid? end diff --git a/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs index db95b8e3c..589b70ac7 100644 --- a/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs @@ -15,7 +15,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoHandlingTest do setup do user = insert(:user) {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"}) - {:ok, like} = CommonAPI.favorite(user, post_activity.id) + {:ok, like} = CommonAPI.favorite(post_activity.id, user) {:ok, valid_like_undo, []} = Builder.undo(user, like) %{user: user, like: like, valid_like_undo: valid_like_undo} diff --git a/test/pleroma/web/activity_pub/side_effects/delete_test.exs b/test/pleroma/web/activity_pub/side_effects/delete_test.exs index 9a2703c4c..637007b7e 100644 --- a/test/pleroma/web/activity_pub/side_effects/delete_test.exs +++ b/test/pleroma/web/activity_pub/side_effects/delete_test.exs @@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects.DeleteTest do {:ok, op} = CommonAPI.post(other_user, %{status: "big oof"}) {:ok, post} = CommonAPI.post(user, %{status: "hey", in_reply_to_id: op}) - {:ok, favorite} = CommonAPI.favorite(user, post.id) + {:ok, favorite} = CommonAPI.favorite(post.id, user) object = Object.normalize(post, fetch: false) {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"]) {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true) diff --git a/test/pleroma/web/activity_pub/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs index 7af50e12c..8c115cedd 100644 --- a/test/pleroma/web/activity_pub/side_effects_test.exs +++ b/test/pleroma/web/activity_pub/side_effects_test.exs @@ -516,7 +516,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do poster = insert(:user) user = insert(:user) {:ok, post} = CommonAPI.post(poster, %{status: "hey"}) - {:ok, like} = CommonAPI.favorite(user, post.id) + {:ok, like} = CommonAPI.favorite(post.id, user) {:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍") {:ok, announce} = CommonAPI.repeat(post.id, user) {:ok, block} = CommonAPI.block(user, poster) diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index cd61e3e4b..47eea9a25 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -220,7 +220,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do object = Object.normalize(activity, fetch: false) {:ok, [vote], object} = CommonAPI.vote(other_user, object, [0]) - {:ok, _activity} = CommonAPI.favorite(user, activity.id) + {:ok, _activity} = CommonAPI.favorite(activity.id, user) [fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object) assert fetched_vote.id == vote.id end @@ -355,7 +355,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do user = insert(:user) refute Utils.get_existing_like(user.ap_id, object) - {:ok, like_activity} = CommonAPI.favorite(user, note_activity.id) + {:ok, like_activity} = CommonAPI.favorite(note_activity.id, user) assert ^like_activity = Utils.get_existing_like(user.ap_id, object) end @@ -546,7 +546,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do target_account = insert(:user) {:ok, activity} = CommonAPI.post(posting_account, %{status: "foobar"}) - {:ok, like} = CommonAPI.favorite(target_account, activity.id) + {:ok, like} = CommonAPI.favorite(activity.id, target_account) context = Utils.generate_context_id() content = "foobar" diff --git a/test/pleroma/web/activity_pub/views/object_view_test.exs b/test/pleroma/web/activity_pub/views/object_view_test.exs index d94878e31..14258795f 100644 --- a/test/pleroma/web/activity_pub/views/object_view_test.exs +++ b/test/pleroma/web/activity_pub/views/object_view_test.exs @@ -59,7 +59,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do object = Object.normalize(note, fetch: false) user = insert(:user) - {:ok, like_activity} = CommonAPI.favorite(user, note.id) + {:ok, like_activity} = CommonAPI.favorite(note.id, user) result = ObjectView.render("object.json", %{object: like_activity}) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 4c1add82e..4f3bc6921 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -454,7 +454,7 @@ defmodule Pleroma.Web.CommonAPITest do users_serial |> Enum.map(fn user -> - CommonAPI.favorite(user, activity.id) + CommonAPI.favorite(activity.id, user) end) object = Object.get_by_ap_id(activity.data["object"]) @@ -463,7 +463,7 @@ defmodule Pleroma.Web.CommonAPITest do users |> Enum.map(fn user -> Task.async(fn -> - CommonAPI.favorite(user, activity.id) + CommonAPI.favorite(activity.id, user) end) end) |> Enum.map(&Task.await/1) @@ -974,7 +974,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, post_activity} = CommonAPI.post(other_user, %{status: "cofe"}) - {:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id) + {:ok, %Activity{data: data}} = CommonAPI.favorite(post_activity.id, user) assert data["type"] == "Like" assert data["actor"] == user.ap_id assert data["object"] == post_activity.data["object"] @@ -994,8 +994,8 @@ defmodule Pleroma.Web.CommonAPITest do other_user = insert(:user) {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"}) - {:ok, %Activity{}} = CommonAPI.favorite(user, activity.id) - assert {:ok, :already_liked} = CommonAPI.favorite(user, activity.id) + {:ok, %Activity{}} = CommonAPI.favorite(activity.id, user) + assert {:ok, :already_liked} = CommonAPI.favorite(activity.id, user) end end @@ -1149,7 +1149,7 @@ defmodule Pleroma.Web.CommonAPITest do } ) - {:ok, favorite_activity} = CommonAPI.favorite(friend2, activity.id) + {:ok, favorite_activity} = CommonAPI.favorite(activity.id, friend2) {:ok, repeat_activity} = CommonAPI.repeat(activity.id, friend1) assert Repo.aggregate( @@ -1695,7 +1695,7 @@ defmodule Pleroma.Web.CommonAPITest do with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do assert {:ok, %Activity{data: %{"type" => "Like"}} = activity} = - CommonAPI.favorite(user, activity.id) + CommonAPI.favorite(activity.id, user) assert Visibility.local_public?(activity) refute called(Pleroma.Web.Federator.publish(activity)) @@ -1708,7 +1708,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe", visibility: "local"}) - {:ok, %Activity{}} = CommonAPI.favorite(user, activity.id) + {:ok, %Activity{}} = CommonAPI.favorite(activity.id, user) with_mock Pleroma.Web.Federator, publish: fn _ -> :ok end do assert {:ok, activity} = CommonAPI.unfavorite(activity.id, user) @@ -2002,7 +2002,7 @@ defmodule Pleroma.Web.CommonAPITest do CommonAPI.post(remote_user, %{status: "I like turtles!"}) {:ok, %{data: %{"id" => ap_id}} = _favorite} = - CommonAPI.favorite(local_user, activity.id) + CommonAPI.favorite(activity.id, local_user) # Generate the publish_one jobs ObanHelpers.perform_all() diff --git a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs index 350b935d7..c3a2a4e25 100644 --- a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs @@ -326,10 +326,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do {:ok, private_activity} = CommonAPI.post(other_user, %{status: ".", visibility: "private"}) - {:ok, _} = CommonAPI.favorite(user, public_activity.id) - {:ok, _} = CommonAPI.favorite(user, direct_activity.id) - {:ok, _} = CommonAPI.favorite(user, unlisted_activity.id) - {:ok, _} = CommonAPI.favorite(user, private_activity.id) + {:ok, _} = CommonAPI.favorite(public_activity.id, user) + {:ok, _} = CommonAPI.favorite(direct_activity.id, user) + {:ok, _} = CommonAPI.favorite(unlisted_activity.id, user) + {:ok, _} = CommonAPI.favorite(private_activity.id, user) activity_ids = conn @@ -414,7 +414,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do in_reply_to_status_id: activity.id }) - {:ok, _favorite} = CommonAPI.favorite(user, reply.id) + {:ok, _favorite} = CommonAPI.favorite(reply.id, user) activity_ids = conn @@ -432,7 +432,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) - {:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id) + {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, other_user) {:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user) {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) @@ -470,7 +470,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) - {:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id) + {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, other_user) {:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user) {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) @@ -517,7 +517,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do {:ok, _activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) - {:ok, _activity} = CommonAPI.favorite(other_user, create_activity.id) + {:ok, _activity} = CommonAPI.favorite(create_activity.id, other_user) {:ok, _activity} = CommonAPI.repeat(create_activity.id, other_user) {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs index f34911e5b..eb43f964a 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -1356,7 +1356,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do user1 = insert(:user) user2 = insert(:user) user3 = insert(:user) - {:ok, _} = CommonAPI.favorite(user2, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, user2) {:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id) {:ok, reblog_activity1} = CommonAPI.repeat(activity.id, user1) {:ok, _} = CommonAPI.repeat(activity.id, user2) @@ -1483,7 +1483,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do test "unfavorites a status and returns it", %{user: user, conn: conn} do activity = insert(:note_activity) - {:ok, _} = CommonAPI.favorite(user, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, user) conn = conn @@ -1859,7 +1859,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do test "returns users who have favorited the status", %{conn: conn, activity: activity} do other_user = insert(:user) - {:ok, _} = CommonAPI.favorite(other_user, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, other_user) response = conn @@ -1890,7 +1890,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do other_user = insert(:user) {:ok, _user_relationship} = User.block(user, other_user) - {:ok, _} = CommonAPI.favorite(other_user, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, other_user) response = conn @@ -1902,7 +1902,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do test "does not fail on an unauthenticated request", %{activity: activity} do other_user = insert(:user) - {:ok, _} = CommonAPI.favorite(other_user, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, other_user) response = build_conn() @@ -1922,7 +1922,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do visibility: "direct" }) - {:ok, _} = CommonAPI.favorite(other_user, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, other_user) favourited_by_url = "/api/v1/statuses/#{activity.id}/favourited_by" @@ -1953,7 +1953,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do clear_config([:instance, :show_reactions], false) other_user = insert(:user) - {:ok, _} = CommonAPI.favorite(other_user, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, other_user) response = conn @@ -2096,9 +2096,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do {:ok, second_post} = CommonAPI.post(other_user, %{status: "bla"}) {:ok, third_post} = CommonAPI.post(other_user, %{status: "bla"}) - {:ok, _first_favorite} = CommonAPI.favorite(user, third_post.id) - {:ok, _second_favorite} = CommonAPI.favorite(user, first_post.id) - {:ok, third_favorite} = CommonAPI.favorite(user, second_post.id) + {:ok, _first_favorite} = CommonAPI.favorite(third_post.id, user) + {:ok, _second_favorite} = CommonAPI.favorite(first_post.id, user) + {:ok, third_favorite} = CommonAPI.favorite(second_post.id, user) result = conn @@ -2134,7 +2134,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do {:ok, _} = CommonAPI.post(other_user, %{status: "bla"}) {:ok, activity} = CommonAPI.post(other_user, %{status: "trees are happy"}) - {:ok, last_like} = CommonAPI.favorite(user, activity.id) + {:ok, last_like} = CommonAPI.favorite(activity.id, user) first_conn = get(conn, "/api/v1/favourites") @@ -2150,7 +2150,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do status: "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful." }) - {:ok, _} = CommonAPI.favorite(user, second_activity.id) + {:ok, _} = CommonAPI.favorite(second_activity.id, user) second_conn = get(conn, "/api/v1/favourites?since_id=#{last_like.id}") diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs index 9896f81b6..003ac8c36 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -93,7 +93,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do user = insert(:user) another_user = insert(:user) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) - {:ok, favorite_activity} = CommonAPI.favorite(another_user, create_activity.id) + {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, another_user) {:ok, [notification]} = Notification.create_notifications(favorite_activity) create_activity = Activity.get_by_id(create_activity.id) @@ -316,7 +316,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do {:ok, _} = Pleroma.UserRelationship.create_mute(user, another_user) {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) - {:ok, favorite_activity} = CommonAPI.favorite(another_user, create_activity.id) + {:ok, favorite_activity} = CommonAPI.favorite(create_activity.id, another_user) {:ok, [notification]} = Notification.create_notifications(favorite_activity) create_activity = Activity.get_by_id(create_activity.id) diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs index 3e8fcd956..5387ec94e 100644 --- a/test/pleroma/web/o_status/o_status_controller_test.exs +++ b/test/pleroma/web/o_status/o_status_controller_test.exs @@ -186,7 +186,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do user = insert(:user) - {:ok, like_activity} = CommonAPI.favorite(user, note_activity.id) + {:ok, like_activity} = CommonAPI.favorite(note_activity.id, user) assert like_activity.data["type"] == "Like" diff --git a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs index 8f000760f..5af5a6138 100644 --- a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs @@ -78,7 +78,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do user: user } do [activity | _] = insert_pair(:note_activity) - CommonAPI.favorite(user, activity.id) + CommonAPI.favorite(activity.id, user) response = conn @@ -95,7 +95,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do user: user } do activity = insert(:note_activity) - CommonAPI.favorite(user, activity.id) + CommonAPI.favorite(activity.id, user) response = build_conn() @@ -115,7 +115,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do visibility: "direct" }) - CommonAPI.favorite(user, direct.id) + CommonAPI.favorite(direct.id, user) for u <- [user, current_user] do response = @@ -148,7 +148,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do visibility: "direct" }) - CommonAPI.favorite(user, direct.id) + CommonAPI.favorite(direct.id, user) response = conn @@ -165,7 +165,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do activities = insert_list(10, :note_activity) Enum.each(activities, fn activity -> - CommonAPI.favorite(user, activity.id) + CommonAPI.favorite(activity.id, user) end) third_activity = Enum.at(activities, 2) @@ -190,7 +190,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do 7 |> insert_list(:note_activity) |> Enum.each(fn activity -> - CommonAPI.favorite(user, activity.id) + CommonAPI.favorite(activity.id, user) end) response = @@ -222,7 +222,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do test "returns 403 error when user has hidden own favorites", %{conn: conn} do user = insert(:user, hide_favorites: true) activity = insert(:note_activity) - CommonAPI.favorite(user, activity.id) + CommonAPI.favorite(activity.id, user) conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/favourites") @@ -232,7 +232,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do test "hides favorites for new users by default", %{conn: conn} do user = insert(:user) activity = insert(:note_activity) - CommonAPI.favorite(user, activity.id) + CommonAPI.favorite(activity.id, user) assert user.hide_favorites conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/favourites") diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index adaae93d0..5e2b20ab5 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -192,7 +192,7 @@ defmodule Pleroma.Web.Push.ImplTest do "Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis." }) - {:ok, activity} = CommonAPI.favorite(user, activity.id) + {:ok, activity} = CommonAPI.favorite(activity.id, user) object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "favourite"}, user, object) == @@ -351,7 +351,7 @@ defmodule Pleroma.Web.Push.ImplTest do body: "New Mention" } - {:ok, activity} = CommonAPI.favorite(user, activity.id) + {:ok, activity} = CommonAPI.favorite(activity.id, user) notif = insert(:notification, user: user2, activity: activity, type: "favourite") @@ -408,7 +408,7 @@ defmodule Pleroma.Web.Push.ImplTest do title: "New Mention" } - {:ok, activity} = CommonAPI.favorite(user, activity.id) + {:ok, activity} = CommonAPI.favorite(activity.id, user) notif = insert(:notification, user: user2, activity: activity, type: "favourite") diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index d85358fd4..978e8a823 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -418,7 +418,7 @@ defmodule Pleroma.Web.StreamerTest do Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) {:ok, activity} = CommonAPI.post(user, %{status: ":("}) - {:ok, _} = CommonAPI.favorite(blocked, activity.id) + {:ok, _} = CommonAPI.favorite(activity.id, blocked) refute_receive _ end @@ -434,7 +434,7 @@ defmodule Pleroma.Web.StreamerTest do Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) - {:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id) + {:ok, favorite_activity} = CommonAPI.favorite(activity.id, user2) refute_receive _ assert Streamer.filtered_by_user?(user, favorite_activity) @@ -448,7 +448,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"}) Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) - {:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id) + {:ok, favorite_activity} = CommonAPI.favorite(activity.id, user2) assert_receive {:render_with_user, _, "notification.json", notif, _} assert notif.activity.id == favorite_activity.id @@ -464,7 +464,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, user} = User.block_domain(user, "hecking-lewd-place.com") {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"}) Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) - {:ok, favorite_activity} = CommonAPI.favorite(user2, activity.id) + {:ok, favorite_activity} = CommonAPI.favorite(activity.id, user2) refute_receive _ assert Streamer.filtered_by_user?(user, favorite_activity) @@ -863,7 +863,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"}) Streamer.get_topic_and_add_socket("user", user1, user1_token) - {:ok, _favorite_activity} = CommonAPI.favorite(user2, create_activity.id) + {:ok, _favorite_activity} = CommonAPI.favorite(create_activity.id, user2) assert_receive {:render_with_user, _, "notification.json", notif, _} refute Streamer.filtered_by_user?(user1, notif) From f602813d314533a50ab7cadf64f1f0fbbb863cc6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 17:49:30 -0400 Subject: [PATCH 04/15] Fix order of args for update/2 --- lib/pleroma/web/common_api.ex | 4 ++-- .../mastodon_api/controllers/status_controller.ex | 2 +- test/pleroma/integration/mastodon_websocket_test.exs | 2 +- test/pleroma/notification_test.exs | 4 ++-- .../article_note_page_validator_test.exs | 2 +- .../object_validators/update_handling_test.exs | 2 +- .../pleroma/web/activity_pub/transmogrifier_test.exs | 2 +- test/pleroma/web/common_api_test.exs | 12 ++++++------ .../mastodon_api/views/notification_view_test.exs | 2 +- .../web/mastodon_api/views/status_view_test.exs | 2 +- test/pleroma/web/metadata/utils_test.exs | 2 +- test/pleroma/web/push/impl_test.exs | 2 +- test/pleroma/web/rich_media/card_test.exs | 2 +- test/pleroma/web/streamer_test.exs | 10 +++++----- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index f8a03680a..cfb36bc1c 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -461,8 +461,8 @@ defmodule Pleroma.Web.CommonAPI do end end - @spec update(User.t(), Activity.t(), map()) :: {:ok, Activity.t()} | {:error, any()} - def update(user, orig_activity, changes) do + @spec update(Activity.t(), User.t(), map()) :: {:ok, Activity.t()} | {:error, any()} + def update(orig_activity, %User{} = user, changes) do with orig_object <- Object.normalize(orig_activity), {:ok, new_object} <- make_update_data(user, orig_object, changes), {:ok, update_data, _} <- Builder.update(user, new_object), diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 80386dc45..f75efd00d 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -276,7 +276,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do actor <- Activity.user_actor(activity), {_, true} <- {:own_status, actor.id == user.id}, changes <- body_params |> put_application(conn), - {_, {:ok, _update_activity}} <- {:pipeline, CommonAPI.update(user, activity, changes)}, + {_, {:ok, _update_activity}} <- {:pipeline, CommonAPI.update(activity, user, changes)}, {_, %Activity{}} = {_, activity} <- {:refetched, Activity.get_by_id_with_object(id)} do try_render(conn, "show.json", activity: activity, diff --git a/test/pleroma/integration/mastodon_websocket_test.exs b/test/pleroma/integration/mastodon_websocket_test.exs index a0ffddf8d..49edeb91e 100644 --- a/test/pleroma/integration/mastodon_websocket_test.exs +++ b/test/pleroma/integration/mastodon_websocket_test.exs @@ -440,7 +440,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do assert_receive {:text, _raw_json}, 1_000 - {:ok, _} = CommonAPI.update(user, activity, %{status: "mew mew", visibility: "private"}) + {:ok, _} = CommonAPI.update(activity, user, %{status: "mew mew", visibility: "private"}) assert_receive {:text, raw_json}, 1_000 diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index e9923cb56..c7ed18bba 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -165,7 +165,7 @@ defmodule Pleroma.NotificationTest do {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user) {:ok, _edit_activity} = - CommonAPI.update(user, activity_one, %{ + CommonAPI.update(activity_one, user, %{ status: "hey @#{other_user.nickname}! mew mew" }) @@ -748,7 +748,7 @@ defmodule Pleroma.NotificationTest do {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user) {:ok, edit_activity} = - CommonAPI.update(user, activity_one, %{ + CommonAPI.update(activity_one, user, %{ status: "hey @#{other_user.nickname}! mew mew" }) diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs index 2b33950d6..e1dbb20c3 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs @@ -43,7 +43,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidatorTest setup do user = insert(:user) {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"}) - {:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"}) + {:ok, edit} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "edited :blank:"}) {:ok, %{"object" => external_rep}} = Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data) diff --git a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs index a09dbf5c6..c88339d14 100644 --- a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs @@ -132,7 +132,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateHandlingTest do setup do user = insert(:user) {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"}) - {:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"}) + {:ok, edit} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "edited :blank:"}) {:ok, external_rep} = Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data) %{external_rep: external_rep} end diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index 2fb0cd079..6da7e4a89 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -353,7 +353,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"}) - {:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew :blank:"}) + {:ok, update} = CommonAPI.update(activity, user, %{status: "mew mew :blank:"}) {:ok, prepared} = Transmogrifier.prepare_outgoing(update.data) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 4f3bc6921..433278d39 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1753,7 +1753,7 @@ defmodule Pleroma.Web.CommonAPITest do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1"}) - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "updated 2" @@ -1767,7 +1767,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1", visibility: "private"}) - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "updated 2" @@ -1784,7 +1784,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1 :#{emoji1}:"}) - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2 :#{emoji2}:"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "updated 2 :#{emoji2}:" @@ -1803,7 +1803,7 @@ defmodule Pleroma.Web.CommonAPITest do with_mock Pleroma.Web.Federator, publish: fn _p -> nil end do - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2 :#{emoji2}:"}) assert updated.data["object"]["content"] == "updated 2 :#{emoji2}:" assert %{^emoji2 => _} = updated.data["object"]["emoji"] @@ -1847,7 +1847,7 @@ defmodule Pleroma.Web.CommonAPITest do assert reply.object.data["emoji"]["remoteemoji"] == remote_emoji_uri {:ok, edit} = - CommonAPI.update(user, reply, %{status: "reply mew mew", spoiler_text: ":remoteemoji:"}) + CommonAPI.update(reply, user, %{status: "reply mew mew", spoiler_text: ":remoteemoji:"}) edited_note = Pleroma.Object.normalize(edit) @@ -1863,7 +1863,7 @@ defmodule Pleroma.Web.CommonAPITest do {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "updated 1"}) assert Object.normalize(activity).data["summary"] == "mewmew 1" - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "mewmew 2" diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs index 003ac8c36..3ad5e1606 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -290,7 +290,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do {:ok, activity} = CommonAPI.post(user, %{status: "mew"}) {:ok, _} = CommonAPI.repeat(activity.id, repeat_user) - {:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew"}) + {:ok, update} = CommonAPI.update(activity, user, %{status: "mew mew"}) user = Pleroma.User.get_by_ap_id(user.ap_id) activity = Pleroma.Activity.normalize(activity) diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index f42d9d1c6..cfcb8cfb2 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -938,7 +938,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do status = StatusView.render("show.json", activity: post) refute status.edited_at - {:ok, _} = CommonAPI.update(poster, post, %{status: "mew mew"}) + {:ok, _} = CommonAPI.update(post, poster, %{status: "mew mew"}) edited = Pleroma.Activity.normalize(post) status = StatusView.render("show.json", activity: edited) diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs index 9bc02dadf..f986d3fd5 100644 --- a/test/pleroma/web/metadata/utils_test.exs +++ b/test/pleroma/web/metadata/utils_test.exs @@ -81,7 +81,7 @@ defmodule Pleroma.Web.Metadata.UtilsTest do object = Pleroma.Object.normalize(activity) assert Utils.scrub_html_and_truncate(object) == "mew mew #def" - {:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"}) + {:ok, update} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "mew mew #abc"}) update = Pleroma.Activity.normalize(update) object = Pleroma.Object.normalize(update) assert Utils.scrub_html_and_truncate(object) == "mew mew #abc" diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index 5e2b20ab5..dcd909f1c 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -225,7 +225,7 @@ defmodule Pleroma.Web.Push.ImplTest do {:ok, activity} = CommonAPI.post(user, %{status: "lorem ipsum"}) - {:ok, activity} = CommonAPI.update(user, activity, %{status: "edited status"}) + {:ok, activity} = CommonAPI.update(activity, user, %{status: "edited status"}) object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "update"}, user, object) == diff --git a/test/pleroma/web/rich_media/card_test.exs b/test/pleroma/web/rich_media/card_test.exs index 9541627c1..387defc8c 100644 --- a/test/pleroma/web/rich_media/card_test.exs +++ b/test/pleroma/web/rich_media/card_test.exs @@ -70,7 +70,7 @@ defmodule Pleroma.Web.RichMedia.CardTest do Card.get_by_activity(activity) ) - {:ok, _} = CommonAPI.update(user, activity, %{status: "I like this site #{updated_url}"}) + {:ok, _} = CommonAPI.update(activity, user, %{status: "I like this site #{updated_url}"}) activity = Pleroma.Activity.get_by_id(activity.id) diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index 978e8a823..e53c6adc4 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -541,7 +541,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) Streamer.get_topic_and_add_socket("user", user, oauth_token) - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"}) create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"]) assert_receive {:render_with_user, _, "status_update.json", ^create, _} @@ -552,7 +552,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, activity} = CommonAPI.post(user, %{status: "hey"}) Streamer.get_topic_and_add_socket("user", user, oauth_token) - {:ok, edited} = CommonAPI.update(user, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, user, %{status: "mew mew"}) create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"]) assert_receive {:render_with_user, _, "status_update.json", ^create, _} @@ -608,7 +608,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) assert_receive {:text, _} - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"}) edited = Pleroma.Activity.normalize(edited) @@ -627,7 +627,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) assert_receive {:text, _} - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"}) edited = Pleroma.Activity.normalize(edited) @@ -638,7 +638,7 @@ defmodule Pleroma.Web.StreamerTest do assert %{"id" => ^activity_id} = Jason.decode!(payload) refute Streamer.filtered_by_user?(sender, edited) - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew 2"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew 2"}) edited = Pleroma.Activity.normalize(edited) From d27ad36ce4b2f00d89ca96bd4d7c6f688ec67262 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 17:59:33 -0400 Subject: [PATCH 05/15] Fix order of args for remove_mute/2 --- lib/pleroma/web/common_api.ex | 9 +++++---- .../web/mastodon_api/controllers/status_controller.ex | 2 +- lib/pleroma/workers/mute_expire_worker.ex | 2 +- test/pleroma/web/common_api_test.exs | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index cfb36bc1c..751260a46 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -572,16 +572,17 @@ defmodule Pleroma.Web.CommonAPI do end end - @spec remove_mute(User.t(), Activity.t()) :: {:ok, Activity.t()} | {:error, any()} - def remove_mute(%User{} = user, %Activity{} = activity) do + @spec remove_mute(Activity.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()} + def remove_mute(%Activity{} = activity, %User{} = user) do ThreadMute.remove_mute(user.id, activity.data["context"]) {:ok, activity} end - def remove_mute(user_id, activity_id) do + @spec remove_mute(String.t(), String.t()) :: {:ok, Activity.t()} | {:error, any()} + def remove_mute(activity_id, user_id) do with {:user, %User{} = user} <- {:user, User.get_by_id(user_id)}, {:activity, %Activity{} = activity} <- {:activity, Activity.get_by_id(activity_id)} do - remove_mute(user, activity) + remove_mute(activity, user) else {what, result} = error -> Logger.warning( diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index f75efd00d..ab5a104dd 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -467,7 +467,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do _ ) do with %Activity{} = activity <- Activity.get_by_id(id), - {:ok, activity} <- CommonAPI.remove_mute(user, activity) do + {:ok, activity} <- CommonAPI.remove_mute(activity, user) do try_render(conn, "show.json", activity: activity, for: user, as: :activity) end end diff --git a/lib/pleroma/workers/mute_expire_worker.ex b/lib/pleroma/workers/mute_expire_worker.ex index 8ad287a7f..a7ab5883a 100644 --- a/lib/pleroma/workers/mute_expire_worker.ex +++ b/lib/pleroma/workers/mute_expire_worker.ex @@ -14,7 +14,7 @@ defmodule Pleroma.Workers.MuteExpireWorker do def perform(%Job{ args: %{"op" => "unmute_conversation", "user_id" => user_id, "activity_id" => activity_id} }) do - Pleroma.Web.CommonAPI.remove_mute(user_id, activity_id) + Pleroma.Web.CommonAPI.remove_mute(activity_id, user_id) :ok end diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 433278d39..0ad296e42 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1219,13 +1219,13 @@ defmodule Pleroma.Web.CommonAPITest do test "remove mute", %{user: user, activity: activity} do CommonAPI.add_mute(user, activity) - {:ok, _} = CommonAPI.remove_mute(user, activity) + {:ok, _} = CommonAPI.remove_mute(activity, user) refute CommonAPI.thread_muted?(user, activity) end test "remove mute by ids", %{user: user, activity: activity} do CommonAPI.add_mute(user, activity) - {:ok, _} = CommonAPI.remove_mute(user.id, activity.id) + {:ok, _} = CommonAPI.remove_mute(activity.id, user.id) refute CommonAPI.thread_muted?(user, activity) end From 4601473aaf65cfc5696e17069014a92750f1560d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 18:18:30 -0400 Subject: [PATCH 06/15] Fix order of args for add_mute/2 --- lib/pleroma/web/common_api.ex | 4 ++-- .../mastodon_api/controllers/status_controller.ex | 2 +- test/pleroma/notification_test.exs | 2 +- .../pleroma/web/activity_pub/activity_pub_test.exs | 4 ++-- test/pleroma/web/common_api_test.exs | 14 +++++++------- .../controllers/status_controller_test.exs | 4 ++-- .../web/mastodon_api/views/status_view_test.exs | 2 +- test/pleroma/web/streamer_test.exs | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 751260a46..b5ba081b8 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -552,8 +552,8 @@ defmodule Pleroma.Web.CommonAPI do end end - @spec add_mute(User.t(), Activity.t(), map()) :: {:ok, Activity.t()} | {:error, any()} - def add_mute(user, activity, params \\ %{}) do + @spec add_mute(Activity.t(), User.t(), map()) :: {:ok, Activity.t()} | {:error, any()} + def add_mute(activity, user, params \\ %{}) do expires_in = Map.get(params, :expires_in, 0) with {:ok, _} <- ThreadMute.add_mute(user.id, activity.data["context"]), diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index ab5a104dd..b9b236920 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -453,7 +453,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do _ ) do with %Activity{} = activity <- Activity.get_by_id(id), - {:ok, activity} <- CommonAPI.add_mute(user, activity, params) do + {:ok, activity} <- CommonAPI.add_mute(activity, user, params) do try_render(conn, "show.json", activity: activity, for: user, as: :activity) end end diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index c7ed18bba..8b3d01270 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -693,7 +693,7 @@ defmodule Pleroma.NotificationTest do {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"}) - {:ok, _} = CommonAPI.add_mute(other_user, activity) + {:ok, _} = CommonAPI.add_mute(activity, other_user) {:ok, same_context_activity} = CommonAPI.post(user, %{ diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index 2fc1f3520..e6fcf9fcc 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -1171,7 +1171,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do note_two = insert(:note, data: %{"context" => "suya.."}) activity_two = insert(:note_activity, note: note_two) - {:ok, _activity_two} = CommonAPI.add_mute(user, activity_two) + {:ok, _activity_two} = CommonAPI.add_mute(activity_two, user) assert [_activity_one] = ActivityPub.fetch_activities([], %{muting_user: user}) end @@ -1182,7 +1182,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do note_two = insert(:note, data: %{"context" => "suya.."}) activity_two = insert(:note_activity, note: note_two) - {:ok, _activity_two} = CommonAPI.add_mute(user, activity_two) + {:ok, _activity_two} = CommonAPI.add_mute(activity_two, user) assert [_activity_two, _activity_one] = ActivityPub.fetch_activities([], %{muting_user: user, with_muted: true}) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 0ad296e42..7c92084bc 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1172,7 +1172,7 @@ defmodule Pleroma.Web.CommonAPITest do n.type == "mention" && n.activity_id == reply_activity.id end) - {:ok, _} = CommonAPI.add_mute(author, activity) + {:ok, _} = CommonAPI.add_mute(activity, author) assert CommonAPI.thread_muted?(author, activity) assert Repo.aggregate( @@ -1197,12 +1197,12 @@ defmodule Pleroma.Web.CommonAPITest do end test "add mute", %{user: user, activity: activity} do - {:ok, _} = CommonAPI.add_mute(user, activity) + {:ok, _} = CommonAPI.add_mute(activity, user) assert CommonAPI.thread_muted?(user, activity) end test "add expiring mute", %{user: user, activity: activity} do - {:ok, _} = CommonAPI.add_mute(user, activity, %{expires_in: 60}) + {:ok, _} = CommonAPI.add_mute(activity, user, %{expires_in: 60}) assert CommonAPI.thread_muted?(user, activity) worker = Pleroma.Workers.MuteExpireWorker @@ -1218,20 +1218,20 @@ defmodule Pleroma.Web.CommonAPITest do end test "remove mute", %{user: user, activity: activity} do - CommonAPI.add_mute(user, activity) + CommonAPI.add_mute(activity, user) {:ok, _} = CommonAPI.remove_mute(activity, user) refute CommonAPI.thread_muted?(user, activity) end test "remove mute by ids", %{user: user, activity: activity} do - CommonAPI.add_mute(user, activity) + CommonAPI.add_mute(activity, user) {:ok, _} = CommonAPI.remove_mute(activity.id, user.id) refute CommonAPI.thread_muted?(user, activity) end test "check that mutes can't be duplicate", %{user: user, activity: activity} do - CommonAPI.add_mute(user, activity) - {:error, _} = CommonAPI.add_mute(user, activity) + CommonAPI.add_mute(activity, user) + {:error, _} = CommonAPI.add_mute(activity, user) end end diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs index eb43f964a..904bf1471 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -1771,7 +1771,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do end test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do - {:ok, _} = CommonAPI.add_mute(user, activity) + {:ok, _} = CommonAPI.add_mute(activity, user) conn = conn @@ -1784,7 +1784,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do end test "unmute conversation", %{conn: conn, user: user, activity: activity} do - {:ok, _} = CommonAPI.add_mute(user, activity) + {:ok, _} = CommonAPI.add_mute(activity, user) id_str = to_string(activity.id) diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index cfcb8cfb2..88a3940c3 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -388,7 +388,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do assert status.pleroma.thread_muted == false - {:ok, activity} = CommonAPI.add_mute(user, activity) + {:ok, activity} = CommonAPI.add_mute(activity, user) status = StatusView.render("show.json", %{activity: activity, for: user}) diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index e53c6adc4..edeec187c 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -430,7 +430,7 @@ defmodule Pleroma.Web.StreamerTest do user2 = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"}) - {:ok, _} = CommonAPI.add_mute(user, activity) + {:ok, _} = CommonAPI.add_mute(activity, user) Streamer.get_topic_and_add_socket("user:notification", user, oauth_token) @@ -878,7 +878,7 @@ defmodule Pleroma.Web.StreamerTest do {:ok, user2, user, _activity} = CommonAPI.follow(user2, user) {:ok, activity} = CommonAPI.post(user, %{status: "super hot take"}) - {:ok, _} = CommonAPI.add_mute(user2, activity) + {:ok, _} = CommonAPI.add_mute(activity, user2) assert_receive {:render_with_user, _, _, ^activity, _} assert Streamer.filtered_by_user?(user2, activity) From 8127e0d8cce9fa8fb62f6699fdee1bed466a6fb6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 18:23:13 -0400 Subject: [PATCH 07/15] Fix order of args for thread_muted?/2 --- lib/pleroma/notification.ex | 2 +- lib/pleroma/web/common_api.ex | 4 ++-- lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- lib/pleroma/web/streamer.ex | 2 +- test/pleroma/user_test.exs | 2 +- test/pleroma/web/common_api_test.exs | 12 ++++++------ 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index de2508b93..75f4ba503 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -734,7 +734,7 @@ defmodule Pleroma.Notification do def mark_as_read?(activity, target_user) do user = Activity.user_actor(activity) - User.mutes_user?(target_user, user) || CommonAPI.thread_muted?(target_user, activity) + User.mutes_user?(target_user, user) || CommonAPI.thread_muted?(activity, target_user) end def for_user_and_activity(user, activity) do diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index b5ba081b8..f26cd8c1e 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -593,8 +593,8 @@ defmodule Pleroma.Web.CommonAPI do end end - @spec thread_muted?(User.t(), Activity.t()) :: boolean() - def thread_muted?(%User{id: user_id}, %{data: %{"context" => context}}) + @spec thread_muted?(Activity.t(), User.t()) :: boolean() + def thread_muted?(%{data: %{"context" => context}}, %User{id: user_id}) when is_binary(context) do ThreadMute.exists?(user_id, context) end diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index d9d7e516a..747638c53 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -293,7 +293,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do cond do is_nil(opts[:for]) -> false is_boolean(activity.thread_muted?) -> activity.thread_muted? - true -> CommonAPI.thread_muted?(opts[:for], activity) + true -> CommonAPI.thread_muted?(activity, opts[:for]) end attachment_data = object.data["attachment"] || [] diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 9abdfae30..76dc0f42d 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -206,7 +206,7 @@ defmodule Pleroma.Web.Streamer do false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, item_host), false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, parent_host), true <- thread_containment(item, user), - false <- CommonAPI.thread_muted?(user, parent) do + false <- CommonAPI.thread_muted?(parent, user) do false else _ -> true diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 2dc1b839d..f2a315508 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -1526,7 +1526,7 @@ defmodule Pleroma.UserTest do assert [activity] == ActivityPub.fetch_public_activities(%{}) |> Repo.preload(:bookmark) - assert [%{activity | thread_muted?: CommonAPI.thread_muted?(user2, activity)}] == + assert [%{activity | thread_muted?: CommonAPI.thread_muted?(activity, user2)}] == ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{ user: user2 }) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 7c92084bc..cc4482efe 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1173,7 +1173,7 @@ defmodule Pleroma.Web.CommonAPITest do end) {:ok, _} = CommonAPI.add_mute(activity, author) - assert CommonAPI.thread_muted?(author, activity) + assert CommonAPI.thread_muted?(activity, author) assert Repo.aggregate( from(n in Notification, where: n.seen == false and n.user_id == ^friend1.id), @@ -1198,12 +1198,12 @@ defmodule Pleroma.Web.CommonAPITest do test "add mute", %{user: user, activity: activity} do {:ok, _} = CommonAPI.add_mute(activity, user) - assert CommonAPI.thread_muted?(user, activity) + assert CommonAPI.thread_muted?(activity, user) end test "add expiring mute", %{user: user, activity: activity} do {:ok, _} = CommonAPI.add_mute(activity, user, %{expires_in: 60}) - assert CommonAPI.thread_muted?(user, activity) + assert CommonAPI.thread_muted?(activity, user) worker = Pleroma.Workers.MuteExpireWorker args = %{"op" => "unmute_conversation", "user_id" => user.id, "activity_id" => activity.id} @@ -1214,19 +1214,19 @@ defmodule Pleroma.Web.CommonAPITest do ) assert :ok = perform_job(worker, args) - refute CommonAPI.thread_muted?(user, activity) + refute CommonAPI.thread_muted?(activity, user) end test "remove mute", %{user: user, activity: activity} do CommonAPI.add_mute(activity, user) {:ok, _} = CommonAPI.remove_mute(activity, user) - refute CommonAPI.thread_muted?(user, activity) + refute CommonAPI.thread_muted?(activity, user) end test "remove mute by ids", %{user: user, activity: activity} do CommonAPI.add_mute(activity, user) {:ok, _} = CommonAPI.remove_mute(activity.id, user.id) - refute CommonAPI.thread_muted?(user, activity) + refute CommonAPI.thread_muted?(activity, user) end test "check that mutes can't be duplicate", %{user: user, activity: activity} do From 1cccc0fc2193b7ba0a87bf0902abce429748153e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 18:38:02 -0400 Subject: [PATCH 08/15] Fix order of args for vote/3 --- lib/pleroma/web/common_api.ex | 4 ++-- lib/pleroma/web/mastodon_api/controllers/poll_controller.ex | 6 +++--- test/pleroma/notification_test.exs | 4 ++-- .../web/activity_pub/activity_pub_controller_test.exs | 2 +- test/pleroma/web/activity_pub/utils_test.exs | 4 ++-- test/pleroma/web/common_api_test.exs | 4 ++-- test/pleroma/web/mastodon_api/views/poll_view_test.exs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index f26cd8c1e..2eb2bcc82 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -329,8 +329,8 @@ defmodule Pleroma.Web.CommonAPI do end end - @spec vote(User.t(), Object.t(), list()) :: {:ok, list(), Object.t()} | {:error, any()} - def vote(user, %{data: %{"type" => "Question"}} = object, choices) do + @spec vote(Object.t(), User.t(), list()) :: {:ok, list(), Object.t()} | {:error, any()} + def vote(%Object{data: %{"type" => "Question"}} = object, %User{} = user, choices) do with :ok <- validate_not_author(object, user), :ok <- validate_existing_votes(user, object), {:ok, options, choices} <- normalize_and_validate_choices(choices, object) do diff --git a/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex b/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex index b074ee405..a2af8148c 100644 --- a/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex @@ -51,7 +51,7 @@ defmodule Pleroma.Web.MastodonAPI.PollController do with %Object{data: %{"type" => "Question"}} = object <- Object.get_by_id(id), %Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]), true <- Visibility.visible_for_user?(activity, user), - {:ok, _activities, object} <- get_cached_vote_or_vote(user, object, choices) do + {:ok, _activities, object} <- get_cached_vote_or_vote(object, user, choices) do try_render(conn, "show.json", %{object: object, for: user}) else nil -> render_error(conn, :not_found, "Record not found") @@ -60,11 +60,11 @@ defmodule Pleroma.Web.MastodonAPI.PollController do end end - defp get_cached_vote_or_vote(user, object, choices) do + defp get_cached_vote_or_vote(object, user, choices) do idempotency_key = "polls:#{user.id}:#{object.data["id"]}" @cachex.fetch!(:idempotency_cache, idempotency_key, fn _ -> - case CommonAPI.vote(user, object, choices) do + case CommonAPI.vote(object, user, choices) do {:error, _message} = res -> {:ignore, res} res -> {:commit, res} end diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 8b3d01270..d476ad3f7 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -180,8 +180,8 @@ defmodule Pleroma.NotificationTest do question = insert(:question, user: user1) activity = insert(:question_activity, question: question) - {:ok, _, _} = CommonAPI.vote(user2, question, [0]) - {:ok, _, _} = CommonAPI.vote(user3, question, [1]) + {:ok, _, _} = CommonAPI.vote(question, user2, [0]) + {:ok, _, _} = CommonAPI.vote(question, user3, [1]) {:ok, notifications} = Notification.create_poll_notifications(activity) diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs index cc67b72d2..8adde8730 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -1402,7 +1402,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do assert question = Object.normalize(activity, fetch: false) - {:ok, [activity], _object} = CommonAPI.vote(voter, question, [1]) + {:ok, [activity], _object} = CommonAPI.vote(question, voter, [1]) assert outbox_get = conn diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index 47eea9a25..833c7fbf3 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -201,7 +201,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do }) object = Object.normalize(activity, fetch: false) - {:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1]) + {:ok, votes, object} = CommonAPI.vote(object, other_user, [0, 1]) assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes) end @@ -219,7 +219,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do }) object = Object.normalize(activity, fetch: false) - {:ok, [vote], object} = CommonAPI.vote(other_user, object, [0]) + {:ok, [vote], object} = CommonAPI.vote(object, other_user, [0]) {:ok, _activity} = CommonAPI.favorite(activity.id, user) [fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object) assert fetched_vote.id == vote.id diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index cc4482efe..381a8f37b 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1559,9 +1559,9 @@ defmodule Pleroma.Web.CommonAPITest do object = Object.normalize(activity, fetch: false) - {:ok, _, object} = CommonAPI.vote(other_user, object, [0]) + {:ok, _, object} = CommonAPI.vote(object, other_user, [0]) - assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1]) + assert {:error, "Already voted"} == CommonAPI.vote(object, other_user, [1]) end end diff --git a/test/pleroma/web/mastodon_api/views/poll_view_test.exs b/test/pleroma/web/mastodon_api/views/poll_view_test.exs index 3aa73c224..6de001421 100644 --- a/test/pleroma/web/mastodon_api/views/poll_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/poll_view_test.exs @@ -74,7 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do object = Object.normalize(activity, fetch: false) - {:ok, _votes, object} = CommonAPI.vote(voter, object, [0, 1]) + {:ok, _votes, object} = CommonAPI.vote(object, voter, [0, 1]) assert match?( %{ @@ -119,7 +119,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do object = Object.normalize(activity, fetch: false) - {:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2]) + {:ok, _, object} = CommonAPI.vote(object, other_user, [1, 2]) result = PollView.render("show.json", %{object: object, for: other_user}) From cbc5e4841725a19761f5d869e2cc8f5152692791 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 18:39:20 -0400 Subject: [PATCH 09/15] Fix order of args for block/2 --- lib/pleroma/user/import.ex | 2 +- lib/pleroma/web/common_api.ex | 2 +- .../web/mastodon_api/controllers/account_controller.ex | 2 +- test/pleroma/web/activity_pub/side_effects_test.exs | 4 ++-- test/pleroma/web/activity_pub/utils_test.exs | 6 +++--- test/pleroma/web/common_api_test.exs | 6 +++--- .../controllers/notification_controller_test.exs | 2 +- .../mastodon_api/controllers/suggestion_controller_test.exs | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/pleroma/user/import.ex b/lib/pleroma/user/import.ex index 4baa7e3a4..f62f1203d 100644 --- a/lib/pleroma/user/import.ex +++ b/lib/pleroma/user/import.ex @@ -31,7 +31,7 @@ defmodule Pleroma.User.Import do identifiers, fn identifier -> with {:ok, %User{} = blocked} <- User.get_or_fetch(identifier), - {:ok, _block} <- CommonAPI.block(blocker, blocked) do + {:ok, _block} <- CommonAPI.block(blocked, blocker) do blocked else error -> handle_error(:blocks_import, identifier, error) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 2eb2bcc82..4109f8992 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -27,7 +27,7 @@ defmodule Pleroma.Web.CommonAPI do require Logger @spec block(User.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()} - def block(blocker, blocked) do + def block(blocked, blocker) do with {:ok, block_data, _} <- Builder.block(blocker, blocked), {:ok, block, _} <- Pipeline.common_pipeline(block_data, local: true) do {:ok, block} diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 47e6f0a64..57439c6d4 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -495,7 +495,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do @doc "POST /api/v1/accounts/:id/block" def block(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do - with {:ok, _activity} <- CommonAPI.block(blocker, blocked) do + with {:ok, _activity} <- CommonAPI.block(blocked, blocker) do render(conn, "relationship.json", user: blocker, target: blocked) else {:error, message} -> json_response(conn, :forbidden, %{error: message}) diff --git a/test/pleroma/web/activity_pub/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs index 8c115cedd..417e47487 100644 --- a/test/pleroma/web/activity_pub/side_effects_test.exs +++ b/test/pleroma/web/activity_pub/side_effects_test.exs @@ -519,7 +519,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do {:ok, like} = CommonAPI.favorite(post.id, user) {:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍") {:ok, announce} = CommonAPI.repeat(post.id, user) - {:ok, block} = CommonAPI.block(user, poster) + {:ok, block} = CommonAPI.block(poster, user) {:ok, undo_data, _meta} = Builder.undo(user, like) {:ok, like_undo, _meta} = ActivityPub.persist(undo_data, local: true) @@ -965,7 +965,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do group: group, poster: poster } do - {:ok, _} = CommonAPI.block(group, poster) + {:ok, _} = CommonAPI.block(poster, group) create_activity_data = make_create.([group]) {:ok, create_activity, _meta} = ActivityPub.persist(create_activity_data, local: false) diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index 833c7fbf3..b7d6b8ec7 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -382,9 +382,9 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do user1 = insert(:user) user2 = insert(:user) - assert {:ok, %Activity{} = _} = CommonAPI.block(user1, user2) - assert {:ok, %Activity{} = _} = CommonAPI.block(user1, user2) - assert {:ok, %Activity{} = activity} = CommonAPI.block(user1, user2) + assert {:ok, %Activity{} = _} = CommonAPI.block(user2, user1) + assert {:ok, %Activity{} = _} = CommonAPI.block(user2, user1) + assert {:ok, %Activity{} = activity} = CommonAPI.block(user2, user1) assert Utils.fetch_latest_block(user1, user2) == activity end diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 381a8f37b..06c912bd0 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -95,7 +95,7 @@ defmodule Pleroma.Web.CommonAPITest do assert User.get_follow_state(blocker, blocked) == :follow_accept refute is_nil(Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(blocker, blocked)) - assert {:ok, block} = CommonAPI.block(blocker, blocked) + assert {:ok, block} = CommonAPI.block(blocked, blocker) assert block.local assert User.blocks?(blocker, blocked) @@ -120,7 +120,7 @@ defmodule Pleroma.Web.CommonAPITest do with_mock Pleroma.Web.Federator, publish: fn _ -> nil end do - assert {:ok, block} = CommonAPI.block(blocker, blocked) + assert {:ok, block} = CommonAPI.block(blocked, blocker) assert block.local assert User.blocks?(blocker, blocked) @@ -1914,7 +1914,7 @@ defmodule Pleroma.Web.CommonAPITest do end test "it does not boost if group is blocking poster", %{poster: poster, group: group} do - {:ok, _} = CommonAPI.block(group, poster) + {:ok, _} = CommonAPI.block(poster, group) {:ok, post} = CommonAPI.post(poster, %{status: "hey @#{group.nickname}"}) announces = get_announces_of_object(post.object) diff --git a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs index c3a2a4e25..8e2890c7e 100644 --- a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs @@ -148,7 +148,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do %{user: user, conn: conn} = oauth_access(["read:notifications"]) blocker = insert(:user) - {:ok, _} = CommonAPI.block(blocker, user) + {:ok, _} = CommonAPI.block(user, blocker) {:ok, activity} = CommonAPI.post(blocker, %{status: "hi @#{user.nickname}"}) {:ok, [_notification]} = Notification.create_notifications(activity) diff --git a/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs index c0f3d5a2a..687b23c83 100644 --- a/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs @@ -47,7 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: blocker} do blocked = insert(:user, is_suggested: true) - {:ok, _} = CommonAPI.block(blocker, blocked) + {:ok, _} = CommonAPI.block(blocked, blocker) res = conn From 082319ff482f82c72b633e88dbe06c06205f4faf Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 18:44:32 -0400 Subject: [PATCH 10/15] Fix order of args for unblock/2 --- lib/pleroma/web/common_api.ex | 2 +- lib/pleroma/web/mastodon_api/controllers/account_controller.ex | 2 +- test/pleroma/web/common_api_test.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 4109f8992..9fafa1f27 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -100,7 +100,7 @@ defmodule Pleroma.Web.CommonAPI do end @spec unblock(User.t(), User.t()) :: {:ok, Activity.t()} | {:error, any()} - def unblock(blocker, blocked) do + def unblock(blocked, blocker) do with {_, %Activity{} = block} <- {:fetch_block, Utils.fetch_latest_block(blocker, blocked)}, {:ok, unblock_data, _} <- Builder.undo(blocker, block), {:ok, unblock, _} <- Pipeline.common_pipeline(unblock_data, local: true) do diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 57439c6d4..00dc2e27c 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -504,7 +504,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do @doc "POST /api/v1/accounts/:id/unblock" def unblock(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do - with {:ok, _activity} <- CommonAPI.unblock(blocker, blocked) do + with {:ok, _activity} <- CommonAPI.unblock(blocked, blocker) do render(conn, "relationship.json", user: blocker, target: blocked) else {:error, message} -> json_response(conn, :forbidden, %{error: message}) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 06c912bd0..0c68495bf 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -324,7 +324,7 @@ defmodule Pleroma.Web.CommonAPITest do User.block(blocker, blocked) assert User.blocks?(blocker, blocked) - assert {:ok, :no_activity} == CommonAPI.unblock(blocker, blocked) + assert {:ok, :no_activity} == CommonAPI.unblock(blocked, blocker) refute User.blocks?(blocker, blocked) end end From f79a16c062a14634d8b5f90e08df0b22b799bb45 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 19:07:55 -0400 Subject: [PATCH 11/15] Fix order of args for follow/2 --- lib/pleroma/following_relationship.ex | 2 +- lib/pleroma/user/import.ex | 2 +- .../web/activity_pub/mrf/follow_bot_policy.ex | 2 +- lib/pleroma/web/activity_pub/relay.ex | 2 +- lib/pleroma/web/common_api.ex | 2 +- lib/pleroma/web/mastodon_api/mastodon_api.ex | 2 +- .../controllers/remote_follow_controller.ex | 6 ++--- .../integration/mastodon_websocket_test.exs | 6 ++--- test/pleroma/notification_test.exs | 18 ++++++------- test/pleroma/stats_test.exs | 2 +- test/pleroma/user/backup_test.exs | 2 +- test/pleroma/user_test.exs | 14 +++++----- .../activity_pub_controller_test.exs | 4 +-- .../web/activity_pub/activity_pub_test.exs | 8 +++--- .../activity_pub/mrf/simple_policy_test.exs | 2 +- test/pleroma/web/activity_pub/relay_test.exs | 4 +-- .../web/activity_pub/side_effects_test.exs | 2 +- .../transmogrifier/accept_handling_test.exs | 4 +-- .../transmogrifier/reject_handling_test.exs | 2 +- test/pleroma/web/activity_pub/utils_test.exs | 12 ++++----- .../web/activity_pub/views/user_view_test.exs | 8 +++--- .../controllers/user_controller_test.exs | 2 +- test/pleroma/web/common_api_test.exs | 26 +++++++++---------- .../controllers/account_controller_test.exs | 14 +++++----- .../follow_request_controller_test.exs | 6 ++--- .../notification_controller_test.exs | 12 ++++----- .../suggestion_controller_test.exs | 2 +- .../mastodon_api/views/account_view_test.exs | 24 ++++++++--------- .../views/notification_view_test.exs | 2 +- .../mastodon_api/views/status_view_test.exs | 2 +- .../controllers/account_controller_test.exs | 14 +++++----- test/pleroma/web/push/impl_test.exs | 6 ++--- test/pleroma/web/streamer_test.exs | 20 +++++++------- .../remote_follow_controller_test.exs | 2 +- 34 files changed, 119 insertions(+), 119 deletions(-) diff --git a/lib/pleroma/following_relationship.ex b/lib/pleroma/following_relationship.ex index f38c2fce9..3ec05da13 100644 --- a/lib/pleroma/following_relationship.ex +++ b/lib/pleroma/following_relationship.ex @@ -199,7 +199,7 @@ defmodule Pleroma.FollowingRelationship do |> preload([:follower]) |> Repo.all() |> 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) end) |> case do diff --git a/lib/pleroma/user/import.ex b/lib/pleroma/user/import.ex index f62f1203d..53ffd1ab3 100644 --- a/lib/pleroma/user/import.ex +++ b/lib/pleroma/user/import.ex @@ -46,7 +46,7 @@ defmodule Pleroma.User.Import do fn identifier -> with {:ok, %User{} = followed} <- User.get_or_fetch(identifier), {:ok, follower, followed} <- User.maybe_direct_follow(follower, followed), - {:ok, _, _, _} <- CommonAPI.follow(follower, followed) do + {:ok, _, _, _} <- CommonAPI.follow(followed, follower) do followed else error -> handle_error(:follow_import, identifier, error) diff --git a/lib/pleroma/web/activity_pub/mrf/follow_bot_policy.ex b/lib/pleroma/web/activity_pub/mrf/follow_bot_policy.ex index 5a4a97626..55ea2683c 100644 --- a/lib/pleroma/web/activity_pub/mrf/follow_bot_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/follow_bot_policy.ex @@ -49,7 +49,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.FollowBotPolicy do "#{__MODULE__}: Follow request from #{follower.nickname} to #{user.nickname}" ) - CommonAPI.follow(follower, user) + CommonAPI.follow(user, follower) end end) diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex index 91a647f29..cff234940 100644 --- a/lib/pleroma/web/activity_pub/relay.ex +++ b/lib/pleroma/web/activity_pub/relay.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Web.ActivityPub.Relay do def follow(target_instance) do with %User{} = local_user <- get_actor(), {: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"]}") {:ok, activity} else diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 9fafa1f27..08bca4ffc 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -121,7 +121,7 @@ defmodule Pleroma.Web.CommonAPI do @spec follow(User.t(), User.t()) :: {: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]) with {:ok, follow_data, _} <- Builder.follow(follower, followed), diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex index 467dc2fac..a382e2826 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex @@ -16,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do def follow(follower, followed, params \\ %{}) do result = if not User.following?(follower, followed) do - CommonAPI.follow(follower, followed) + CommonAPI.follow(followed, follower) else {:ok, follower, followed, nil} end diff --git a/lib/pleroma/web/twitter_api/controllers/remote_follow_controller.ex b/lib/pleroma/web/twitter_api/controllers/remote_follow_controller.ex index 1557d95ab..38ebc8c5d 100644 --- a/lib/pleroma/web/twitter_api/controllers/remote_follow_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/remote_follow_controller.ex @@ -73,7 +73,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowController 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)}, - {:ok, _, _, _} <- CommonAPI.follow(user, followee) do + {:ok, _, _, _} <- CommonAPI.follow(followee, user) do redirect(conn, to: "/users/#{followee.id}") else error -> @@ -90,7 +90,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowController do with {_, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)}, {_, {:ok, user}, _} <- {:auth, WrapperAuthenticator.get_user(conn), followee}, {_, _, _, 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}") else error -> @@ -108,7 +108,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowController do {_, _, {:ok, %{user: user}}} <- {:mfa_token, followee, MFA.Token.validate(token)}, {_, _, _, {:ok, _}} <- {: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}") else error -> diff --git a/test/pleroma/integration/mastodon_websocket_test.exs b/test/pleroma/integration/mastodon_websocket_test.exs index 49edeb91e..f499f54ad 100644 --- a/test/pleroma/integration/mastodon_websocket_test.exs +++ b/test/pleroma/integration/mastodon_websocket_test.exs @@ -404,7 +404,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do test "receives private statuses", %{user: reading_user, token: token} do user = insert(:user) - CommonAPI.follow(reading_user, user) + CommonAPI.follow(user, reading_user) {: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 user = insert(:user) - CommonAPI.follow(reading_user, user) + CommonAPI.follow(user, reading_user) {: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 user = insert(:user) - CommonAPI.follow(reading_user, user) + CommonAPI.follow(user, reading_user) {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}") diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index d476ad3f7..4300827a6 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -209,7 +209,7 @@ defmodule Pleroma.NotificationTest do 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}"}) refute Notification.create_notification(activity, followed) end @@ -222,7 +222,7 @@ defmodule Pleroma.NotificationTest do 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}"}) assert Notification.create_notification(activity, receiver) end @@ -238,7 +238,7 @@ defmodule Pleroma.NotificationTest do user = insert(:user) subscriber = insert(:user) - {:ok, _, _, _} = CommonAPI.follow(subscriber, user) + {:ok, _, _, _} = CommonAPI.follow(user, subscriber) User.subscribe(subscriber, user) {:ok, status} = CommonAPI.post(user, %{status: "Akariiiin"}) {:ok, [_notif]} = Notification.create_notifications(status) @@ -309,7 +309,7 @@ defmodule Pleroma.NotificationTest do user = insert(:user) 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 [notification] = Notification.for_user(followed_user) @@ -324,7 +324,7 @@ defmodule Pleroma.NotificationTest do user = insert(:user) 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) assert [notification] = Notification.for_user(followed_user) @@ -349,12 +349,12 @@ defmodule Pleroma.NotificationTest do user = insert(:user) 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 [notification] = Notification.for_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 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 user = insert(:user, is_locked: true) follower = insert(:user) - {:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user) + {:ok, _, _, _follow_activity} = CommonAPI.follow(user, follower) assert [_notification] = Notification.for_user(user) {:ok, _follower} = CommonAPI.reject_follow_request(follower, user) assert [] = Notification.for_user(user) @@ -1101,7 +1101,7 @@ defmodule Pleroma.NotificationTest do 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) assert [notification] = Notification.for_user(followed_user) diff --git a/test/pleroma/stats_test.exs b/test/pleroma/stats_test.exs index a04bed28e..c70603ab9 100644 --- a/test/pleroma/stats_test.exs +++ b/test/pleroma/stats_test.exs @@ -73,7 +73,7 @@ defmodule Pleroma.StatsTest do user = insert(:user) other_user = insert(:user) {: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.repeat(activity.id, other_user) diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs index fbde7fde8..d82d1719b 100644 --- a/test/pleroma/user/backup_test.exs +++ b/test/pleroma/user/backup_test.exs @@ -183,7 +183,7 @@ defmodule Pleroma.User.BackupTest do Bookmark.create(user.id, status2.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, path} = Backup.export(backup, self()) diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index f2a315508..036ae78fb 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -182,8 +182,8 @@ defmodule Pleroma.UserTest do locked = insert(:user, is_locked: true) follower = insert(:user) - CommonAPI.follow(follower, unlocked) - CommonAPI.follow(follower, locked) + CommonAPI.follow(unlocked, follower) + CommonAPI.follow(locked, follower) assert [] = User.get_follow_requests(unlocked) assert [activity] = User.get_follow_requests(locked) @@ -196,9 +196,9 @@ defmodule Pleroma.UserTest do pending_follower = insert(:user) accepted_follower = insert(:user) - CommonAPI.follow(pending_follower, locked) - CommonAPI.follow(pending_follower, locked) - CommonAPI.follow(accepted_follower, locked) + CommonAPI.follow(locked, pending_follower) + CommonAPI.follow(locked, pending_follower) + CommonAPI.follow(locked, accepted_follower) Pleroma.FollowingRelationship.update(accepted_follower, locked, :follow_accept) @@ -209,7 +209,7 @@ defmodule Pleroma.UserTest do locked = insert(:user, is_locked: true) pending_follower = insert(:user, %{is_active: false}) - CommonAPI.follow(pending_follower, locked) + CommonAPI.follow(locked, pending_follower) refute pending_follower.is_active assert [] = User.get_follow_requests(locked) @@ -219,7 +219,7 @@ defmodule Pleroma.UserTest do followed = insert(:user, is_locked: true) follower = insert(:user) - CommonAPI.follow(follower, followed) + CommonAPI.follow(followed, follower) assert [_activity] = User.get_follow_requests(followed) {:ok, _user_relationship} = User.block(followed, follower) diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs index 8adde8730..6aae61835 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -1747,7 +1747,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do %{conn: conn} do user = insert(:user, hide_followers: true) 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 = conn @@ -1843,7 +1843,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do %{conn: conn} do user = insert(:user, hide_follows: true) 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 = conn diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index e6fcf9fcc..164f42480 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -1038,7 +1038,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do refute activity in activities followed_user = insert(:user) - CommonAPI.follow(user, followed_user) + CommonAPI.follow(followed_user, user) {:ok, repeat_activity} = CommonAPI.repeat(activity.id, followed_user) activities = ActivityPub.fetch_activities([], %{blocking_user: user, skip_preload: true}) @@ -1452,7 +1452,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do follower = 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 assert {:error, :reverted} = ActivityPub.unfollow(follower, followed) @@ -1469,7 +1469,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do follower = 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) assert activity.data["type"] == "Undo" @@ -1486,7 +1486,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do follower = insert(:user) 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) assert activity.data["type"] == "Undo" diff --git a/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs b/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs index 57fc00af5..1a51b7d30 100644 --- a/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/simple_policy_test.exs @@ -318,7 +318,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do following_user = insert(:user) non_following_user = insert(:user) - {:ok, _, _, _} = CommonAPI.follow(following_user, actor) + {:ok, _, _, _} = CommonAPI.follow(actor, following_user) activity = %{ "actor" => actor.ap_id, diff --git a/test/pleroma/web/activity_pub/relay_test.exs b/test/pleroma/web/activity_pub/relay_test.exs index 5867246d7..7c45593ed 100644 --- a/test/pleroma/web/activity_pub/relay_test.exs +++ b/test/pleroma/web/activity_pub/relay_test.exs @@ -53,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do test "returns activity" do user = insert(:user) 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 {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id) assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay" @@ -74,7 +74,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do end) 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 Pleroma.Repo.get_by( diff --git a/test/pleroma/web/activity_pub/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs index 417e47487..68922e536 100644 --- a/test/pleroma/web/activity_pub/side_effects_test.exs +++ b/test/pleroma/web/activity_pub/side_effects_test.exs @@ -834,7 +834,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do user = 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, _meta} = ActivityPub.persist(reject_data, local: true) diff --git a/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs index 968fd4ede..4209a24a7 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs @@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do {:ok, follower, followed} = User.follow(follower, followed) assert User.following?(follower, followed) == true - {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) + {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower) accept_data = File.read!("test/fixtures/mastodon-accept-activity.json") @@ -48,7 +48,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do follower = insert(:user) followed = insert(:user, is_locked: true) - {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) + {:ok, _, _, follow_activity} = CommonAPI.follow(followed, follower) accept_data = File.read!("test/fixtures/mastodon-accept-activity.json") diff --git a/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs index 11562422d..225898e85 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs @@ -36,7 +36,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do followed = insert(:user, is_locked: true) {: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 diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index b7d6b8ec7..872a440cb 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -231,8 +231,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do user = insert(:user, is_locked: true) follower = insert(:user) - {:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) - {:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) + {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower) + {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower) data = follow_activity_two.data @@ -253,8 +253,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do user = insert(:user) follower = insert(:user) - {:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) - {:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) + {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower) + {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower) {:ok, follow_activity_two} = 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) follower = insert(:user) - {:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) - {:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) + {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower) + {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower) data = follow_activity_two.data diff --git a/test/pleroma/web/activity_pub/views/user_view_test.exs b/test/pleroma/web/activity_pub/views/user_view_test.exs index c75149dab..c94f8a2bc 100644 --- a/test/pleroma/web/activity_pub/views/user_view_test.exs +++ b/test/pleroma/web/activity_pub/views/user_view_test.exs @@ -138,7 +138,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do test "sets totalItems to zero when followers are hidden" do 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}) user = Map.merge(user, %{hide_followers_count: true, hide_followers: true}) 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 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}) user = Map.merge(user, %{hide_followers_count: false, hide_followers: true}) 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 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}) user = Map.merge(user, %{hide_follows_count: true, hide_follows: true}) 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 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}) user = Map.merge(user, %{hide_follows_count: false, hide_follows: true}) assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user}) diff --git a/test/pleroma/web/admin_api/controllers/user_controller_test.exs b/test/pleroma/web/admin_api/controllers/user_controller_test.exs index 8edfda54c..c8495c477 100644 --- a/test/pleroma/web/admin_api/controllers/user_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/user_controller_test.exs @@ -69,8 +69,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do # Create some activities to check they got deleted later follower = insert(:user) {:ok, _} = CommonAPI.post(user, %{status: "test"}) - {:ok, _, _, _} = CommonAPI.follow(user, follower) {:ok, _, _, _} = CommonAPI.follow(follower, user) + {:ok, _, _, _} = CommonAPI.follow(user, follower) user = Repo.get(User, user.id) assert user.note_count == 1 assert user.follower_count == 1 diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 0c68495bf..19efcb99c 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -80,8 +80,8 @@ defmodule Pleroma.Web.CommonAPITest do setup do blocker = insert(:user) blocked = insert(:user, local: false) - CommonAPI.follow(blocker, blocked) CommonAPI.follow(blocked, blocker) + CommonAPI.follow(blocker, blocked) CommonAPI.accept_follow_request(blocker, blocked) CommonAPI.accept_follow_request(blocked, blocked) %{blocker: blocker, blocked: blocked} @@ -955,7 +955,7 @@ defmodule Pleroma.Web.CommonAPITest do test "author can repeat own private statuses" do author = insert(:user) follower = insert(:user) - CommonAPI.follow(follower, author) + CommonAPI.follow(author, follower) {:ok, activity} = CommonAPI.post(author, %{status: "cofe", visibility: "private"}) @@ -1420,7 +1420,7 @@ defmodule Pleroma.Web.CommonAPITest do describe "follow/2" do test "directly follows a non-locked local user" do [follower, followed] = insert_pair(:user) - {:ok, follower, followed, _} = CommonAPI.follow(follower, followed) + {:ok, follower, followed, _} = CommonAPI.follow(followed, follower) assert User.following?(follower, followed) end @@ -1429,7 +1429,7 @@ defmodule Pleroma.Web.CommonAPITest do describe "unfollow/2" do test "also unsubscribes a user" do [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) assert User.subscribed_to?(follower, followed) @@ -1441,7 +1441,7 @@ defmodule Pleroma.Web.CommonAPITest do test "also unpins a user" do [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) assert User.endorses?(follower, followed) @@ -1456,7 +1456,7 @@ defmodule Pleroma.Web.CommonAPITest do followed = insert(:user, is_locked: true) 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 {:ok, follower} = CommonAPI.unfollow(follower, followed) @@ -1478,7 +1478,7 @@ defmodule Pleroma.Web.CommonAPITest do followed = insert(:user, is_locked: true, local: false) 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 {:ok, follower} = CommonAPI.unfollow(follower, followed) @@ -1502,9 +1502,9 @@ defmodule Pleroma.Web.CommonAPITest do follower = insert(:user) follower_two = insert(:user) - {:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) - {:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) - {:ok, _, _, follow_activity_three} = CommonAPI.follow(follower_two, user) + {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower) + {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower) + {:ok, _, _, follow_activity_three} = CommonAPI.follow(user, follower_two) assert follow_activity.data["state"] == "pending" assert follow_activity_two.data["state"] == "pending" @@ -1522,9 +1522,9 @@ defmodule Pleroma.Web.CommonAPITest do follower = insert(:user) follower_two = insert(:user) - {:ok, _, _, follow_activity} = CommonAPI.follow(follower, user) - {:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user) - {:ok, _, _, follow_activity_three} = CommonAPI.follow(follower_two, user) + {:ok, _, _, follow_activity} = CommonAPI.follow(user, follower) + {:ok, _, _, follow_activity_two} = CommonAPI.follow(user, follower) + {:ok, _, _, follow_activity_three} = CommonAPI.follow(user, follower_two) assert follow_activity.data["state"] == "pending" assert follow_activity_two.data["state"] == "pending" diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index e87b33960..54f6818bd 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -1120,7 +1120,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do |> json_response_and_validate_schema(200) # Follow the user, then the pinned status can be seen - CommonAPI.follow(reader, user) + CommonAPI.follow(user, reader) ObanHelpers.perform_all() assert [%{"id" => ^activity_id, "pinned" => true}] = @@ -2118,7 +2118,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do test "pin account", %{user: user, conn: conn} do %{id: id1} = other_user1 = insert(:user) - CommonAPI.follow(user, other_user1) + CommonAPI.follow(other_user1, user) assert %{"id" => ^id1, "endorsed" => true} = conn @@ -2136,7 +2136,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do test "unpin account", %{user: user, conn: conn} do %{id: id1} = other_user1 = insert(:user) - CommonAPI.follow(user, other_user1) + CommonAPI.follow(other_user1, user) User.endorse(user, other_user1) assert %{"id" => ^id1, "endorsed" => false} = @@ -2156,8 +2156,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do %{id: id1} = other_user1 = insert(:user) %{id: id2} = other_user2 = insert(:user) - CommonAPI.follow(user, other_user1) - CommonAPI.follow(user, other_user2) + CommonAPI.follow(other_user1, user) + CommonAPI.follow(other_user2, user) conn |> 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 %{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} = conn @@ -2240,7 +2240,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do test "removing remote user from followers", %{conn: conn, user: user} do %{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) diff --git a/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs index ff01b549c..b7c7ccae0 100644 --- a/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs @@ -20,7 +20,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do test "/api/v1/follow_requests works", %{user: user, conn: conn} do 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) 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 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) 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 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) diff --git a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs index 8e2890c7e..8fc22dde1 100644 --- a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs @@ -434,7 +434,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) {:ok, favorite_activity} = CommonAPI.favorite(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) 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, favorite_activity} = CommonAPI.favorite(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) 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, _activity} = CommonAPI.favorite(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) @@ -578,7 +578,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do %{user: user, conn: conn} = oauth_access(["read:notifications"]) user2 = insert(:user) - {:ok, _, _, _} = CommonAPI.follow(user, user2) + {:ok, _, _, _} = CommonAPI.follow(user2, user) {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"}) 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"]) user2 = insert(:user) - {:ok, _, _, _} = CommonAPI.follow(user, user2) + {:ok, _, _, _} = CommonAPI.follow(user2, user) {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"}) 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"]) user2 = insert(:user) - {:ok, _, _, _} = CommonAPI.follow(user, user2) + {:ok, _, _, _} = CommonAPI.follow(user2, user) {:ok, _} = CommonAPI.post(user2, %{status: "hey @#{user.nickname}"}) ret_conn = get(conn, "/api/v1/notifications") diff --git a/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs index 687b23c83..01c3384e7 100644 --- a/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs @@ -59,7 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do test "returns v2 suggestions excluding followed accounts", %{conn: conn, user: follower} do followed = insert(:user, is_suggested: true) - {:ok, _, _, _} = CommonAPI.follow(follower, followed) + {:ok, _, _, _} = CommonAPI.follow(followed, follower) res = conn diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index 8dcdaf447..30f8eea5b 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -493,7 +493,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do user = insert(:user) 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) other_user = User.get_cached_by_id(other_user.id) @@ -547,8 +547,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do }) other_user = insert(:user) - {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user) - {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) + {:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user) + {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user) assert %{ followers_count: 0, @@ -560,8 +560,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do test "shows when follows/followers are hidden" do user = insert(:user, hide_followers: true, hide_follows: true) other_user = insert(:user) - {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user) - {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user) + {:ok, user, other_user, _activity} = CommonAPI.follow(other_user, user) + {:ok, _other_user, user, _activity} = CommonAPI.follow(user, other_user) assert %{ followers_count: 1, @@ -573,11 +573,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do test "shows actual follower/following count to the account owner" do user = insert(:user, hide_followers: true, hide_follows: true) 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 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 %{ followers_count: 1, @@ -684,7 +684,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do AccountView.render("show.json", %{user: user, for: 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} = 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}) 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} = 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}) 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} = 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}) 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} = 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}) 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}) diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs index 3ad5e1606..fae672871 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -132,7 +132,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do test "Follow notification" do follower = 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) expected = %{ diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index 88a3940c3..afe0ccb28 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -479,7 +479,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do # After following the user, the quote is rendered follower = insert(:user) - CommonAPI.follow(follower, user) + CommonAPI.follow(user, follower) status = StatusView.render("show.json", %{activity: quote_private, for: follower}) assert status.pleroma.quote.id == to_string(private.id) diff --git a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs index 5af5a6138..61880e2c0 100644 --- a/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/account_controller_test.exs @@ -286,8 +286,8 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do %{id: id2} = user2 = insert(:user) %{id: id3} = user3 = insert(:user) - CommonAPI.follow(user1, user2) - CommonAPI.follow(user1, user3) + CommonAPI.follow(user2, user1) + CommonAPI.follow(user3, user1) User.endorse(user1, user2) User.endorse(user1, user3) @@ -324,9 +324,9 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do user3 = insert(:user) - CommonAPI.follow(user, user1) - CommonAPI.follow(user, user2) - CommonAPI.follow(user, user3) + CommonAPI.follow(user1, user) + CommonAPI.follow(user2, user) + CommonAPI.follow(user3, user) [%{"id" => ^id1}] = conn @@ -350,8 +350,8 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do show_birthday: true }) - CommonAPI.follow(user, user1) - CommonAPI.follow(user, user2) + CommonAPI.follow(user1, user) + CommonAPI.follow(user2, user) [%{"id" => ^id2}] = conn diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index dcd909f1c..ffc38dc80 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -78,7 +78,7 @@ defmodule Pleroma.Web.Push.ImplTest do ) other_user = insert(:user) - {:ok, _, _, activity} = CommonAPI.follow(user, other_user) + {:ok, _, _, activity} = CommonAPI.follow(other_user, user) notif = insert(:notification, @@ -103,7 +103,7 @@ defmodule Pleroma.Web.Push.ImplTest do ) other_user = insert(:user) - {:ok, _, _, activity} = CommonAPI.follow(user, other_user) + {:ok, _, _, activity} = CommonAPI.follow(other_user, user) notif = insert(:notification, @@ -154,7 +154,7 @@ defmodule Pleroma.Web.Push.ImplTest do test "renders title and body for follow activity" do user = insert(:user, nickname: "Bob") other_user = insert(:user) - {:ok, _, _, activity} = CommonAPI.follow(user, other_user) + {:ok, _, _, activity} = CommonAPI.follow(other_user, user) object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "follow"}, user, object) == diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index edeec187c..b6f30eb7c 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -477,7 +477,7 @@ defmodule Pleroma.Web.StreamerTest do user2 = insert(:user) 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 notif.activity.id == follow_activity.id @@ -493,7 +493,7 @@ defmodule Pleroma.Web.StreamerTest do other_user_id = other_user.id 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} @@ -536,7 +536,7 @@ defmodule Pleroma.Web.StreamerTest do test "it streams edits in the 'user' stream", %{user: user, token: oauth_token} do sender = insert(:user) - {:ok, _, _, _} = CommonAPI.follow(user, sender) + {:ok, _, _, _} = CommonAPI.follow(sender, user) {: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 user2 = insert(:user) user3 = insert(:user) - CommonAPI.follow(user1, user2) + CommonAPI.follow(user2, user1) CommonAPI.hide_reblogs(user1, user2) {:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"}) @@ -842,7 +842,7 @@ defmodule Pleroma.Web.StreamerTest do token: user1_token } do user2 = insert(:user) - CommonAPI.follow(user1, user2) + CommonAPI.follow(user2, user1) CommonAPI.hide_reblogs(user1, user2) {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"}) @@ -858,7 +858,7 @@ defmodule Pleroma.Web.StreamerTest do token: user1_token } do user2 = insert(:user) - CommonAPI.follow(user1, user2) + CommonAPI.follow(user2, user1) CommonAPI.hide_reblogs(user1, user2) {: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"]) 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, _} = CommonAPI.add_mute(activity, user2) @@ -1026,8 +1026,8 @@ defmodule Pleroma.Web.StreamerTest do %{user: user2, token: user2_token} = oauth_access(["read"]) post_user = insert(:user) - CommonAPI.follow(user, post_user) - CommonAPI.follow(user2, post_user) + CommonAPI.follow(post_user, user) + CommonAPI.follow(post_user, user2) tasks = [ Task.async(child_proc.(starter.(user, token), hit)), @@ -1058,7 +1058,7 @@ defmodule Pleroma.Web.StreamerTest do %{user: user, token: token} = oauth_access(["read"]) post_user = insert(:user) - CommonAPI.follow(user, post_user) + CommonAPI.follow(post_user, user) tasks = [ Task.async(child_proc.(starter.(user, token), hit)), diff --git a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs index c6ecb53f4..f762b1356 100644 --- a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs +++ b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs @@ -216,7 +216,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do test "returns success result when user already in followers", %{conn: conn} do user = insert(:user) user2 = insert(:user) - {:ok, _, _, _} = CommonAPI.follow(user, user2) + {:ok, _, _, _} = CommonAPI.follow(user2, user) conn = conn From adb93f7e5d9b86a02f5114f0597b8274e4ada88d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 19:11:22 -0400 Subject: [PATCH 12/15] Fix order of args for unfollow/2 --- lib/pleroma/following_relationship.ex | 2 +- lib/pleroma/web/common_api.ex | 2 +- .../web/mastodon_api/controllers/account_controller.ex | 2 +- test/pleroma/notification_test.exs | 2 +- test/pleroma/web/common_api_test.exs | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/pleroma/following_relationship.ex b/lib/pleroma/following_relationship.ex index 3ec05da13..495488dfd 100644 --- a/lib/pleroma/following_relationship.ex +++ b/lib/pleroma/following_relationship.ex @@ -200,7 +200,7 @@ defmodule Pleroma.FollowingRelationship do |> Repo.all() |> Enum.map(fn following_relationship -> Pleroma.Web.CommonAPI.follow(target, following_relationship.follower) - Pleroma.Web.CommonAPI.unfollow(following_relationship.follower, origin) + Pleroma.Web.CommonAPI.unfollow(origin, following_relationship.follower) end) |> case do [] -> diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 08bca4ffc..827710c11 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -136,7 +136,7 @@ defmodule Pleroma.Web.CommonAPI do end @spec unfollow(User.t(), User.t()) :: {:ok, User.t()} | {:error, any()} - def unfollow(follower, unfollowed) do + def unfollow(unfollowed, follower) do with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed), {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed), {:ok, _subscription} <- User.unsubscribe(follower, unfollowed), diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 00dc2e27c..80ab95a57 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -460,7 +460,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do end def unfollow(%{assigns: %{user: follower, account: followed}} = conn, _params) do - with {:ok, follower} <- CommonAPI.unfollow(follower, followed) do + with {:ok, follower} <- CommonAPI.unfollow(followed, follower) do render(conn, "relationship.json", user: follower, target: followed) end end diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 4300827a6..e595c5c53 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -353,7 +353,7 @@ defmodule Pleroma.NotificationTest do assert FollowingRelationship.following?(user, followed_user) assert [notification] = Notification.for_user(followed_user) - CommonAPI.unfollow(user, followed_user) + CommonAPI.unfollow(followed_user, user) {:ok, _, _, _activity_dupe} = CommonAPI.follow(followed_user, user) notification_id = notification.id diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 19efcb99c..c1b825d93 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1434,7 +1434,7 @@ defmodule Pleroma.Web.CommonAPITest do assert User.subscribed_to?(follower, followed) - {:ok, follower} = CommonAPI.unfollow(follower, followed) + {:ok, follower} = CommonAPI.unfollow(followed, follower) refute User.subscribed_to?(follower, followed) end @@ -1446,7 +1446,7 @@ defmodule Pleroma.Web.CommonAPITest do assert User.endorses?(follower, followed) - {:ok, follower} = CommonAPI.unfollow(follower, followed) + {:ok, follower} = CommonAPI.unfollow(followed, follower) refute User.endorses?(follower, followed) end @@ -1459,7 +1459,7 @@ defmodule Pleroma.Web.CommonAPITest do CommonAPI.follow(followed, follower) assert User.get_follow_state(follower, followed) == :follow_pending - assert {:ok, follower} = CommonAPI.unfollow(follower, followed) + assert {:ok, follower} = CommonAPI.unfollow(followed, follower) assert User.get_follow_state(follower, followed) == nil assert %{id: ^activity_id, data: %{"state" => "cancelled"}} = @@ -1481,7 +1481,7 @@ defmodule Pleroma.Web.CommonAPITest do CommonAPI.follow(followed, follower) assert User.get_follow_state(follower, followed) == :follow_pending - assert {:ok, follower} = CommonAPI.unfollow(follower, followed) + assert {:ok, follower} = CommonAPI.unfollow(followed, follower) assert User.get_follow_state(follower, followed) == nil assert %{id: ^activity_id, data: %{"state" => "cancelled"}} = From 3f4f567c9cbc0182eb99ec951a6088bfc5bb57d5 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 19:16:00 -0400 Subject: [PATCH 13/15] Fix order of args for hide_reblogs/2 --- lib/pleroma/web/common_api.ex | 2 +- lib/pleroma/web/mastodon_api/mastodon_api.ex | 2 +- test/pleroma/web/activity_pub/activity_pub_test.exs | 4 ++-- test/pleroma/web/common_api_test.exs | 4 ++-- test/pleroma/web/mastodon_api/views/account_view_test.exs | 2 +- test/pleroma/web/streamer_test.exs | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 827710c11..13d738310 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -687,7 +687,7 @@ defmodule Pleroma.Web.CommonAPI do defp set_visibility(activity, _), do: {:ok, activity} @spec hide_reblogs(User.t(), User.t()) :: {:ok, any()} | {:error, any()} - def hide_reblogs(%User{} = user, %User{} = target) do + def hide_reblogs(%User{} = target, %User{} = user) do UserRelationship.create_reblog_mute(user, target) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex index a382e2826..c6243d654 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex @@ -30,7 +30,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do end defp set_reblogs_visibility(false, {:ok, follower, followed, _}) do - CommonAPI.hide_reblogs(follower, followed) + CommonAPI.hide_reblogs(followed, follower) end defp set_reblogs_visibility(_, {:ok, follower, followed, _}) do diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index 164f42480..4ec453127 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -1358,7 +1358,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do activity = insert(:note_activity) user = insert(:user) booster = insert(:user) - {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, booster) + {:ok, _reblog_mute} = CommonAPI.hide_reblogs(booster, user) {:ok, activity} = CommonAPI.repeat(activity.id, booster) @@ -1371,7 +1371,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do activity = insert(:note_activity) user = insert(:user) booster = insert(:user) - {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, booster) + {:ok, _reblog_mute} = CommonAPI.hide_reblogs(booster, user) {:ok, _reblog_mute} = CommonAPI.show_reblogs(user, booster) {:ok, activity} = CommonAPI.repeat(activity.id, booster) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index c1b825d93..e0fb6d63d 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1404,13 +1404,13 @@ defmodule Pleroma.Web.CommonAPITest do end test "add a reblog mute", %{muter: muter, muted: muted} do - {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted) + {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muted, muter) assert User.showing_reblogs?(muter, muted) == false end test "remove a reblog mute", %{muter: muter, muted: muted} do - {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muter, muted) + {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muted, muter) {:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted) assert User.showing_reblogs?(muter, muted) == true diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index 30f8eea5b..f0711fa0d 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -436,7 +436,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do {:ok, other_user, user} = User.follow(other_user, user) {:ok, _subscription} = User.subscribe(user, other_user) {:ok, _user_relationships} = User.mute(user, other_user, %{notifications: true}) - {:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user) + {:ok, _reblog_mute} = CommonAPI.hide_reblogs(other_user, user) expected = Map.merge( diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index b6f30eb7c..262ff11d2 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -827,7 +827,7 @@ defmodule Pleroma.Web.StreamerTest do user2 = insert(:user) user3 = insert(:user) CommonAPI.follow(user2, user1) - CommonAPI.hide_reblogs(user1, user2) + CommonAPI.hide_reblogs(user2, user1) {:ok, create_activity} = CommonAPI.post(user3, %{status: "I'm kawen"}) @@ -843,7 +843,7 @@ defmodule Pleroma.Web.StreamerTest do } do user2 = insert(:user) CommonAPI.follow(user2, user1) - CommonAPI.hide_reblogs(user1, user2) + CommonAPI.hide_reblogs(user2, user1) {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"}) Streamer.get_topic_and_add_socket("user", user1, user1_token) @@ -859,7 +859,7 @@ defmodule Pleroma.Web.StreamerTest do } do user2 = insert(:user) CommonAPI.follow(user2, user1) - CommonAPI.hide_reblogs(user1, user2) + CommonAPI.hide_reblogs(user2, user1) {:ok, create_activity} = CommonAPI.post(user1, %{status: "I'm kawen"}) Streamer.get_topic_and_add_socket("user", user1, user1_token) From 12f498bc0d996ccdacf7769d57b96b1c2ecabdb3 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 19:19:21 -0400 Subject: [PATCH 14/15] Fix order of args for show_reblogs/2 --- lib/pleroma/web/common_api.ex | 2 +- lib/pleroma/web/mastodon_api/mastodon_api.ex | 2 +- test/pleroma/web/activity_pub/activity_pub_test.exs | 2 +- test/pleroma/web/common_api_test.exs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 13d738310..06faf845e 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -692,7 +692,7 @@ defmodule Pleroma.Web.CommonAPI do end @spec show_reblogs(User.t(), User.t()) :: {:ok, any()} | {:error, any()} - def show_reblogs(%User{} = user, %User{} = target) do + def show_reblogs(%User{} = target, %User{} = user) do UserRelationship.delete_reblog_mute(user, target) end diff --git a/lib/pleroma/web/mastodon_api/mastodon_api.ex b/lib/pleroma/web/mastodon_api/mastodon_api.ex index c6243d654..6dcbfb097 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api.ex @@ -34,7 +34,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do end defp set_reblogs_visibility(_, {:ok, follower, followed, _}) do - CommonAPI.show_reblogs(follower, followed) + CommonAPI.show_reblogs(followed, follower) end defp set_subscription(true, {:ok, follower, followed, _}) do diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index 4ec453127..b4f6fb68a 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -1372,7 +1372,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do user = insert(:user) booster = insert(:user) {:ok, _reblog_mute} = CommonAPI.hide_reblogs(booster, user) - {:ok, _reblog_mute} = CommonAPI.show_reblogs(user, booster) + {:ok, _reblog_mute} = CommonAPI.show_reblogs(booster, user) {:ok, activity} = CommonAPI.repeat(activity.id, booster) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index e0fb6d63d..b6fba6999 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1411,7 +1411,7 @@ defmodule Pleroma.Web.CommonAPITest do test "remove a reblog mute", %{muter: muter, muted: muted} do {:ok, _reblog_mute} = CommonAPI.hide_reblogs(muted, muter) - {:ok, _reblog_mute} = CommonAPI.show_reblogs(muter, muted) + {:ok, _reblog_mute} = CommonAPI.show_reblogs(muted, muter) assert User.showing_reblogs?(muter, muted) == true end From c700c5db43b7580bb70f2c7dac23c4250b7d5312 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 19:23:16 -0400 Subject: [PATCH 15/15] changelog --- changelog.d/commonapi-reordering.skip | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 changelog.d/commonapi-reordering.skip diff --git a/changelog.d/commonapi-reordering.skip b/changelog.d/commonapi-reordering.skip new file mode 100644 index 000000000..e69de29bb