Fix rejecting duplicated bites

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-10-18 15:46:00 +02:00
parent ad0ebe666c
commit e79dcd2bfe

View file

@ -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