Fix polls percent display.

This commit is contained in:
John Preston 2018-12-22 22:48:25 +04:00
parent f2e1d90c74
commit ac2dce4bb1
1 changed files with 7 additions and 5 deletions

View File

@ -231,9 +231,9 @@ ClickHandlerPtr HistoryPoll::createAnswerClickHandler(
} }
void HistoryPoll::updateVotes() const { void HistoryPoll::updateVotes() const {
updateTotalVotes();
_voted = _poll->voted(); _voted = _poll->voted();
updateAnswerVotes(); updateAnswerVotes();
updateTotalVotes();
} }
void HistoryPoll::updateVotesCheckAnimation() const { void HistoryPoll::updateVotesCheckAnimation() const {
@ -268,11 +268,13 @@ void HistoryPoll::updateAnswerVotesFromOriginal(
const PollAnswer &original, const PollAnswer &original,
int totalVotes, int totalVotes,
int maxVotes) const { int maxVotes) const {
if (!_voted && !_closed) { if (canVote()) {
answer.votesPercent.clear(); answer.votesPercent.clear();
} else if (answer.votes != original.votes } else if (answer.votes != original.votes
|| answer.votesPercent.isEmpty()) { || answer.votesPercent.isEmpty()
const auto percent = original.votes * 100 / totalVotes; || std::max(_totalVotes, 1) != totalVotes) {
const auto percent = int(std::round(
original.votes * 100. / totalVotes));
answer.votesPercent = QString::number(percent) + '%'; answer.votesPercent = QString::number(percent) + '%';
answer.votesPercentWidth = st::historyPollPercentFont->width( answer.votesPercentWidth = st::historyPollPercentFont->width(
answer.votesPercent); answer.votesPercent);
@ -286,7 +288,7 @@ void HistoryPoll::updateAnswerVotes() const {
|| _poll->answers.empty()) { || _poll->answers.empty()) {
return; 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( const auto maxVotes = std::max(1, ranges::max_element(
_poll->answers, _poll->answers,
ranges::less(), ranges::less(),