projects
/
akkoma
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
65db5e9
)
Mastodon API: actually check for poll votes
author
rinpatch
<rinpatch@sdf.org>
Sat, 1 Jun 2019 18:41:23 +0000
(21:41 +0300)
committer
rinpatch
<rinpatch@sdf.org>
Sat, 1 Jun 2019 18:41:23 +0000
(21:41 +0300)
lib/pleroma/web/mastodon_api/views/status_view.ex
patch
|
blob
|
history
diff --git
a/lib/pleroma/web/mastodon_api/views/status_view.ex
b/lib/pleroma/web/mastodon_api/views/status_view.ex
index 5bf4a6ba2bc6b40cf38a6d491938afbaa0d5a2b0..7eea0122b6727294f64e4f3e9e21ff1f92dffd09 100644
(file)
--- 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
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}
{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
_ -> 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
{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,
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
emojis: build_emojis(object.data["emoji"])
}
else