2018-12-18 05:43:11 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
struct PollAnswer {
|
|
|
|
QString text;
|
|
|
|
QByteArray option;
|
|
|
|
int votes = 0;
|
|
|
|
bool chosen = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator==(const PollAnswer &a, const PollAnswer &b) {
|
|
|
|
return (a.text == b.text)
|
|
|
|
&& (a.option == b.option);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const PollAnswer &a, const PollAnswer &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PollData {
|
|
|
|
explicit PollData(PollId id);
|
|
|
|
|
|
|
|
bool applyChanges(const MTPDpoll &poll);
|
|
|
|
bool applyResults(const MTPPollResults &results);
|
2019-02-19 06:57:53 +00:00
|
|
|
void checkResultsReload(not_null<HistoryItem*> item, crl::time now);
|
2018-12-18 05:43:11 +00:00
|
|
|
|
|
|
|
PollAnswer *answerByOption(const QByteArray &option);
|
|
|
|
const PollAnswer *answerByOption(const QByteArray &option) const;
|
|
|
|
|
2018-12-19 11:20:04 +00:00
|
|
|
bool voted() const;
|
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
PollId id = 0;
|
|
|
|
QString question;
|
|
|
|
std::vector<PollAnswer> answers;
|
|
|
|
int totalVoters = 0;
|
|
|
|
bool closed = false;
|
2018-12-22 19:32:04 +00:00
|
|
|
QByteArray sendingVote;
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time lastResultsUpdate = 0;
|
2018-12-18 05:43:11 +00:00
|
|
|
|
2018-12-18 13:56:38 +00:00
|
|
|
int version = 0;
|
|
|
|
|
2018-12-25 14:17:02 +00:00
|
|
|
static constexpr auto kMaxOptions = 10;
|
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
private:
|
|
|
|
bool applyResultToAnswers(
|
|
|
|
const MTPPollAnswerVoters &result,
|
|
|
|
bool isMinResults);
|
|
|
|
|
|
|
|
};
|
2018-12-20 16:02:44 +00:00
|
|
|
|
|
|
|
MTPPoll PollDataToMTP(not_null<const PollData*> poll);
|