X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fcommon_api%2Futils.ex;h=54918d13c832939998478b45c4c069e1ef64b975;hb=62e22eeff23b8841e3cdc7e4a4ee6ef29b612aca;hp=22594be4605f24fb81b3166f1b002e9aa1df4c15;hpb=063cc61fc11cd80981d0e23e6d0dfa778cc91bbf;p=akkoma diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 22594be46..54918d13c 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -230,12 +230,13 @@ defmodule Pleroma.Web.CommonAPI.Utils do end end - def make_context(_, %Participation{} = participation) do + def make_context(%{in_reply_to_conversation: %Participation{} = participation}) do Repo.preload(participation, :conversation).conversation.ap_id end - def make_context(%Activity{data: %{"context" => context}}, _), do: context - def make_context(_, _), do: Utils.generate_context_id() + def make_context(%{in_reply_to: %Activity{data: %{"context" => context}}}), do: context + def make_context(%{quote: %Activity{data: %{"context" => context}}}), do: context + def make_context(_), do: Utils.generate_context_id() def maybe_add_attachments(parsed, _attachments, false = _no_links), do: parsed @@ -288,7 +289,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do def format_input(text, "text/x.misskeymarkdown", options) do text - |> Formatter.markdown_to_html() + |> Formatter.markdown_to_html(%{breaks: true}) |> MfmParser.Parser.parse() |> MfmParser.Encoder.to_html() |> Formatter.linkify(options) @@ -327,20 +328,27 @@ defmodule Pleroma.Web.CommonAPI.Utils do end def to_masto_date(%NaiveDateTime{} = date) do - date - |> NaiveDateTime.to_iso8601() - |> String.replace(~r/(\.\d+)?$/, ".000Z", global: false) + # NOTE: Elixir’s ISO 8601 format is a superset of the real standard + # It supports negative years for example. + # ISO8601 only supports years before 1583 with mutual agreement + if date.year < 1583 do + "1970-01-01T00:00:00Z" + else + date + |> NaiveDateTime.to_iso8601() + |> String.replace(~r/(\.\d+)?$/, ".000Z", global: false) + end end def to_masto_date(date) when is_binary(date) do with {:ok, date} <- NaiveDateTime.from_iso8601(date) do to_masto_date(date) else - _ -> "" + _ -> "1970-01-01T00:00:00Z" end end - def to_masto_date(_), do: "" + def to_masto_date(_), do: "1970-01-01T00:00:00Z" defp shortname(name) do with max_length when max_length > 0 <-