mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-06 03:42:56 +00:00
Added poll stats action and dialog with API-backed chart loading.
This commit is contained in:
@@ -188,6 +188,21 @@ bool PollData::applyResults(const MTPPollResults &results) {
|
||||
const auto newTotalVoters
|
||||
= results.vtotal_voters().value_or(totalVoters);
|
||||
auto changed = (newTotalVoters != totalVoters);
|
||||
const auto setCanViewStats = [&](bool value) {
|
||||
const auto previous = (_flags & Flag::CanViewStats);
|
||||
if (previous == value) {
|
||||
return;
|
||||
}
|
||||
if (value) {
|
||||
_flags |= Flag::CanViewStats;
|
||||
} else {
|
||||
_flags &= ~Flag::CanViewStats;
|
||||
}
|
||||
changed = true;
|
||||
};
|
||||
if (!results.is_min() || results.is_can_view_stats()) {
|
||||
setCanViewStats(results.is_can_view_stats());
|
||||
}
|
||||
if (const auto list = results.vresults()) {
|
||||
for (const auto &result : list->v) {
|
||||
if (applyResultToAnswers(result, results.is_min())) {
|
||||
@@ -382,6 +397,10 @@ bool PollData::subscribersOnly() const {
|
||||
return (_flags & Flag::SubscribersOnly);
|
||||
}
|
||||
|
||||
bool PollData::canViewStats() const {
|
||||
return (_flags & Flag::CanViewStats);
|
||||
}
|
||||
|
||||
QString PollData::debugString() const {
|
||||
auto result = QString();
|
||||
result += u"Poll #"_q + QString::number(id) + u'\n';
|
||||
@@ -401,6 +420,9 @@ QString PollData::debugString() const {
|
||||
if (subscribersOnly()) {
|
||||
result += u"[SubscribersOnly]"_q;
|
||||
}
|
||||
if (canViewStats()) {
|
||||
result += u"[CanViewStats]"_q;
|
||||
}
|
||||
if (!result.endsWith(u'\n')) {
|
||||
result += u'\n';
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ struct PollData {
|
||||
HideResultsUntilClose = 0x080,
|
||||
Creator = 0x100,
|
||||
SubscribersOnly = 0x200,
|
||||
CanViewStats = 0x400,
|
||||
};
|
||||
friend inline constexpr bool is_flag_type(Flag) { return true; };
|
||||
using Flags = base::flags<Flag>;
|
||||
@@ -103,6 +104,7 @@ struct PollData {
|
||||
[[nodiscard]] bool hideResultsUntilClose() const;
|
||||
[[nodiscard]] bool creator() const;
|
||||
[[nodiscard]] bool subscribersOnly() const;
|
||||
[[nodiscard]] bool canViewStats() const;
|
||||
|
||||
[[nodiscard]] QString debugString() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user