From e79dcd2bfec23c45e88d51653a542a59508b651f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 18 Oct 2024 15:46:00 +0200 Subject: [PATCH] Fix rejecting duplicated bites MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- lib/pleroma/web/activity_pub/utils.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index f6570cdde9..dac42b7948 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -971,6 +971,7 @@ def fetch_latest_bite( |> maybe_exclude_activity_id(exclude_activity) |> Activity.Queries.by_object_id(bitten_ap_id) |> order_by([activity], fragment("? desc nulls last", activity.id)) + |> exclude_rejected() |> limit(1) |> Repo.one() end @@ -981,4 +982,13 @@ defp maybe_exclude_activity_id(query, %Activity{id: activity_id}) do query |> where([a], a.id != ^activity_id) end + + defp exclude_rejected(query) do + rejected_activities = "Reject" + |> Activity.Queries.by_type() + |> select([a], fragment("?->>'object'", a.data)) + + query + |> where([a], fragment("?->>'id'", a.data) not in subquery(rejected_activities)) + end end