X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Factivity.ex;h=afd09982fcd45211249c0c4cac75f80fefaf65db;hb=d8db39564eb21d9d9b572baae1886af8d0c047d5;hp=9a5e6fc787c5035dcb5d5e5a7a1f5af058fbdfed;hpb=2b21c05105d550d09d85807246be696a1aed4b32;p=akkoma diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 9a5e6fc78..afd09982f 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -6,7 +6,8 @@ defmodule Pleroma.Activity do schema "activities" do field :data, :map field :local, :boolean, default: true - has_many :notifications, Notification + field :actor, :string + has_many :notifications, Notification, on_delete: :delete_all timestamps() end @@ -16,24 +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("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id)) + 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("(?)->>'object' = ?", activity.data, ^to_string(ap_id)) + 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("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id)) - and fragment("(?)->>'type' = 'Create'", activity.data)) + where: fragment("coalesce((?)->'object'->>'id', (?)->>'object') = ?", activity.data, activity.data, ^to_string(ap_id)), + where: fragment("(?)->>'type' = 'Create'", activity.data)) end end