Actual vote count in poll view
authorrinpatch <rinpatch@sdf.org>
Tue, 21 May 2019 11:27:09 +0000 (14:27 +0300)
committerrinpatch <rinpatch@sdf.org>
Tue, 21 May 2019 11:27:09 +0000 (14:27 +0300)
lib/pleroma/web/mastodon_api/views/status_view.ex

index 0df8bb5c2bbe24a2738f3f02f668563e061cc06e..c501c213c3e584c96b54d873f32b5dede5804c7a 100644 (file)
@@ -338,8 +338,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         (object.data["closed"] || object.data["endTime"])
         |> NaiveDateTime.from_iso8601!()
 
-      votes_count = object.data["votes_count"] || 0
-
       expired =
         end_time
         |> NaiveDateTime.compare(NaiveDateTime.utc_now())
@@ -348,12 +346,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
           _ -> false
         end
 
-      options =
-        Enum.map(options, fn %{"name" => name} = option ->
-          %{
-            title: HTML.strip_tags(name),
-            votes_count: option["replies"]["votes_count"] || 0
-          }
+      {options, votes_count} =
+        Enum.map_reduce(options, 0, fn %{"name" => name} = option, count ->
+          current_count = option["replies"]["totalItems"] || 0
+
+          {%{
+             title: HTML.strip_tags(name),
+             votes_count: current_count
+           }, current_count + count}
         end)
 
       %{