X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Factivity.ex;h=f43b32b565a502c8338b2d9a655577fc906b1a2b;hb=6dfa62800ad6cdcef9e73ecdabe45363c574a528;hp=c4efc62839bc659cccd64591b3ba6770fe1978f5;hpb=8de523c8aec19e999334753b5a982fff00d1f44c;p=akkoma diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index c4efc6283..f43b32b56 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -1,9 +1,44 @@ defmodule Pleroma.Activity do use Ecto.Schema + alias Pleroma.{Repo, Activity, Notification} + import Ecto.Query schema "activities" do field :data, :map + field :local, :boolean, default: true + has_many :notifications, Notification timestamps() end + + def get_by_ap_id(ap_id) do + Repo.one(from activity in Activity, + where: fragment("(?)->>'id' = ?", activity.data, ^to_string(ap_id))) + end + + # TODO: + # Go through these and fix them everywhere. + # Wrong name, only returns create activities + def all_by_object_ap_id_q(ap_id) do + from activity in Activity, + where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)), + where: fragment("(?)->>'type' = 'Create'", activity.data) + end + + # Wrong name, returns all. + def all_non_create_by_object_ap_id_q(ap_id) do + from activity in Activity, + where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)) + end + + # Wrong name plz fix thx + def all_by_object_ap_id(ap_id) do + Repo.all(all_by_object_ap_id_q(ap_id)) + end + + def get_create_activity_by_object_ap_id(ap_id) do + Repo.one(from activity in Activity, + where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)), + where: fragment("(?)->>'type' = 'Create'", activity.data)) + end end