From 8fe29bf5d2f6899f646c2b76744e1bfeeb84c5eb Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Mon, 17 Jul 2023 17:53:03 +0100 Subject: [PATCH] Exclude deactivated users from emoji reaction lists --- .../controllers/emoji_reaction_controller.ex | 13 ++++++++++++- .../controllers/status_controller_test.exs | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex index 0933363a6..e762fcad8 100644 --- a/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex @@ -41,6 +41,17 @@ def index(%{assigns: %{user: user}} = conn, %{id: activity_id} = params) do end end + defp filter_allowed_user_by_ap_id(ap_ids, excluded_ap_ids) do + Enum.reject(ap_ids, fn ap_id -> + with false <- ap_id in excluded_ap_ids, + %{is_active: true} <- User.get_cached_by_ap_id(ap_id) do + false + else + _ -> true + end + end) + end + def filter_allowed_users(reactions, user, with_muted) do exclude_ap_ids = if is_nil(user) do @@ -51,7 +62,7 @@ def filter_allowed_users(reactions, user, with_muted) do end filter_emoji = fn emoji, users, url -> - case Enum.reject(users, &(&1 in exclude_ap_ids)) do + case filter_allowed_user_by_ap_id(users, exclude_ap_ids) do [] -> nil users -> {emoji, users, url} 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 6f04975b8..30be34007 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -1960,6 +1960,10 @@ test "index" do {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅") User.mute(user, other_user) + deactivated_user = insert(:user) + {:ok, _} = CommonAPI.react_with_emoji(activity.id, deactivated_user, "🎅") + User.set_activation(deactivated_user, false) + result = conn |> get("/api/v1/statuses/?ids[]=#{activity.id}") @@ -1967,6 +1971,7 @@ test "index" do assert [ %{ + "emoji_reactions" => [], "pleroma" => %{ "emoji_reactions" => [] }