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>
Wed, 27 Jun 2018 13:06:52 +0000 (13:06 +0000)
lib/pleroma/object.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)