Added printable representation to PollData.

This commit is contained in:
23rd
2026-03-29 11:27:08 +03:00
parent e66a5a3442
commit bcb447520e
3 changed files with 50 additions and 0 deletions
+37
View File
@@ -368,6 +368,43 @@ bool PollData::creator() const {
return (_flags & Flag::Creator);
}
QString PollData::debugString() const {
auto result = QString();
result += u"Poll #"_q + QString::number(id) + u'\n';
result += u"Q: "_q + question.text + u'\n';
if (quiz()) {
result += u"[Quiz]"_q;
}
if (multiChoice()) {
result += u"[MultiChoice]"_q;
}
if (closed()) {
result += u"[Closed]"_q;
}
if (publicVotes()) {
result += u"[PublicVotes]"_q;
}
if (!result.endsWith(u'\n')) {
result += u'\n';
}
result += u"Total voters: "_q + QString::number(totalVoters) + u'\n';
for (const auto &answer : answers) {
result += u" - "_q + answer.text.text
+ u" ["_q + QString::number(answer.votes) + u" votes"_q;
if (answer.chosen) {
result += u", chosen"_q;
}
if (answer.correct) {
result += u", correct"_q;
}
result += u"]\n"_q;
}
if (!solution.text.isEmpty()) {
result += u"Solution: "_q + solution.text + u'\n';
}
return result;
}
MTPInputMedia PollMediaToMTP(const PollMedia &media) {
if (media.photo) {
return MTP_inputMediaPhoto(
+2
View File
@@ -102,6 +102,8 @@ struct PollData {
[[nodiscard]] bool hideResultsUntilClose() const;
[[nodiscard]] bool creator() const;
[[nodiscard]] QString debugString() const;
PollId id = 0;
TextWithEntities question;
std::vector<PollAnswer> answers;
@@ -52,6 +52,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/crc32hash.h"
#include "base/unixtime.h"
#include "base/timer.h"
#include "base/qt/qt_key_modifiers.h"
#include "main/main_app_config.h"
#include "main/main_session.h"
#include "apiwrap.h"
@@ -2525,6 +2526,11 @@ ClickHandlerPtr Poll::Options::createAnswerClickHandler(
auto result = ClickHandlerPtr();
if (_owner->_flags & PollData::Flag::MultiChoice) {
result = std::make_shared<LambdaClickHandler>(crl::guard(this, [=] {
if (Logs::DebugEnabled() && base::IsCtrlPressed()) {
TextUtilities::SetClipboardText(
TextForMimeData::Simple(_owner->_poll->debugString()));
return;
}
if (_owner->canVote()) {
toggleMultiOption(option);
} else if (_owner->showVotes()) {
@@ -2533,6 +2539,11 @@ ClickHandlerPtr Poll::Options::createAnswerClickHandler(
}));
} else {
result = std::make_shared<LambdaClickHandler>(crl::guard(this, [=] {
if (Logs::DebugEnabled() && base::IsCtrlPressed()) {
TextUtilities::SetClipboardText(
TextForMimeData::Simple(_owner->_poll->debugString()));
return;
}
if (_owner->canVote()) {
_votedFromHere = true;
_owner->history()->session().api().polls().sendVotes(