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
|
|
|
|
|
2020-01-09 17:24:54 +00:00
|
|
|
namespace Data {
|
|
|
|
class Session;
|
|
|
|
} // namespace Data
|
|
|
|
|
2020-06-08 08:03:45 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
struct PollAnswer {
|
|
|
|
QString text;
|
|
|
|
QByteArray option;
|
|
|
|
int votes = 0;
|
|
|
|
bool chosen = false;
|
2020-01-09 14:13:35 +00:00
|
|
|
bool correct = false;
|
2018-12-18 05:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
2020-01-09 17:24:54 +00:00
|
|
|
PollData(not_null<Data::Session*> owner, PollId id);
|
2018-12-18 05:43:11 +00:00
|
|
|
|
2020-06-08 08:03:45 +00:00
|
|
|
[[nodiscard]] Data::Session &owner() const;
|
|
|
|
[[nodiscard]] Main::Session &session() const;
|
|
|
|
|
2020-01-09 14:13:35 +00:00
|
|
|
enum class Flag {
|
|
|
|
Closed = 0x01,
|
|
|
|
PublicVotes = 0x02,
|
|
|
|
MultiChoice = 0x04,
|
|
|
|
Quiz = 0x08,
|
|
|
|
};
|
|
|
|
friend inline constexpr bool is_flag_type(Flag) { return true; };
|
|
|
|
using Flags = base::flags<Flag>;
|
|
|
|
|
2020-04-07 12:10:34 +00:00
|
|
|
bool closeByTimer();
|
2018-12-18 05:43:11 +00:00
|
|
|
bool applyChanges(const MTPDpoll &poll);
|
|
|
|
bool applyResults(const MTPPollResults &results);
|
2021-10-20 19:56:10 +00:00
|
|
|
[[nodiscard]] bool checkResultsReload(crl::time now);
|
2018-12-18 05:43:11 +00:00
|
|
|
|
2020-01-09 14:13:35 +00:00
|
|
|
[[nodiscard]] PollAnswer *answerByOption(const QByteArray &option);
|
|
|
|
[[nodiscard]] const PollAnswer *answerByOption(
|
|
|
|
const QByteArray &option) const;
|
2018-12-18 05:43:11 +00:00
|
|
|
|
2020-01-13 10:49:18 +00:00
|
|
|
void setFlags(Flags flags);
|
2020-01-09 14:13:35 +00:00
|
|
|
[[nodiscard]] Flags flags() const;
|
|
|
|
[[nodiscard]] bool voted() const;
|
|
|
|
[[nodiscard]] bool closed() const;
|
|
|
|
[[nodiscard]] bool publicVotes() const;
|
|
|
|
[[nodiscard]] bool multiChoice() const;
|
|
|
|
[[nodiscard]] bool quiz() const;
|
2018-12-19 11:20:04 +00:00
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
PollId id = 0;
|
|
|
|
QString question;
|
|
|
|
std::vector<PollAnswer> answers;
|
2023-04-28 13:43:57 +00:00
|
|
|
std::vector<not_null<PeerData*>> recentVoters;
|
2020-01-10 12:47:36 +00:00
|
|
|
std::vector<QByteArray> sendingVotes;
|
2020-04-06 14:55:31 +00:00
|
|
|
TextWithEntities solution;
|
2020-04-07 12:10:34 +00:00
|
|
|
TimeId closePeriod = 0;
|
|
|
|
TimeId closeDate = 0;
|
2020-04-06 14:55:31 +00:00
|
|
|
int totalVoters = 0;
|
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);
|
|
|
|
|
2020-04-13 08:27:53 +00:00
|
|
|
const not_null<Data::Session*> _owner;
|
2020-01-09 14:13:35 +00:00
|
|
|
Flags _flags = Flags();
|
2020-04-13 08:27:53 +00:00
|
|
|
crl::time _lastResultsUpdate = 0; // < 0 means force reload.
|
2020-01-09 14:13:35 +00:00
|
|
|
|
2018-12-18 05:43:11 +00:00
|
|
|
};
|
2018-12-20 16:02:44 +00:00
|
|
|
|
2020-04-06 14:55:31 +00:00
|
|
|
[[nodiscard]] MTPPoll PollDataToMTP(
|
|
|
|
not_null<const PollData*> poll,
|
|
|
|
bool close = false);
|
|
|
|
[[nodiscard]] MTPInputMedia PollDataToInputMedia(
|
|
|
|
not_null<const PollData*> poll,
|
|
|
|
bool close = false);
|