import Ecto.Query
@type t :: %__MODULE__{}
+ @primary_key {:id, Pleroma.FlakeId, autogenerate: true}
# https://github.com/tootsuite/mastodon/blob/master/app/models/notification.rb#L19
@mastodon_notification_types %{
)
end
- def create_by_object_ap_id(ap_id) do
+ def get_by_id(id) do
+ Repo.get(Activity, id)
+ end
+
+ def by_object_ap_id(ap_id) do
from(
activity in Activity,
where:
activity.data,
activity.data,
^to_string(ap_id)
- ),
- where: fragment("(?)->>'type' = 'Create'", activity.data)
+ )
)
end
- def by_object_ap_id(ap_id) do
+ def create_by_object_ap_id(ap_ids) when is_list(ap_ids) do
from(
activity in Activity,
where:
fragment(
- "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
+ "coalesce((?)->'object'->>'id', (?)->>'object') = ANY(?)",
activity.data,
activity.data,
- ^to_string(ap_id)
- )
+ ^ap_ids
+ ),
+ where: fragment("(?)->>'type' = 'Create'", activity.data)
)
end
- def create_by_object_ap_id(ap_ids) when is_list(ap_ids) do
+ def create_by_object_ap_id(ap_id) do
from(
activity in Activity,
where:
fragment(
- "coalesce((?)->'object'->>'id', (?)->>'object') = ANY(?)",
+ "coalesce((?)->'object'->>'id', (?)->>'object') = ?",
activity.data,
activity.data,
- ^ap_ids
+ ^to_string(ap_id)
),
where: fragment("(?)->>'type' = 'Create'", activity.data)
)
Repo.all(create_by_object_ap_id(ap_id))
end
- def get_create_activity_by_object_ap_id(ap_id) when is_binary(ap_id) do
+ def get_create_by_object_ap_id(ap_id) when is_binary(ap_id) do
create_by_object_ap_id(ap_id)
|> Repo.one()
end
- def get_create_activity_by_object_ap_id(_), do: nil
+ def get_create_by_object_ap_id(_), do: nil
def normalize(obj) when is_map(obj), do: Activity.get_by_ap_id(obj["id"])
def normalize(ap_id) when is_binary(ap_id), do: Activity.get_by_ap_id(ap_id)
def normalize(_), do: nil
def get_in_reply_to_activity(%Activity{data: %{"object" => %{"inReplyTo" => ap_id}}}) do
- get_create_activity_by_object_ap_id(ap_id)
+ get_create_by_object_ap_id(ap_id)
end
def get_in_reply_to_activity(_), do: nil