+
+ def get_existing_votes(actor, %{data: %{"id" => id}}) do
+ query =
+ from(
+ [activity, object: object] in Activity.with_preloaded_object(Activity),
+ where: fragment("(?)->>'type' = 'Create'", activity.data),
+ where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
+ where:
+ fragment(
+ "(?)->>'inReplyTo' = ?",
+ object.data,
+ ^to_string(id)
+ ),
+ where: fragment("(?)->>'type' = 'Answer'", object.data)
+ )
+
+ Repo.all(query)
+ end