Mastodon API: actually check for poll votes
This commit is contained in:
parent
65db5e9f52
commit
444406167b
|
@ -331,7 +331,7 @@ def render("attachment.json", %{attachment: attachment}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Add tests for this view
|
# TODO: Add tests for this view
|
||||||
def render("poll.json", %{object: object} = _opts) do
|
def render("poll.json", %{object: object} = opts) do
|
||||||
{multiple, options} =
|
{multiple, options} =
|
||||||
case object.data do
|
case object.data do
|
||||||
%{"anyOf" => options} when is_list(options) -> {true, options}
|
%{"anyOf" => options} when is_list(options) -> {true, options}
|
||||||
|
@ -352,6 +352,16 @@ def render("poll.json", %{object: object} = _opts) do
|
||||||
_ -> false
|
_ -> false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
voted =
|
||||||
|
if opts[:for] do
|
||||||
|
existing_votes =
|
||||||
|
Pleroma.Web.ActivityPub.Utils.get_existing_votes(opts[:for].ap_id, object)
|
||||||
|
|
||||||
|
existing_votes != [] or opts[:for].ap_id == object.data["actor"]
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
{options, votes_count} =
|
{options, votes_count} =
|
||||||
Enum.map_reduce(options, 0, fn %{"name" => name} = option, count ->
|
Enum.map_reduce(options, 0, fn %{"name" => name} = option, count ->
|
||||||
current_count = option["replies"]["totalItems"] || 0
|
current_count = option["replies"]["totalItems"] || 0
|
||||||
|
@ -371,8 +381,7 @@ def render("poll.json", %{object: object} = _opts) do
|
||||||
multiple: multiple,
|
multiple: multiple,
|
||||||
votes_count: votes_count,
|
votes_count: votes_count,
|
||||||
options: options,
|
options: options,
|
||||||
# TODO: Actually check for a vote
|
voted: voted,
|
||||||
voted: false,
|
|
||||||
emojis: build_emojis(object.data["emoji"])
|
emojis: build_emojis(object.data["emoji"])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue