diff --git a/Telegram/SourceFiles/api/api_bot.cpp b/Telegram/SourceFiles/api/api_bot.cpp index 8265435ec4..236eafad9b 100644 --- a/Telegram/SourceFiles/api/api_bot.cpp +++ b/Telegram/SourceFiles/api/api_bot.cpp @@ -394,7 +394,7 @@ void ActivateBotCommand(ClickHandlerContext context, int row, int column) { case ButtonType::RequestPoll: { HideSingleUseKeyboard(controller, item); - auto chosen = PollData::Flags(); + auto chosen = kDefaultPollCreateFlags; auto disabled = PollData::Flags(); if (!button->data.isEmpty()) { disabled |= PollData::Flag::Quiz; diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 80c27839f8..083388a6e9 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -2752,11 +2752,19 @@ object_ptr CreatePollBox::setupContent() { *handled = true; }, solution->lifetime()); - const auto updateQuizDependentLocks = [=](bool checked) { + const auto updateAddOptionsLocked = [=] { if (addOptions) { - addOptions->setToggleLocked( - (_disabled & PollData::Flag::OpenAnswers) || checked); + const auto locked = (_disabled & PollData::Flag::OpenAnswers) + || quiz->toggled() + || (showWhoVoted && !showWhoVoted->toggled()); + addOptions->setToggleLocked(locked); + if (locked) { + state->addOptionsForceOff.fire(false); + } } + }; + const auto updateQuizDependentLocks = [=](bool checked) { + updateAddOptionsLocked(); revoting->setToggleLocked( (_disabled & PollData::Flag::RevotingDisabled) || checked); }; @@ -2788,19 +2796,11 @@ object_ptr CreatePollBox::setupContent() { }, multiple->lifetime()); if (addOptions && showWhoVoted) { - const auto updateShowWhoVotedLock = [=](bool openAnswers) { - showWhoVoted->setToggleLocked( - (_disabled & PollData::Flag::PublicVotes) - || openAnswers); - if (openAnswers) { - state->showWhoVotedForceOn.fire(true); - } - }; - updateShowWhoVotedLock(addOptions->toggled()); - addOptions->toggledChanges( - ) | rpl::on_next([=](bool checked) { - updateShowWhoVotedLock(checked); - }, addOptions->lifetime()); + updateAddOptionsLocked(); + showWhoVoted->toggledChanges( + ) | rpl::on_next([=](bool) { + updateAddOptionsLocked(); + }, showWhoVoted->lifetime()); } const auto isValidQuestion = [=] { diff --git a/Telegram/SourceFiles/data/data_poll.h b/Telegram/SourceFiles/data/data_poll.h index 8dc87b4797..03760f8771 100644 --- a/Telegram/SourceFiles/data/data_poll.h +++ b/Telegram/SourceFiles/data/data_poll.h @@ -131,6 +131,11 @@ private: }; +inline constexpr auto kDefaultPollCreateFlags = PollData::Flag::PublicVotes + | PollData::Flag::MultiChoice + | PollData::Flag::OpenAnswers + | PollData::Flag::ShuffleAnswers; + [[nodiscard]] QByteArray PollOptionFromLink(const QString &value); [[nodiscard]] QString PollOptionToLink(const QByteArray &option); diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 66b2862e3d..9df6493781 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -2751,14 +2751,14 @@ std::unique_ptr MakeAttachBotsMenu( || action.history->peer->starsPerMessageChecked()) ? SendMenu::Type::SilentOnly : SendMenu::Type::Scheduled; - const auto flag = PollData::Flags(); + const auto chosen = kDefaultPollCreateFlags; Window::PeerMenuCreatePoll( controller, peer, action.replyTo, action.options.suggest, - flag, - flag, + chosen, + PollData::Flags(), source, { sendMenuType }); }, &st::menuIconCreatePoll); diff --git a/Telegram/SourceFiles/settings/detailed_settings_button.cpp b/Telegram/SourceFiles/settings/detailed_settings_button.cpp index 353acb565a..ec904543e4 100644 --- a/Telegram/SourceFiles/settings/detailed_settings_button.cpp +++ b/Telegram/SourceFiles/settings/detailed_settings_button.cpp @@ -43,7 +43,9 @@ DetailedSettingsButton::DetailedSettingsButton( false, [this] { rtlupdate(toggleRect()); }); addClickHandler([=] { - _toggle->setChecked(!_toggle->checked(), anim::type::normal); + if (!_toggleLocked) { + _toggle->setChecked(!_toggle->checked(), anim::type::normal); + } }); std::move( toggled @@ -88,6 +90,7 @@ DetailedSettingsButton::clickAreaEvents() const { } void DetailedSettingsButton::setToggleLocked(bool locked) { + _toggleLocked = locked; _toggle->setLocked(locked); } diff --git a/Telegram/SourceFiles/settings/detailed_settings_button.h b/Telegram/SourceFiles/settings/detailed_settings_button.h index 76b070fa3d..f2854ed478 100644 --- a/Telegram/SourceFiles/settings/detailed_settings_button.h +++ b/Telegram/SourceFiles/settings/detailed_settings_button.h @@ -64,6 +64,7 @@ private: int _descriptionWidth = 0; int _descriptionTop = 0; int _descriptionHeight = 0; + bool _toggleLocked = false; }; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index d3ceb9094c..1b7f0aff11 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -1271,17 +1271,17 @@ void Filler::addCreatePoll() { || _peer->starsPerMessageChecked()) ? SendMenu::Type::SilentOnly : SendMenu::Type::Scheduled; - const auto flag = PollData::Flags(); const auto replyTo = _request.currentReplyTo; const auto suggest = _request.currentSuggest; + const auto chosen = kDefaultPollCreateFlags; auto callback = [=] { PeerMenuCreatePoll( controller, peer, replyTo, suggest, - flag, - flag, + chosen, + PollData::Flags(), source, { sendMenuType }); }; diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index 48910a4824..8664c91dbb 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -123,7 +123,7 @@ void PeerMenuCreatePoll( not_null peer, FullReplyTo replyTo = FullReplyTo(), SuggestOptions suggest = SuggestOptions(), - PollData::Flags chosen = PollData::Flags(), + PollData::Flags chosen = kDefaultPollCreateFlags, PollData::Flags disabled = PollData::Flags(), Api::SendType sendType = Api::SendType::Normal, SendMenu::Details sendMenuDetails = SendMenu::Details());