Mastodon API Poll view: Fix handling of polls without an end date

This commit is contained in:
rinpatch 2019-09-05 11:58:02 +03:00
commit b312ca3d52
6 changed files with 44 additions and 10 deletions

View file

@ -385,16 +385,27 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
end
if options do
end_time =
(object.data["closed"] || object.data["endTime"])
|> NaiveDateTime.from_iso8601!()
{end_time, expired} =
case object.data["closed"] || object.data["endTime"] do
end_time when is_binary(end_time) ->
end_time =
(object.data["closed"] || object.data["endTime"])
|> NaiveDateTime.from_iso8601!()
expired =
end_time
|> NaiveDateTime.compare(NaiveDateTime.utc_now())
|> case do
:lt -> true
_ -> false
expired =
end_time
|> NaiveDateTime.compare(NaiveDateTime.utc_now())
|> case do
:lt -> true
_ -> false
end
end_time = Utils.to_masto_date(end_time)
{end_time, expired}
_ ->
{nil, false}
end
voted =
@ -421,7 +432,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
# Mastodon uses separate ids for polls, but an object can't have
# more than one poll embedded so object id is fine
id: to_string(object.id),
expires_at: Utils.to_masto_date(end_time),
expires_at: end_time,
expired: expired,
multiple: multiple,
votes_count: votes_count,