X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Factivity.ex;h=c7502981e31be64eac7e478750537dc772280ea4;hb=9e6ae447294d055af6add2efa9aca0024a252fe1;hp=40e14005b07d4d50ed64ea112c041924058af4a4;hpb=b76001ded34314b30da2fca94063fcecb0bed90f;p=akkoma diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 40e14005b..c7502981e 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -1,28 +1,79 @@ 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(: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("(?)->>'id' = ?", activity.data, ^to_string(ap_id))) + 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(from activity in Activity, - where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))) + Repo.all(all_by_object_ap_id_q(ap_id)) + end + + def create_activity_by_object_id_query(ap_ids) do + from( + activity in Activity, + where: + fragment( + "coalesce((?)->'object'->>'id', (?)->>'object') = ANY(?)", + activity.data, + activity.data, + ^ap_ids + ), + where: fragment("(?)->>'type' = 'Create'", activity.data) + ) end def get_create_activity_by_object_ap_id(ap_id) do - Repo.one(from activity in Activity, - where: fragment("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id)) - and fragment("(?)->>'type' = 'Create'", activity.data)) + create_activity_by_object_id_query([ap_id]) + |> Repo.one() end end