Use nil for empty last_status_at value

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2023-07-13 09:23:57 +02:00
parent 7c28e26535
commit ee0984a0c8
2 changed files with 7 additions and 5 deletions

View file

@ -334,21 +334,23 @@ def date_to_asctime(date) do
""
end
def to_masto_date(%NaiveDateTime{} = date) do
def to_masto_date(date, default \\ "")
def to_masto_date(%NaiveDateTime{} = date, _default) do
date
|> NaiveDateTime.to_iso8601()
|> String.replace(~r/(\.\d+)?$/, ".000Z", global: false)
end
def to_masto_date(date) when is_binary(date) do
def to_masto_date(date, default) when is_binary(date) do
with {:ok, date} <- NaiveDateTime.from_iso8601(date) do
to_masto_date(date)
to_masto_date(date, default)
else
_ -> ""
end
end
def to_masto_date(_), do: ""
def to_masto_date(_, default), do: default
defp shortname(name) do
with max_length when max_length > 0 <-

View file

@ -296,7 +296,7 @@ defp do_render("show.json", %{user: user} = opts) do
actor_type: user.actor_type
}
},
last_status_at: Utils.to_masto_date(user.last_status_at),
last_status_at: Utils.to_masto_date(user.last_status_at, nil),
# Pleroma extensions
# Note: it's insecure to output :email but fully-qualified nickname may serve as safe stub