aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2019-06-01 21:41:23 +0300
committerrinpatch <rinpatch@sdf.org>2019-06-01 21:41:23 +0300
commit444406167b050524efb016cfee78636f7f6828ca (patch)
tree583febe6f4d8b8503febbea6355e034c8f1cc9b3 /lib
parent65db5e9f528a3f8d8b3c81953fd160a6744dfffd (diff)
downloadpleroma-444406167b050524efb016cfee78636f7f6828ca.tar.gz
Mastodon API: actually check for poll votes
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 5bf4a6ba2..7eea0122b 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -331,7 +331,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
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}
@@ -352,6 +352,16 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
_ -> false
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} =
Enum.map_reduce(options, 0, fn %{"name" => name} = option, count ->
current_count = option["replies"]["totalItems"] || 0
@@ -371,8 +381,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
multiple: multiple,
votes_count: votes_count,
options: options,
- # TODO: Actually check for a vote
- voted: false,
+ voted: voted,
emojis: build_emojis(object.data["emoji"])
}
else