From 546c786ed358798e25b6535c1aee372eab533abc Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 26 Mar 2026 19:53:51 +0300 Subject: [PATCH] [poll-create] Added poll option toggle to extend poll with new answers. --- Telegram/Resources/langs/lang.strings | 2 ++ Telegram/SourceFiles/boxes/create_poll_box.cpp | 16 ++++++++++++++++ Telegram/SourceFiles/data/data_poll.cpp | 8 +++++++- Telegram/SourceFiles/data/data_poll.h | 2 ++ Telegram/SourceFiles/window/window_peer_menu.cpp | 2 ++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index cc934b5221..c9b83ffd3b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -6855,6 +6855,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_polls_create_show_who_voted_about" = "Display voter name on each option."; "lng_polls_create_allow_multiple_answers" = "Allow Multiple Answers"; "lng_polls_create_allow_multiple_answers_about" = "Voters can select more than one option."; +"lng_polls_create_allow_adding_options" = "Allow Adding Options"; +"lng_polls_create_allow_adding_options_about" = "Participants can suggest new options."; "lng_polls_create_allow_revoting" = "Allow Revoting"; "lng_polls_create_allow_revoting_about" = "Voters can change their vote."; "lng_polls_create_shuffle_options" = "Shuffle Options"; diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index cce95c1f0f..693ca76078 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -1108,6 +1108,18 @@ object_ptr CreatePollBox::setupContent() { | rpl::then(state->multipleForceOff.events()), st::detailedSettingsButtonStyle) : nullptr; + const auto addOptions = (!(_disabled & PollData::Flag::OpenAnswers)) + ? AddPollToggleButton( + container, + tr::lng_polls_create_allow_adding_options(), + tr::lng_polls_create_allow_adding_options_about(), + { + .icon = &st::pollBoxFilledPollAddIcon, + .background = &st::settingsIconBg4, + }, + rpl::single(!!(_chosen & PollData::Flag::OpenAnswers)), + st::detailedSettingsButtonStyle) + : nullptr; const auto revoting = AddPollToggleButton( container, tr::lng_polls_create_allow_revoting(), @@ -1160,6 +1172,9 @@ object_ptr CreatePollBox::setupContent() { }, solution->lifetime()); quiz->setToggleLocked(_disabled & PollData::Flag::Quiz); + if (addOptions) { + addOptions->setToggleLocked(_disabled & PollData::Flag::OpenAnswers); + } revoting->setToggleLocked(_disabled & PollData::Flag::RevotingDisabled); shuffle->setToggleLocked(_disabled & PollData::Flag::ShuffleAnswers); if (multiple) { @@ -1235,6 +1250,7 @@ object_ptr CreatePollBox::setupContent() { result.setFlags(Flag(0) | (publicVotes ? Flag::PublicVotes : Flag(0)) | (multiChoice ? Flag::MultiChoice : Flag(0)) + | ((addOptions && addOptions->toggled()) ? Flag::OpenAnswers : Flag(0)) | (!revoting->toggled() ? Flag::RevotingDisabled : Flag(0)) | (shuffle->toggled() ? Flag::ShuffleAnswers : Flag(0)) | (quiz->toggled() ? Flag::Quiz : Flag(0))); diff --git a/Telegram/SourceFiles/data/data_poll.cpp b/Telegram/SourceFiles/data/data_poll.cpp index 18fb9c1e51..13297cc465 100644 --- a/Telegram/SourceFiles/data/data_poll.cpp +++ b/Telegram/SourceFiles/data/data_poll.cpp @@ -78,7 +78,8 @@ bool PollData::applyChanges(const MTPDpoll &poll) { | (poll.is_multiple_choice() ? Flag::MultiChoice : Flag(0)) | (poll.is_quiz() ? Flag::Quiz : Flag(0)) | (poll.is_shuffle_answers() ? Flag::ShuffleAnswers : Flag(0)) - | (poll.is_revoting_disabled() ? Flag::RevotingDisabled : Flag(0)); + | (poll.is_revoting_disabled() ? Flag::RevotingDisabled : Flag(0)) + | (poll.is_open_answers() ? Flag::OpenAnswers : Flag(0)); const auto newCloseDate = poll.vclose_date().value_or_empty(); const auto newClosePeriod = poll.vclose_period().value_or_empty(); auto newAnswers = ranges::views::all( @@ -270,6 +271,10 @@ bool PollData::revotingDisabled() const { return (_flags & Flag::RevotingDisabled); } +bool PollData::openAnswers() const { + return (_flags & Flag::OpenAnswers); +} + MTPPoll PollDataToMTP(not_null poll, bool close) { const auto convert = [&](const PollAnswer &answer) { return MTP_pollAnswer( @@ -295,6 +300,7 @@ MTPPoll PollDataToMTP(not_null poll, bool close) { | (poll->quiz() ? Flag::f_quiz : Flag(0)) | (poll->shuffleAnswers() ? Flag::f_shuffle_answers : Flag(0)) | (poll->revotingDisabled() ? Flag::f_revoting_disabled : Flag(0)) + | (poll->openAnswers() ? Flag::f_open_answers : Flag(0)) | (poll->closePeriod > 0 ? Flag::f_close_period : Flag(0)) | (poll->closeDate > 0 ? Flag::f_close_date : Flag(0)); return MTP_poll( diff --git a/Telegram/SourceFiles/data/data_poll.h b/Telegram/SourceFiles/data/data_poll.h index 23638e54e4..0d020295a0 100644 --- a/Telegram/SourceFiles/data/data_poll.h +++ b/Telegram/SourceFiles/data/data_poll.h @@ -45,6 +45,7 @@ struct PollData { Quiz = 0x08, ShuffleAnswers = 0x10, RevotingDisabled = 0x20, + OpenAnswers = 0x40, }; friend inline constexpr bool is_flag_type(Flag) { return true; }; using Flags = base::flags; @@ -67,6 +68,7 @@ struct PollData { [[nodiscard]] bool quiz() const; [[nodiscard]] bool shuffleAnswers() const; [[nodiscard]] bool revotingDisabled() const; + [[nodiscard]] bool openAnswers() const; PollId id = 0; TextWithEntities question; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 4d22a526a8..92e4d27a64 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -2202,6 +2202,8 @@ void PeerMenuCreatePoll( if (peer->isChannel() && !peer->isMegagroup()) { chosen &= ~PollData::Flag::PublicVotes; disabled |= PollData::Flag::PublicVotes; + chosen &= ~PollData::Flag::OpenAnswers; + disabled |= PollData::Flag::OpenAnswers; } auto starsRequired = peer->session().changes().peerFlagsValue( peer,