1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Activity.Queries do
7 Contains queries for Activity.
10 import Ecto.Query, only: [from: 2]
12 @type query :: Ecto.Queryable.t() | Activity.t()
14 alias Pleroma.Activity
16 @spec by_ap_id(query, String.t()) :: query
17 def by_ap_id(query \\ Activity, ap_id) do
20 where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id))
24 @spec by_actor(query, String.t()) :: query
25 def by_actor(query \\ Activity, actor) do
28 where: fragment("(?)->>'actor' = ?", activity.data, ^actor)
32 @spec by_object_id(query, String.t() | [String.t()]) :: query
33 def by_object_id(query \\ Activity, object_id)
35 def by_object_id(query, object_ids) when is_list(object_ids) do
40 "coalesce((?)->'object'->>'id', (?)->>'object') = ANY(?)",
48 def by_object_id(query, object_id) when is_binary(object_id) do
49 from(activity in query,
52 "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
60 @spec by_type(query, String.t()) :: query
61 def by_type(query \\ Activity, activity_type) do
64 where: fragment("(?)->>'type' = ?", activity.data, ^activity_type)