Make auth tokens usable once and expire them.
[akkoma] / lib / pleroma / activity.ex
index d77c8899749a7dd16e568829e3a77340392afa31..f226c4c5f351d797a9eac90bc835645c230c10bd 100644 (file)
@@ -12,16 +12,27 @@ defmodule Pleroma.Activity do
 
   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
+
+  # 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))
+  end
+
+  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))
   end
 
   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("(?)->'object'->>'id' = ?", activity.data, ^to_string(ap_id))
+             and fragment("(?)->>'type' = 'Create'", activity.data))
   end
 end