From a2009432408dd0e93c3eb9506ff37da788b50895 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 18 Jun 2018 05:23:54 +0000 Subject: [PATCH] object: add helper functions to handle various forms of a given object and return a normalized one --- lib/pleroma/object.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index ff2af4a6f..1bcff5a7b 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -27,6 +27,10 @@ def get_by_ap_id(ap_id) 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)