Correctly show scheduled polls.

This commit is contained in:
John Preston 2019-08-20 15:05:51 +03:00
parent f690f93f32
commit 8eac2dcb78
2 changed files with 20 additions and 14 deletions

View File

@ -213,8 +213,12 @@ QSize Poll::countOptimalSize() {
return { maxWidth, minHeight }; return { maxWidth, minHeight };
} }
bool Poll::showVotes() const {
return _voted || _closed;
}
bool Poll::canVote() const { bool Poll::canVote() const {
return !_voted && !_closed; return !showVotes() && IsServerMsgId(_parent->data()->id);
} }
int Poll::countAnswerTop( int Poll::countAnswerTop(
@ -395,7 +399,7 @@ void Poll::updateAnswerVotesFromOriginal(
const PollAnswer &original, const PollAnswer &original,
int percent, int percent,
int maxVotes) { int maxVotes) {
if (canVote()) { if (!showVotes()) {
answer.votesPercent = 0; answer.votesPercent = 0;
answer.votesPercentString.clear(); answer.votesPercentString.clear();
answer.votesPercentWidth = 0; answer.votesPercentWidth = 0;
@ -590,7 +594,7 @@ int Poll::paintAnswer(
selection); selection);
p.setOpacity(1.); p.setOpacity(1.);
} }
} else if (canVote()) { } else if (!showVotes()) {
paintRadio(p, answer, left, top, selection); paintRadio(p, answer, left, top, selection);
} else { } else {
paintPercent( paintPercent(
@ -730,14 +734,14 @@ void Poll::saveStateInAnimation() const {
if (_answersAnimation) { if (_answersAnimation) {
return; return;
} }
const auto can = canVote(); const auto show = showVotes();
_answersAnimation = std::make_unique<AnswersAnimation>(); _answersAnimation = std::make_unique<AnswersAnimation>();
_answersAnimation->data.reserve(_answers.size()); _answersAnimation->data.reserve(_answers.size());
const auto convert = [&](const Answer &answer) { const auto convert = [&](const Answer &answer) {
auto result = AnswerAnimation(); auto result = AnswerAnimation();
result.percent = can ? 0. : float64(answer.votesPercent); result.percent = show ? float64(answer.votesPercent) : 0.;
result.filling = can ? 0. : answer.filling; result.filling = show ? answer.filling : 0.;
result.opacity = can ? 0. : 1.; result.opacity = show ? 1. : 0.;
return result; return result;
}; };
ranges::transform( ranges::transform(
@ -751,7 +755,7 @@ bool Poll::checkAnimationStart() const {
// Skip initial changes. // Skip initial changes.
return false; return false;
} }
const auto result = (canVote() != (!_poll->voted() && !_poll->closed)) const auto result = (showVotes() != (_poll->voted() || _poll->closed))
|| answerVotesChanged(); || answerVotesChanged();
if (result) { if (result) {
saveStateInAnimation(); saveStateInAnimation();
@ -764,12 +768,12 @@ void Poll::startAnswersAnimation() const {
return; return;
} }
const auto can = canVote(); const auto show = showVotes();
auto &&both = ranges::view::zip(_answers, _answersAnimation->data); auto &&both = ranges::view::zip(_answers, _answersAnimation->data);
for (auto &&[answer, data] : both) { for (auto &&[answer, data] : both) {
data.percent.start(can ? 0. : float64(answer.votesPercent)); data.percent.start(show ? float64(answer.votesPercent) : 0.);
data.filling.start(can ? 0. : answer.filling); data.filling.start(show ? answer.filling : 0.);
data.opacity.start(can ? 0. : 1.); data.opacity.start(show ? 1. : 0.);
} }
_answersAnimation->progress.start( _answersAnimation->progress.start(
[=] { history()->owner().requestViewRepaint(_parent); }, [=] { history()->owner().requestViewRepaint(_parent); },
@ -785,6 +789,7 @@ TextState Poll::textState(QPoint point, StateRequest request) const {
} }
const auto can = canVote(); const auto can = canVote();
const auto show = showVotes();
const auto padding = st::msgPadding; const auto padding = st::msgPadding;
auto paintw = width(); auto paintw = width();
auto tshift = st::historyPollQuestionTop; auto tshift = st::historyPollQuestionTop;
@ -804,7 +809,7 @@ TextState Poll::textState(QPoint point, StateRequest request) const {
if (can) { if (can) {
_lastLinkPoint = point; _lastLinkPoint = point;
result.link = answer.handler; result.link = answer.handler;
} else { } else if (show) {
result.customTooltip = true; result.customTooltip = true;
using Flag = Ui::Text::StateRequest::Flag; using Flag = Ui::Text::StateRequest::Flag;
if (request.flags & Flag::LookupCustomTooltip) { if (request.flags & Flag::LookupCustomTooltip) {

View File

@ -51,7 +51,8 @@ private:
QSize countOptimalSize() override; QSize countOptimalSize() override;
QSize countCurrentSize(int newWidth) override; QSize countCurrentSize(int newWidth) override;
bool canVote() const; [[nodiscard]] bool showVotes() const;
[[nodiscard]] bool canVote() const;
[[nodiscard]] int countAnswerTop( [[nodiscard]] int countAnswerTop(
const Answer &answer, const Answer &answer,