end
# TODO: Add tests for this view
- def render("poll.json", %{object: object} = opts) do
+ def render("poll.json", %{object: object} = _opts) do
{multiple, options} =
case object.data do
%{"anyOf" => options} when is_list(options) -> {true, options}
(object.data["closed"] || object.data["endTime"])
|> NaiveDateTime.from_iso8601!()
- votes_count = object.data["votes_count"] || 0
-
expired =
end_time
|> NaiveDateTime.compare(NaiveDateTime.utc_now())
_ -> false
end
- options =
- Enum.map(options, fn %{"name" => name} = option ->
- name =
- HTML.filter_tags(
- name,
- User.html_filter_policy(opts[:for])
- )
+ {options, votes_count} =
+ Enum.map_reduce(options, 0, fn %{"name" => name} = option, count ->
+ current_count = option["replies"]["totalItems"] || 0
- %{title: name, votes_count: option["replies"]["votes_count"] || 0}
+ {%{
+ title: HTML.strip_tags(name),
+ votes_count: current_count
+ }, current_count + count}
end)
%{
multiple: multiple,
votes_count: votes_count,
options: options,
+ # TODO: Actually check for a vote
voted: false,
emojis: build_emojis(object.data["emoji"])
}