diff --git a/lib/pleroma/web/static_fe/static_fe_controller.ex b/lib/pleroma/web/static_fe/static_fe_controller.ex index f1be6cb9b..6f73b575e 100644 --- a/lib/pleroma/web/static_fe/static_fe_controller.ex +++ b/lib/pleroma/web/static_fe/static_fe_controller.ex @@ -190,6 +190,13 @@ defp represent(%Activity{object: %Object{data: data}} = activity, selected) do nil end + total_votes = + if data["oneOf"] do + Enum.sum(for option <- data["oneOf"], do: option["replies"]["totalItems"]) + else + 0 + end + %{ user: User.sanitize_html(user), title: get_title(activity.object), @@ -204,7 +211,9 @@ defp represent(%Activity{object: %Object{data: data}} = activity, selected) do visibility: Visibility.get_visibility(activity.object), reply_to: data["inReplyTo"], reply_to_user: reply_to_user, - edited_at: data["updated"] + edited_at: data["updated"], + poll: data["oneOf"], + total_votes: total_votes } end diff --git a/lib/pleroma/web/static_fe/static_fe_view.ex b/lib/pleroma/web/static_fe/static_fe_view.ex index 92177e3b7..f0c9ddd22 100644 --- a/lib/pleroma/web/static_fe/static_fe_view.ex +++ b/lib/pleroma/web/static_fe/static_fe_view.ex @@ -45,4 +45,14 @@ def open_content? do def get_attachment_name(%{"name" => name}), do: name def get_attachment_name(_), do: "" + + def poll_percentage(count, total_votes) do + case count do + 0 -> + "0%" + + _ -> + Integer.to_string(trunc(count / total_votes * 100)) <> "%" + end + end end diff --git a/lib/pleroma/web/templates/static_fe/static_fe/_notice.html.eex b/lib/pleroma/web/templates/static_fe/static_fe/_notice.html.eex index c11096872..6585e81b6 100644 --- a/lib/pleroma/web/templates/static_fe/static_fe/_notice.html.eex +++ b/lib/pleroma/web/templates/static_fe/static_fe/_notice.html.eex @@ -31,10 +31,10 @@ <%= if @visibility == "public" do %> - + <% else %> <%= if @visibility == "unlisted" do %> - + <% end %> <% end %> @@ -42,7 +42,7 @@ <%= if @reply_to do %>