object: add helper functions to handle various forms of a given object and return...
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 18 Jun 2018 05:23:54 +0000 (05:23 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 18 Jun 2018 05:27:10 +0000 (05:27 +0000)
lib/pleroma/object.ex
lib/pleroma/user.ex

index ff2af4a6fa986cea2d557498ed8c7344e824a87e..1bcff5a7b092f5dbc1db4a23192f2d98b4e5cf99 100644 (file)
@@ -27,6 +27,10 @@ defmodule Pleroma.Object do
     Repo.one(from(object in Object, where: fragment("(?)->>'id' = ?", object.data, ^ap_id)))
   end
 
+  def normalize(obj) when is_map(obj), do: Object.get_by_ap_id(obj["id"])
+  def normalize(ap_id) when is_binary(ap_id), do: Object.get_by_ap_id(ap_id)
+  def normalize(_), do: nil
+
   def get_cached_by_ap_id(ap_id) do
     if Mix.env() == :test do
       get_by_ap_id(ap_id)
index 856f27e1013a160701c0ef7a3991c4cd5e5b66fc..d68aef52ab76e08778ccaa8300d222f6e1beeb43 100644 (file)
@@ -458,7 +458,7 @@ defmodule Pleroma.User do
   end
 
   def get_notified_from_activity(%Activity{recipients: to, data: %{"type" => "Announce"} = data}) do
-    object = Object.get_by_ap_id(data["object"])
+    object = Object.normalize(data["object"])
 
     # ensure that the actor who published the announced object appears only once
     to =