From ac2dce4bb1676ed3d228c11e5c8bfd976b77b8fc Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 22 Dec 2018 22:48:25 +0400 Subject: [PATCH] Fix polls percent display. --- .../SourceFiles/history/media/history_media_poll.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/history/media/history_media_poll.cpp b/Telegram/SourceFiles/history/media/history_media_poll.cpp index 837b0d070..c5d6a75c2 100644 --- a/Telegram/SourceFiles/history/media/history_media_poll.cpp +++ b/Telegram/SourceFiles/history/media/history_media_poll.cpp @@ -231,9 +231,9 @@ ClickHandlerPtr HistoryPoll::createAnswerClickHandler( } void HistoryPoll::updateVotes() const { - updateTotalVotes(); _voted = _poll->voted(); updateAnswerVotes(); + updateTotalVotes(); } void HistoryPoll::updateVotesCheckAnimation() const { @@ -268,11 +268,13 @@ void HistoryPoll::updateAnswerVotesFromOriginal( const PollAnswer &original, int totalVotes, int maxVotes) const { - if (!_voted && !_closed) { + if (canVote()) { answer.votesPercent.clear(); } else if (answer.votes != original.votes - || answer.votesPercent.isEmpty()) { - const auto percent = original.votes * 100 / totalVotes; + || answer.votesPercent.isEmpty() + || std::max(_totalVotes, 1) != totalVotes) { + const auto percent = int(std::round( + original.votes * 100. / totalVotes)); answer.votesPercent = QString::number(percent) + '%'; answer.votesPercentWidth = st::historyPollPercentFont->width( answer.votesPercent); @@ -286,7 +288,7 @@ void HistoryPoll::updateAnswerVotes() const { || _poll->answers.empty()) { return; } - const auto totalVotes = std::max(1, _totalVotes); + const auto totalVotes = std::max(1, _poll->totalVoters); const auto maxVotes = std::max(1, ranges::max_element( _poll->answers, ranges::less(),