X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Factivity.ex;h=a8154859a7f81429eac2b293c2a32cd44f8a34f9;hb=37e406ae36e4b7f922cb46d7873ec584768a721b;hp=46568bb13eb288d6322b145db776e5427aa5e9c8;hpb=7a0046d1271d97d635294ee0cace135d32b141ba;p=akkoma diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 46568bb13..a8154859a 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -1,21 +1,46 @@ defmodule Pleroma.Activity do use Ecto.Schema - alias Pleroma.{Repo, Activity} + alias Pleroma.{Repo, Activity, Notification} import Ecto.Query schema "activities" do field :data, :map + field :local, :boolean, default: true + field :actor, :string + field :recipients, {:array, :string} + has_many :notifications, Notification, on_delete: :delete_all timestamps() end def get_by_ap_id(ap_id) do Repo.one(from activity in Activity, - where: fragment("? @> ?", activity.data, ^%{id: ap_id})) + 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(from activity in Activity, - where: fragment("? @> ?", activity.data, ^%{object: %{id: ap_id}})) + 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