From c31ddce51ea18f052c1c3ad30a221b77c7a94e71 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Fri, 15 Nov 2019 21:38:54 +0300 Subject: [PATCH] [#1335] Reorganized `users.mutes` as relation to UserMute entity. --- lib/pleroma/user.ex | 114 ++++++++++++------ lib/pleroma/user_mute.ex | 71 +++++++++++ lib/pleroma/web/activity_pub/activity_pub.ex | 6 +- .../controllers/account_controller.ex | 8 +- .../web/mastodon_api/views/account_view.ex | 4 +- lib/pleroma/web/streamer/worker.ex | 3 +- ...11_data_migration_populate_user_blocks.exs | 3 +- .../20191112151559_create_user_mutes.exs | 14 +++ ...614_data_migration_populate_user_mutes.exs | 48 ++++++++ test/notification_test.exs | 11 +- test/user_test.exs | 11 +- test/web/activity_pub/activity_pub_test.exs | 9 +- .../controllers/account_controller_test.exs | 2 +- .../notification_controller_test.exs | 9 +- .../mastodon_api/views/account_view_test.exs | 5 +- .../mastodon_api/views/status_view_test.exs | 4 +- 16 files changed, 258 insertions(+), 64 deletions(-) create mode 100644 lib/pleroma/user_mute.ex create mode 100644 priv/repo/migrations/20191112151559_create_user_mutes.exs create mode 100644 priv/repo/migrations/20191112151614_data_migration_populate_user_mutes.exs diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 9dd1ad8fc..383c45992 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -23,6 +23,7 @@ defmodule Pleroma.User do alias Pleroma.RepoStreamer alias Pleroma.User alias Pleroma.UserBlock + alias Pleroma.UserMute alias Pleroma.Web alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils @@ -119,11 +120,17 @@ defmodule Pleroma.User do has_many(:notifications, Notification) has_many(:registrations, Registration) has_many(:deliveries, Delivery) + has_many(:blocker_blocks, UserBlock, foreign_key: :blocker_id) has_many(:blockee_blocks, UserBlock, foreign_key: :blockee_id) has_many(:blocked_users, through: [:blocker_blocks, :blockee]) has_many(:blocker_users, through: [:blockee_blocks, :blocker]) + has_many(:muter_mutes, UserMute, foreign_key: :muter_id) + has_many(:mutee_mutes, UserMute, foreign_key: :mutee_id) + has_many(:muted_users, through: [:muter_mutes, :mutee]) + has_many(:muter_users, through: [:mutee_mutes, :muter]) + field(:info, :map, default: %{}) # `:blocks` is deprecated (replaced with `blocked_users` relation) @@ -968,12 +975,12 @@ defmodule Pleroma.User do end @spec mute(User.t(), User.t(), boolean()) :: {:ok, User.t()} | {:error, String.t()} - def mute(muter, %User{ap_id: ap_id}, notifications? \\ true) do - add_to_mutes(muter, ap_id, notifications?) + def mute(muter, %User{} = mutee, notifications? \\ true) do + add_to_mutes(muter, mutee, notifications?) end - def unmute(muter, %{ap_id: ap_id}) do - remove_from_mutes(muter, ap_id) + def unmute(muter, %User{} = mutee) do + remove_from_mutes(muter, mutee) end def subscribe(subscriber, %{ap_id: ap_id}) do @@ -1041,7 +1048,11 @@ defmodule Pleroma.User do end def mutes?(nil, _), do: false - def mutes?(user, %{ap_id: ap_id}), do: Enum.member?(user.mutes, ap_id) + def mutes?(%User{} = user, %User{} = target), do: mutes_user?(user, target) + + def mutes_user?(%User{} = user, %User{} = target) do + UserMute.exists?(user, target) + end @spec muted_notifications?(User.t() | nil, User.t() | map()) :: boolean() def muted_notifications?(nil, _), do: false @@ -1049,17 +1060,17 @@ defmodule Pleroma.User do def muted_notifications?(user, %{ap_id: ap_id}), do: Enum.member?(user.muted_notifications, ap_id) - def blocks?(%User{} = user, %User{} = target) do - blocks_ap_id?(user, target) || blocks_domain?(user, target) - end - def blocks?(nil, _), do: false - def blocks_ap_id?(%User{} = user, %User{} = target) do + def blocks?(%User{} = user, %User{} = target) do + blocks_user?(user, target) || blocks_domain?(user, target) + end + + def blocks_user?(%User{} = user, %User{} = target) do UserBlock.exists?(user, target) end - def blocks_ap_id?(_, _), do: false + def blocks_user?(_, _), do: false def blocks_domain?(%User{} = user, %User{} = target) do domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks) @@ -1077,7 +1088,16 @@ defmodule Pleroma.User do @spec muted_users(User.t()) :: [User.t()] def muted_users(user) do - User.Query.build(%{ap_id: user.mutes, deactivated: false}) + user + |> assoc(:muted_users) + |> restrict_deactivated() + |> Repo.all() + end + + def muted_ap_ids(user) do + user + |> assoc(:muted_users) + |> select([u], u.ap_id) |> Repo.all() end @@ -1096,6 +1116,35 @@ defmodule Pleroma.User do |> Repo.all() end + defp related_ap_ids_sql(join_table, source_column, target_column) do + "(SELECT array_agg(u.ap_id) FROM users as u " <> + "INNER JOIN #{join_table} AS join_table " <> + "ON join_table.#{source_column} = $1 " <> + "WHERE u.id = join_table.#{target_column})" + end + + @related_ap_ids_sql_params %{ + blocked_users: ["user_blocks", "blocker_id", "blockee_id"], + muted_users: ["user_mutes", "muter_id", "mutee_id"] + } + + def related_ap_ids(user, relations) when is_list(relations) do + query = + relations + |> Enum.map(fn r -> @related_ap_ids_sql_params[r] end) + |> Enum.filter(& &1) + |> Enum.map(fn [join_table, source_column, target_column] -> + related_ap_ids_sql(join_table, source_column, target_column) + end) + |> Enum.join(", ") + + with {:ok, %{rows: [ap_ids_arrays]}} <- + Repo.query("SELECT #{query}", [FlakeId.from_string(user.id)]) do + ap_ids_arrays = Enum.map(ap_ids_arrays, &(&1 || [])) + {:ok, ap_ids_arrays} + end + end + @spec subscribers(User.t()) :: [User.t()] def subscribers(user) do User.Query.build(%{ap_id: user.subscribers, deactivated: false}) @@ -1877,32 +1926,27 @@ defmodule Pleroma.User do UserBlock.delete(user, blocked) end - defp set_mutes(user, mutes) do - params = %{mutes: mutes} - - user - |> cast(params, [:mutes]) - |> validate_required([:mutes]) - |> update_and_set_cache() - end - - def add_to_mutes(user, muted, notifications?) do - with {:ok, user} <- set_mutes(user, Enum.uniq([muted | user.mutes])) do - set_notification_mutes( - user, - Enum.uniq([muted | user.muted_notifications]), - notifications? - ) + defp add_to_mutes(%User{} = user, %User{ap_id: ap_id} = muted_user, notifications?) do + with {:ok, user_mute} <- UserMute.create(user, muted_user), + {:ok, _user} <- + set_notification_mutes( + user, + Enum.uniq([ap_id | user.muted_notifications]), + notifications? + ) do + {:ok, user_mute} end end - def remove_from_mutes(user, muted) do - with {:ok, user} <- set_mutes(user, List.delete(user.mutes, muted)) do - set_notification_mutes( - user, - List.delete(user.muted_notifications, muted), - true - ) + defp remove_from_mutes(user, %User{ap_id: ap_id} = muted_user) do + with {:ok, user_mute} <- UserMute.delete(user, muted_user), + {:ok, _user} <- + set_notification_mutes( + user, + List.delete(user.muted_notifications, ap_id), + true + ) do + {:ok, user_mute} end end diff --git a/lib/pleroma/user_mute.ex b/lib/pleroma/user_mute.ex new file mode 100644 index 000000000..417a5ff84 --- /dev/null +++ b/lib/pleroma/user_mute.ex @@ -0,0 +1,71 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.UserMute do + use Ecto.Schema + + import Ecto.Changeset + import Ecto.Query + + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.UserMute + + schema "user_mutes" do + belongs_to(:muter, User, type: FlakeId.Ecto.CompatType) + belongs_to(:mutee, User, type: FlakeId.Ecto.CompatType) + + timestamps(updated_at: false) + end + + def changeset(%UserMute{} = user_mute, params \\ %{}) do + user_mute + |> cast(params, [:muter_id, :mutee_id]) + |> validate_required([:muter_id, :mutee_id]) + |> unique_constraint(:mutee_id, name: :user_mutes_muter_id_mutee_id_index) + |> validate_not_self_mute() + end + + def exists?(%User{} = muter, %User{} = mutee) do + UserMute + |> where(muter_id: ^muter.id, mutee_id: ^mutee.id) + |> Repo.exists?() + end + + def create(%User{} = muter, %User{} = mutee) do + %UserMute{} + |> changeset(%{muter_id: muter.id, mutee_id: mutee.id}) + |> Repo.insert( + on_conflict: :replace_all_except_primary_key, + conflict_target: [:muter_id, :mutee_id] + ) + end + + def delete(%User{} = muter, %User{} = mutee) do + attrs = %{muter_id: muter.id, mutee_id: mutee.id} + + case Repo.get_by(UserMute, attrs) do + %UserMute{} = existing_record -> Repo.delete(existing_record) + nil -> {:ok, nil} + end + end + + defp validate_not_self_mute(%Ecto.Changeset{} = changeset) do + changeset + |> validate_change(:mutee_id, fn _, mutee_id -> + if mutee_id == get_field(changeset, :muter_id) do + [mutee_id: "can't be equal to muter_id"] + else + [] + end + end) + |> validate_change(:muter_id, fn _, muter_id -> + if muter_id == get_field(changeset, :mutee_id) do + [muter_id: "can't be equal to mutee_id"] + else + [] + end + end) + end +end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 82203ef5c..cba2abfc3 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -858,7 +858,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query defp restrict_muted(query, %{"muting_user" => %User{} = user} = opts) do - mutes = user.mutes + mutes = opts["muted_ap_ids"] || User.muted_ap_ids(user) query = from([activity] in query, @@ -875,8 +875,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do defp restrict_muted(query, _), do: query - defp restrict_blocked(query, %{"blocking_user" => %User{} = user}) do - blocked_ap_ids = User.blocked_ap_ids(user) + defp restrict_blocked(query, %{"blocking_user" => %User{} = user} = opts) do + blocked_ap_ids = opts["blocked_ap_ids"] || User.blocked_ap_ids(user) domain_blocks = user.domain_blocks || [] query = diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 7c94a35d9..e37d3bb07 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -323,7 +323,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do def mute(%{assigns: %{user: muter, account: muted}} = conn, params) do notifications? = params |> Map.get("notifications", true) |> truthy_param?() - with {:ok, muter} <- User.mute(muter, muted, notifications?) do + with {:ok, _user_mute} <- User.mute(muter, muted, notifications?) do + # TODO: remove `muter` refresh once `muted_notifications` field is deprecated + muter = User.get_cached_by_id(muter.id) render(conn, "relationship.json", user: muter, target: muted) else {:error, message} -> json_response(conn, :forbidden, %{error: message}) @@ -332,7 +334,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do @doc "POST /api/v1/accounts/:id/unmute" def unmute(%{assigns: %{user: muter, account: muted}} = conn, _params) do - with {:ok, muter} <- User.unmute(muter, muted) do + with {:ok, _user_mute} <- User.unmute(muter, muted) do + # TODO: remove `muter` refresh once `muted_notifications` field is deprecated + muter = User.get_cached_by_id(muter.id) render(conn, "relationship.json", user: muter, target: muted) else {:error, message} -> json_response(conn, :forbidden, %{error: message}) diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index e30fed610..37dc8e194 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -50,8 +50,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do id: to_string(target.id), following: User.following?(user, target), followed_by: User.following?(target, user), - blocking: User.blocks_ap_id?(user, target), - blocked_by: User.blocks_ap_id?(target, user), + blocking: User.blocks_user?(user, target), + blocked_by: User.blocks_user?(target, user), muting: User.mutes?(user, target), muting_notifications: User.muted_notifications?(user, target), subscribing: User.subscribed_to?(user, target), diff --git a/lib/pleroma/web/streamer/worker.ex b/lib/pleroma/web/streamer/worker.ex index 672dd52ee..45f9c7c53 100644 --- a/lib/pleroma/web/streamer/worker.ex +++ b/lib/pleroma/web/streamer/worker.ex @@ -129,8 +129,7 @@ defmodule Pleroma.Web.Streamer.Worker do end defp should_send?(%User{} = user, %Activity{} = item) do - blocks = User.blocked_ap_ids(user) - mutes = user.mutes || [] + {:ok, [blocks, mutes]} = User.related_ap_ids(user, [:blocked_users, :muted_users]) reblog_mutes = user.muted_reblogs || [] recipient_blocks = MapSet.new(blocks ++ mutes) recipients = MapSet.new(item.recipients) diff --git a/priv/repo/migrations/20191108173911_data_migration_populate_user_blocks.exs b/priv/repo/migrations/20191108173911_data_migration_populate_user_blocks.exs index 728da8211..fe537679d 100644 --- a/priv/repo/migrations/20191108173911_data_migration_populate_user_blocks.exs +++ b/priv/repo/migrations/20191108173911_data_migration_populate_user_blocks.exs @@ -30,9 +30,8 @@ defmodule Pleroma.Repo.Migrations.DataMigrationPopulateUserBlocks do for blockee_ap_id <- blockee_ap_ids do blockee_id = blockee_id_by_ap_id[blockee_ap_id] - blockee_uuid = blockee_id && Ecto.UUID.cast!(blockee_id) - with {:ok, blockee_uuid} <- Ecto.UUID.cast(blockee_id) do + with {:ok, blockee_uuid} <- blockee_id && Ecto.UUID.cast(blockee_id) do execute( "INSERT INTO user_blocks(blocker_id, blockee_id, inserted_at) " <> "VALUES('#{blocker_uuid}'::uuid, '#{blockee_uuid}'::uuid, now()) " <> diff --git a/priv/repo/migrations/20191112151559_create_user_mutes.exs b/priv/repo/migrations/20191112151559_create_user_mutes.exs new file mode 100644 index 000000000..eaa285de2 --- /dev/null +++ b/priv/repo/migrations/20191112151559_create_user_mutes.exs @@ -0,0 +1,14 @@ +defmodule Pleroma.Repo.Migrations.CreateUserMutes do + use Ecto.Migration + + def change do + create_if_not_exists table(:user_mutes) do + add(:muter_id, references(:users, type: :uuid, on_delete: :delete_all)) + add(:mutee_id, references(:users, type: :uuid, on_delete: :delete_all)) + + timestamps(updated_at: false) + end + + create_if_not_exists(unique_index(:user_mutes, [:muter_id, :mutee_id])) + end +end diff --git a/priv/repo/migrations/20191112151614_data_migration_populate_user_mutes.exs b/priv/repo/migrations/20191112151614_data_migration_populate_user_mutes.exs new file mode 100644 index 000000000..a8bdd072e --- /dev/null +++ b/priv/repo/migrations/20191112151614_data_migration_populate_user_mutes.exs @@ -0,0 +1,48 @@ +defmodule Pleroma.Repo.Migrations.DataMigrationPopulateUserMutes do + use Ecto.Migration + + alias Ecto.Adapters.SQL + alias Pleroma.Repo + + require Logger + + def up do + {:ok, %{rows: mute_rows}} = SQL.query(Repo, "SELECT id, mutes FROM users WHERE mutes != '{}'") + + mutee_ap_ids = + Enum.flat_map( + mute_rows, + fn [_, ap_ids] -> ap_ids end + ) + |> Enum.uniq() + + # Selecting ids of all mutees at once in order to reduce the number of SELECT queries + {:ok, %{rows: mutee_ap_id_id}} = + SQL.query(Repo, "SELECT ap_id, id FROM users WHERE ap_id = ANY($1)", [mutee_ap_ids]) + + mutee_id_by_ap_id = Enum.into(mutee_ap_id_id, %{}, fn [k, v] -> {k, v} end) + + Enum.each( + mute_rows, + fn [muter_id, mutee_ap_ids] -> + muter_uuid = Ecto.UUID.cast!(muter_id) + + for mutee_ap_id <- mutee_ap_ids do + mutee_id = mutee_id_by_ap_id[mutee_ap_id] + + with {:ok, mutee_uuid} <- mutee_id && Ecto.UUID.cast(mutee_id) do + execute( + "INSERT INTO user_mutes(muter_id, mutee_id, inserted_at) " <> + "VALUES('#{muter_uuid}'::uuid, '#{mutee_uuid}'::uuid, now()) " <> + "ON CONFLICT (muter_id, mutee_id) DO NOTHING" + ) + else + _ -> Logger.warn("Missing reference: (#{muter_uuid}, #{mutee_id})") + end + end + end + ) + end + + def down, do: :noop +end diff --git a/test/notification_test.exs b/test/notification_test.exs index 5388214ba..d3d409c68 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -112,7 +112,7 @@ defmodule Pleroma.NotificationTest do muter = insert(:user) muted = insert(:user) - {:ok, muter} = User.mute(muter, muted, false) + {:ok, _user_mute} = User.mute(muter, muted, false) {:ok, activity} = CommonAPI.post(muted, %{"status" => "Hi @#{muter.nickname}"}) @@ -636,7 +636,7 @@ defmodule Pleroma.NotificationTest do test "it returns notifications for muted user without notifications" do user = insert(:user) muted = insert(:user) - {:ok, user} = User.mute(user, muted, false) + {:ok, _user_mute} = User.mute(user, muted, false) {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"}) @@ -646,7 +646,10 @@ defmodule Pleroma.NotificationTest do test "it doesn't return notifications for muted user with notifications" do user = insert(:user) muted = insert(:user) - {:ok, user} = User.mute(user, muted) + {:ok, _user_mute} = User.mute(user, muted) + + # Refreshing to reflect embedded ap id relation fields (remove once removed) + user = refresh_record(user) {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"}) @@ -686,7 +689,7 @@ defmodule Pleroma.NotificationTest do test "it returns notifications from a muted user when with_muted is set" do user = insert(:user) muted = insert(:user) - {:ok, user} = User.mute(user, muted) + {:ok, _user_mute} = User.mute(user, muted) {:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"}) diff --git a/test/user_test.exs b/test/user_test.exs index fa8d336f2..15b4f67f6 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -673,7 +673,10 @@ defmodule Pleroma.UserTest do refute User.mutes?(user, muted_user) refute User.muted_notifications?(user, muted_user) - {:ok, user} = User.mute(user, muted_user) + {:ok, _user_mute} = User.mute(user, muted_user) + + # Refreshing to reflect embedded ap id relation fields (remove once removed) + user = refresh_record(user) assert User.mutes?(user, muted_user) assert User.muted_notifications?(user, muted_user) @@ -683,8 +686,8 @@ defmodule Pleroma.UserTest do user = insert(:user) muted_user = insert(:user) - {:ok, user} = User.mute(user, muted_user) - {:ok, user} = User.unmute(user, muted_user) + {:ok, _user_mute} = User.mute(user, muted_user) + {:ok, _user_mute} = User.unmute(user, muted_user) refute User.mutes?(user, muted_user) refute User.muted_notifications?(user, muted_user) @@ -697,7 +700,7 @@ defmodule Pleroma.UserTest do refute User.mutes?(user, muted_user) refute User.muted_notifications?(user, muted_user) - {:ok, user} = User.mute(user, muted_user, false) + {:ok, _user_mute} = User.mute(user, muted_user, false) assert User.mutes?(user, muted_user) refute User.muted_notifications?(user, muted_user) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 17d283954..de8472691 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -611,7 +611,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do activity_three = insert(:note_activity) user = insert(:user) booster = insert(:user) - {:ok, user} = User.mute(user, %User{ap_id: activity_one.data["actor"]}) + + activity_one_actor = User.get_by_ap_id(activity_one.data["actor"]) + {:ok, _user_mute} = User.mute(user, activity_one_actor) activities = ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true}) @@ -632,7 +634,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert Enum.member?(activities, activity_three) assert Enum.member?(activities, activity_one) - {:ok, user} = User.unmute(user, %User{ap_id: activity_one.data["actor"]}) + {:ok, _user_mute} = User.unmute(user, activity_one_actor) activities = ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true}) @@ -641,7 +643,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert Enum.member?(activities, activity_three) assert Enum.member?(activities, activity_one) - {:ok, user} = User.mute(user, %User{ap_id: activity_three.data["actor"]}) + activity_three_actor = User.get_by_ap_id(activity_three.data["actor"]) + {:ok, _user_mute} = User.mute(user, activity_three_actor) {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster) %Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id) activity_three = Activity.get_by_id(activity_three.id) diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index b98d9c8e3..c5ef96bb7 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -868,7 +868,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do user = insert(:user) other_user = insert(:user) - {:ok, user} = User.mute(user, other_user) + {:ok, _user_mute} = User.mute(user, other_user) conn = conn diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs index fa55a7cf9..75b871a43 100644 --- a/test/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/web/mastodon_api/controllers/notification_controller_test.exs @@ -289,7 +289,10 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do assert length(json_response(conn, 200)) == 1 - {:ok, user} = User.mute(user, user2) + {:ok, _user_mute} = User.mute(user, user2) + + # Refreshing to reflect embedded ap id relation fields (remove once removed) + user = refresh_record(user) conn = assign(build_conn(), :user, user) conn = get(conn, "/api/v1/notifications") @@ -310,7 +313,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do assert length(json_response(conn, 200)) == 1 - {:ok, user} = User.mute(user, user2, false) + {:ok, _user_mute} = User.mute(user, user2, false) conn = assign(build_conn(), :user, user) conn = get(conn, "/api/v1/notifications") @@ -333,7 +336,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do assert length(json_response(conn, 200)) == 1 - {:ok, user} = User.mute(user, user2) + {:ok, _user_mute} = User.mute(user, user2) conn = assign(build_conn(), :user, user) conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"}) diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index c34bf7ba9..f8b74553b 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -191,9 +191,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do {:ok, user} = User.follow(user, other_user) {:ok, other_user} = User.follow(other_user, user) {:ok, other_user} = User.subscribe(user, other_user) - {:ok, user} = User.mute(user, other_user, true) + {:ok, _user_mute} = User.mute(user, other_user, true) {:ok, user} = CommonAPI.hide_reblogs(user, other_user) + # Refreshing to reflect embedded ap id relation fields (remove once removed) + user = refresh_record(user) + expected = %{ id: to_string(other_user.id), following: true, diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index d46ecc646..89b146e1e 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -183,7 +183,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do user = insert(:user) other_user = insert(:user) - {:ok, user} = User.mute(user, other_user) + {:ok, _user_mute} = User.mute(user, other_user) {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"}) status = StatusView.render("show.json", %{activity: activity}) @@ -199,7 +199,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do user = insert(:user) other_user = insert(:user) - {:ok, user} = User.mute(user, other_user) + {:ok, _user_mute} = User.mute(user, other_user) {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"}) status = StatusView.render("show.json", %{activity: activity, for: user})