diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 1f5137ebf..2ac6a8fb7 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -1059,19 +1059,19 @@ object_ptr CreatePollBox::setupContent() { *error &= ~Error::Solution; } }; - const auto showError = [=](const QString &text) { - Ui::Toast::Show(text); + const auto showError = [](tr::phrase<> text) { + Ui::Toast::Show(text(tr::now)); }; const auto send = [=](Api::SendOptions sendOptions) { collectError(); if (*error & Error::Question) { - showError(tr::lng_polls_choose_question(tr::now)); + showError(tr::lng_polls_choose_question); question->setFocus(); } else if (*error & Error::Options) { - showError(tr::lng_polls_choose_answers(tr::now)); + showError(tr::lng_polls_choose_answers); options->focusFirst(); } else if (*error & Error::Correct) { - showError(tr::lng_polls_choose_correct(tr::now)); + showError(tr::lng_polls_choose_correct); } else if (*error & Error::Solution) { solution->showError(); } else if (!*error) { @@ -1079,9 +1079,7 @@ object_ptr CreatePollBox::setupContent() { } }; const auto sendSilent = [=] { - auto options = Api::SendOptions(); - options.silent = true; - send(options); + send({ .silent = true }); }; const auto sendScheduled = [=] { Ui::show( @@ -1102,13 +1100,18 @@ object_ptr CreatePollBox::setupContent() { FocusAtEnd(question); }, lifetime()); + const auto isNormal = (_sendType == Api::SendType::Normal); + const auto isScheduled = (_sendType == Api::SendType::Scheduled); + const auto submit = addButton( - tr::lng_polls_create_button(), - [=] { send({}); }); - if (_sendType == Api::SendType::Normal) { + isNormal + ? tr::lng_polls_create_button() + : tr::lng_schedule_button(), + [=] { isNormal ? send({}) : sendScheduled(); }); + if (isNormal || isScheduled) { const auto sendMenuType = [=] { collectError(); - return *error + return (*error || isScheduled) ? SendMenu::Type::Disabled : SendMenu::Type::Scheduled; }; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index c08579410..464b7e418 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -233,7 +233,9 @@ void TopBarWidget::showMenu() { peer, FilterId(), addAction, - Window::PeerMenuSource::History); + (_section == Section::Scheduled) + ? Window::PeerMenuSource::ScheduledSection + : Window::PeerMenuSource::History); } else if (const auto folder = _activeChat.folder()) { Window::FillFolderMenu( _controller, @@ -640,8 +642,12 @@ void TopBarWidget::updateControlsVisibility() { _unreadBadge->show(); } const auto historyMode = (_section == Section::History); + const auto scheduledMode = (_section == Section::Scheduled); + const auto showInScheduledMode = (_activeChat.peer() + && _activeChat.peer()->canSendPolls()); updateSearchVisibility(); - _menuToggle->setVisible(historyMode && !_activeChat.folder()); + _menuToggle->setVisible(!_activeChat.folder() + && (scheduledMode ? showInScheduledMode : historyMode)); _infoToggle->setVisible(historyMode && !_activeChat.folder() && !Adaptive::OneColumn() diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index cc736bc86..d4aff3db6 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -25,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "mainwidget.h" #include "mainwindow.h" -#include "api/api_common.h" #include "api/api_chat_filters.h" #include "mtproto/mtproto_config.h" #include "history/history.h" @@ -92,6 +91,8 @@ private: void addChatActions(not_null chat); void addChannelActions(not_null channel); + void addPollAction(not_null peer); + not_null _controller; not_null _peer; FilterId _filterId = 0; @@ -484,11 +485,7 @@ void Filler::addUserActions(not_null user) { tr::lng_profile_invite_to_group(tr::now), [=] { AddBotToGroup::Start(controller, user); }); } - if (user->canSendPolls()) { - _addAction( - tr::lng_polls_create(tr::now), - [=] { PeerMenuCreatePoll(controller, user); }); - } + addPollAction(user); if (user->canExportChatHistory()) { _addAction( tr::lng_profile_export_chat(tr::now), @@ -522,11 +519,7 @@ void Filler::addChatActions(not_null chat) { tr::lng_profile_add_participant(tr::now), [=] { AddChatMembers(controller, chat); }); } - if (chat->canSendPolls()) { - _addAction( - tr::lng_polls_create(tr::now), - [=] { PeerMenuCreatePoll(controller, chat); }); - } + addPollAction(chat); if (chat->canExportChatHistory()) { _addAction( tr::lng_profile_export_chat(tr::now), @@ -568,11 +561,7 @@ void Filler::addChannelActions(not_null channel) { tr::lng_channel_add_members(tr::now), [=] { PeerMenuAddChannelMembers(navigation, channel); }); } - if (channel->canSendPolls()) { - _addAction( - tr::lng_polls_create(tr::now), - [=] { PeerMenuCreatePoll(navigation, channel); }); - } + addPollAction(channel); if (channel->canExportChatHistory()) { _addAction( (isGroup @@ -610,7 +599,26 @@ void Filler::addChannelActions(not_null channel) { } } +void Filler::addPollAction(not_null peer) { + if (!peer->canSendPolls()) { + return; + } + const auto controller = _controller; + const auto source = (_source == PeerMenuSource::ScheduledSection) + ? Api::SendType::Scheduled + : Api::SendType::Normal; + const auto flag = PollData::Flags(); + auto callback = [=] { + PeerMenuCreatePoll(controller, peer, flag, flag, source); + }; + _addAction(tr::lng_polls_create(tr::now), std::move(callback)); +} + void Filler::fill() { + if (_source == PeerMenuSource::ScheduledSection) { + addPollAction(_peer); + return; + } if (showHidePromotion()) { addHidePromotion(); } @@ -791,7 +799,8 @@ void PeerMenuCreatePoll( not_null controller, not_null peer, PollData::Flags chosen, - PollData::Flags disabled) { + PollData::Flags disabled, + Api::SendType sendType) { if (peer->isChannel() && !peer->isMegagroup()) { chosen &= ~PollData::Flag::PublicVotes; disabled |= PollData::Flag::PublicVotes; @@ -800,7 +809,7 @@ void PeerMenuCreatePoll( controller, chosen, disabled, - Api::SendType::Normal)); + sendType)); const auto lock = box->lifetime().make_state(false); box->submitRequests( ) | rpl::start_with_next([=](const CreatePollBox::Result &result) { diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index e68bdb138..3268ffcbf 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "api/api_common.h" #include "data/data_poll.h" class History; @@ -30,6 +31,7 @@ enum class PeerMenuSource { ChatsList, History, Profile, + ScheduledSection, }; using PeerMenuCallback = Fn controller, not_null peer, PollData::Flags chosen = PollData::Flags(), - PollData::Flags disabled = PollData::Flags()); + PollData::Flags disabled = PollData::Flags(), + Api::SendType sendType = Api::SendType::Normal); void PeerMenuBlockUserBox( not_null box, not_null window,