|> fix_context
|> fix_in_reply_to
|> fix_emoji
+ |> fix_tag
end
def fix_in_reply_to(%{"inReplyTo" => in_reply_to_id} = object) when not is_nil(in_reply_to_id) do
|> Map.put("emoji", emoji)
end
+ def fix_tag(object) do
+ tags = (object["tag"] || [])
+ |> Enum.filter(fn (data) -> data["type"] == "Hashtag" and data["name"] end)
+ |> Enum.map(fn (data) -> String.slice(data["name"], 1..-1) end)
+
+ combined = (object["tag"] || []) ++ tags
+
+ object
+ |> Map.put("tag", combined)
+ end
+
# TODO: validate those with a Ecto scheme
# - tags
# - emoji
if object = Object.get_by_ap_id(id), do: {:ok, object}, else: nil
end
+ def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do
+ with false <- String.starts_with?(inReplyTo, "http"),
+ {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do
+ Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo)
+ else
+ _e -> object
+ end
+ end
+ def set_reply_to_uri(obj), do: obj
+
+ # Prepares the object of an outgoing create activity.
def prepare_object(object) do
object
|> set_sensitive
|> add_attributed_to
|> prepare_attachments
|> set_conversation
+ |> set_reply_to_uri
end
@doc