- query =
- from(
- activity in Activity,
- where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
- # this is to use the index
- where:
- fragment(
- "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
- activity.data,
- activity.data,
- ^id
- ),
- where: fragment("(?)->>'type' = 'Like'", activity.data)
- )
-
- Repo.one(query)
- end
-
- @doc """
- Returns like activities targeting an object
- """
- def get_object_likes(%{data: %{"id" => id}}) do
- query =
- from(
- activity in Activity,
- # this is to use the index
- where:
- fragment(
- "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
- activity.data,
- activity.data,
- ^id
- ),
- where: fragment("(?)->>'type' = 'Like'", activity.data)
- )
-
- Repo.all(query)
+ actor
+ |> Activity.Queries.by_actor()
+ |> Activity.Queries.by_object_id(id)
+ |> Activity.Queries.by_type("Like")
+ |> limit(1)
+ |> Repo.one()