mirror of
https://github.com/Qz3rK/tdesktop.git
synced 2026-07-03 14:15:08 +02:00
[poll-view] Prevented bogus poll percentages without total voter count.
This commit is contained in:
@@ -1529,7 +1529,8 @@ struct Poll::Options : public Poll::Part {
|
||||
Answer &answer,
|
||||
const PollAnswer &original,
|
||||
int percent,
|
||||
int maxVotes);
|
||||
int maxVotes,
|
||||
bool showPercent);
|
||||
|
||||
std::vector<Answer> _answers;
|
||||
mutable std::unique_ptr<AnswersAnimation> _answersAnimation;
|
||||
@@ -2823,8 +2824,9 @@ void Poll::Options::updateAnswerVotesFromOriginal(
|
||||
Answer &answer,
|
||||
const PollAnswer &original,
|
||||
int percent,
|
||||
int maxVotes) {
|
||||
if (!_owner->showVotes()) {
|
||||
int maxVotes,
|
||||
bool showPercent) {
|
||||
if (!_owner->showVotes() || !showPercent) {
|
||||
answer.votesPercent = 0;
|
||||
answer.votesPercentString.clear();
|
||||
answer.votesPercentWidth = 0;
|
||||
@@ -2875,7 +2877,11 @@ void Poll::Options::updateAnswerVotes() {
|
||||
|| _owner->_poll->answers.empty()) {
|
||||
return;
|
||||
}
|
||||
const auto totalVotes = std::max(1, _owner->_poll->totalVoters);
|
||||
const auto totalVotes = _owner->_poll->totalVoters;
|
||||
const auto showPercent = (totalVotes > 0)
|
||||
&& ranges::all_of(_owner->_poll->answers, [=](const PollAnswer &a) {
|
||||
return a.votes <= totalVotes;
|
||||
});
|
||||
const auto maxVotes = std::max(1, ranges::max_element(
|
||||
_owner->_poll->answers,
|
||||
ranges::less(),
|
||||
@@ -2893,10 +2899,12 @@ void Poll::Options::updateAnswerVotes() {
|
||||
) | ranges::views::transform(&PollAnswer::votes),
|
||||
ranges::begin(VotesStorage));
|
||||
|
||||
CountNicePercent(
|
||||
gsl::make_span(VotesStorage).subspan(0, count),
|
||||
totalVotes,
|
||||
gsl::make_span(PercentsStorage).subspan(0, count));
|
||||
if (showPercent) {
|
||||
CountNicePercent(
|
||||
gsl::make_span(VotesStorage).subspan(0, count),
|
||||
totalVotes,
|
||||
gsl::make_span(PercentsStorage).subspan(0, count));
|
||||
}
|
||||
|
||||
for (auto &answer : _answers) {
|
||||
const auto i = ranges::find(
|
||||
@@ -2909,7 +2917,8 @@ void Poll::Options::updateAnswerVotes() {
|
||||
answer,
|
||||
*i,
|
||||
PercentsStorage[index],
|
||||
maxVotes);
|
||||
maxVotes,
|
||||
showPercent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user