X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Factivity.ex;h=afd09982fcd45211249c0c4cac75f80fefaf65db;hb=dffde6631d105949b62c1ff27c22fefcb873b2e8;hp=f48199cae876b8441af760973b5868b1df7d7924;hpb=14a9dd468b1f445fa0fb49ab222d51eaa0e98faf;p=akkoma diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index f48199cae..afd09982f 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -1,11 +1,13 @@ 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 + has_many :notifications, Notification, on_delete: :delete_all timestamps() end @@ -15,13 +17,29 @@ defmodule Pleroma.Activity do 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("? @> ?", activity.data, ^%{type: "Create", object: %{id: ap_id}})) + where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)), + where: fragment("(?)->>'type' = 'Create'", activity.data)) end end