From: William Pitcock Date: Mon, 18 Jun 2018 05:23:54 +0000 (+0000) Subject: object: add helper functions to handle various forms of a given object and return... X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=a2009432408dd0e93c3eb9506ff37da788b50895;p=akkoma object: add helper functions to handle various forms of a given object and return a normalized one --- 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 @@ 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)