question_validator: fix for mastodon poll expiration
Mastodon activities do not have a "closed" field, this could be seen on https://pouet.it/users/lanodan_tmp/statuses/104345126997708380 which runs Mastodon 3.1.4 (SDF runs 3.1.2)
This commit is contained in:
parent
47ba796f41
commit
173f69c854
|
@ -71,7 +71,17 @@ def cast_data(data) do
|
||||||
|> changeset(data)
|
|> changeset(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fix(data) do
|
||||||
|
cond do
|
||||||
|
is_binary(data["closed"]) -> data
|
||||||
|
is_binary(data["endTime"]) -> Map.put(data, "closed", data["endTime"])
|
||||||
|
true -> Map.drop(data, ["closed"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def changeset(struct, data) do
|
def changeset(struct, data) do
|
||||||
|
data = fix(data)
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|> cast(data, __schema__(:fields) -- [:anyOf, :oneOf])
|
|> cast(data, __schema__(:fields) -- [:anyOf, :oneOf])
|
||||||
|> cast_embed(:anyOf)
|
|> cast_embed(:anyOf)
|
||||||
|
|
|
@ -40,14 +40,12 @@ def render("show.json", %{object: object} = params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp end_time_and_expired(object) do
|
defp end_time_and_expired(object) do
|
||||||
case object.data["closed"] || object.data["endTime"] do
|
if object.data["closed"] do
|
||||||
end_time when is_binary(end_time) ->
|
end_time = NaiveDateTime.from_iso8601!(object.data["closed"])
|
||||||
end_time = NaiveDateTime.from_iso8601!(end_time)
|
|
||||||
expired = NaiveDateTime.compare(end_time, NaiveDateTime.utc_now()) == :lt
|
expired = NaiveDateTime.compare(end_time, NaiveDateTime.utc_now()) == :lt
|
||||||
|
|
||||||
{Utils.to_masto_date(end_time), expired}
|
{Utils.to_masto_date(end_time), expired}
|
||||||
|
else
|
||||||
_ ->
|
|
||||||
{nil, false}
|
{nil, false}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,7 +49,6 @@
|
||||||
"en": "<p>Why is Tenshi eating a corndog so cute?</p>"
|
"en": "<p>Why is Tenshi eating a corndog so cute?</p>"
|
||||||
},
|
},
|
||||||
"endTime": "2019-05-11T09:03:36Z",
|
"endTime": "2019-05-11T09:03:36Z",
|
||||||
"closed": "2019-05-11T09:03:36Z",
|
|
||||||
"attachment": [],
|
"attachment": [],
|
||||||
"tag": [],
|
"tag": [],
|
||||||
"replies": {
|
"replies": {
|
||||||
|
|
Loading…
Reference in New Issue