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