Added ability to schedule polls from section of scheduled messages.

Fixed #7433.
This commit is contained in:
23rd 2020-08-03 12:02:41 +03:00 committed by John Preston
parent 14cda49db2
commit b12256f1ee
4 changed files with 54 additions and 33 deletions

View file

@ -1059,19 +1059,19 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
*error &= ~Error::Solution; *error &= ~Error::Solution;
} }
}; };
const auto showError = [=](const QString &text) { const auto showError = [](tr::phrase<> text) {
Ui::Toast::Show(text); Ui::Toast::Show(text(tr::now));
}; };
const auto send = [=](Api::SendOptions sendOptions) { const auto send = [=](Api::SendOptions sendOptions) {
collectError(); collectError();
if (*error & Error::Question) { if (*error & Error::Question) {
showError(tr::lng_polls_choose_question(tr::now)); showError(tr::lng_polls_choose_question);
question->setFocus(); question->setFocus();
} else if (*error & Error::Options) { } else if (*error & Error::Options) {
showError(tr::lng_polls_choose_answers(tr::now)); showError(tr::lng_polls_choose_answers);
options->focusFirst(); options->focusFirst();
} else if (*error & Error::Correct) { } else if (*error & Error::Correct) {
showError(tr::lng_polls_choose_correct(tr::now)); showError(tr::lng_polls_choose_correct);
} else if (*error & Error::Solution) { } else if (*error & Error::Solution) {
solution->showError(); solution->showError();
} else if (!*error) { } else if (!*error) {
@ -1079,9 +1079,7 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
} }
}; };
const auto sendSilent = [=] { const auto sendSilent = [=] {
auto options = Api::SendOptions(); send({ .silent = true });
options.silent = true;
send(options);
}; };
const auto sendScheduled = [=] { const auto sendScheduled = [=] {
Ui::show( Ui::show(
@ -1102,13 +1100,18 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
FocusAtEnd(question); FocusAtEnd(question);
}, lifetime()); }, lifetime());
const auto isNormal = (_sendType == Api::SendType::Normal);
const auto isScheduled = (_sendType == Api::SendType::Scheduled);
const auto submit = addButton( const auto submit = addButton(
tr::lng_polls_create_button(), isNormal
[=] { send({}); }); ? tr::lng_polls_create_button()
if (_sendType == Api::SendType::Normal) { : tr::lng_schedule_button(),
[=] { isNormal ? send({}) : sendScheduled(); });
if (isNormal || isScheduled) {
const auto sendMenuType = [=] { const auto sendMenuType = [=] {
collectError(); collectError();
return *error return (*error || isScheduled)
? SendMenu::Type::Disabled ? SendMenu::Type::Disabled
: SendMenu::Type::Scheduled; : SendMenu::Type::Scheduled;
}; };

View file

@ -233,7 +233,9 @@ void TopBarWidget::showMenu() {
peer, peer,
FilterId(), FilterId(),
addAction, addAction,
Window::PeerMenuSource::History); (_section == Section::Scheduled)
? Window::PeerMenuSource::ScheduledSection
: Window::PeerMenuSource::History);
} else if (const auto folder = _activeChat.folder()) { } else if (const auto folder = _activeChat.folder()) {
Window::FillFolderMenu( Window::FillFolderMenu(
_controller, _controller,
@ -640,8 +642,12 @@ void TopBarWidget::updateControlsVisibility() {
_unreadBadge->show(); _unreadBadge->show();
} }
const auto historyMode = (_section == Section::History); const auto historyMode = (_section == Section::History);
const auto scheduledMode = (_section == Section::Scheduled);
const auto showInScheduledMode = (_activeChat.peer()
&& _activeChat.peer()->canSendPolls());
updateSearchVisibility(); updateSearchVisibility();
_menuToggle->setVisible(historyMode && !_activeChat.folder()); _menuToggle->setVisible(!_activeChat.folder()
&& (scheduledMode ? showInScheduledMode : historyMode));
_infoToggle->setVisible(historyMode _infoToggle->setVisible(historyMode
&& !_activeChat.folder() && !_activeChat.folder()
&& !Adaptive::OneColumn() && !Adaptive::OneColumn()

View file

@ -25,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "apiwrap.h" #include "apiwrap.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "api/api_common.h"
#include "api/api_chat_filters.h" #include "api/api_chat_filters.h"
#include "mtproto/mtproto_config.h" #include "mtproto/mtproto_config.h"
#include "history/history.h" #include "history/history.h"
@ -92,6 +91,8 @@ private:
void addChatActions(not_null<ChatData*> chat); void addChatActions(not_null<ChatData*> chat);
void addChannelActions(not_null<ChannelData*> channel); void addChannelActions(not_null<ChannelData*> channel);
void addPollAction(not_null<PeerData*> peer);
not_null<SessionController*> _controller; not_null<SessionController*> _controller;
not_null<PeerData*> _peer; not_null<PeerData*> _peer;
FilterId _filterId = 0; FilterId _filterId = 0;
@ -484,11 +485,7 @@ void Filler::addUserActions(not_null<UserData*> user) {
tr::lng_profile_invite_to_group(tr::now), tr::lng_profile_invite_to_group(tr::now),
[=] { AddBotToGroup::Start(controller, user); }); [=] { AddBotToGroup::Start(controller, user); });
} }
if (user->canSendPolls()) { addPollAction(user);
_addAction(
tr::lng_polls_create(tr::now),
[=] { PeerMenuCreatePoll(controller, user); });
}
if (user->canExportChatHistory()) { if (user->canExportChatHistory()) {
_addAction( _addAction(
tr::lng_profile_export_chat(tr::now), tr::lng_profile_export_chat(tr::now),
@ -522,11 +519,7 @@ void Filler::addChatActions(not_null<ChatData*> chat) {
tr::lng_profile_add_participant(tr::now), tr::lng_profile_add_participant(tr::now),
[=] { AddChatMembers(controller, chat); }); [=] { AddChatMembers(controller, chat); });
} }
if (chat->canSendPolls()) { addPollAction(chat);
_addAction(
tr::lng_polls_create(tr::now),
[=] { PeerMenuCreatePoll(controller, chat); });
}
if (chat->canExportChatHistory()) { if (chat->canExportChatHistory()) {
_addAction( _addAction(
tr::lng_profile_export_chat(tr::now), tr::lng_profile_export_chat(tr::now),
@ -568,11 +561,7 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
tr::lng_channel_add_members(tr::now), tr::lng_channel_add_members(tr::now),
[=] { PeerMenuAddChannelMembers(navigation, channel); }); [=] { PeerMenuAddChannelMembers(navigation, channel); });
} }
if (channel->canSendPolls()) { addPollAction(channel);
_addAction(
tr::lng_polls_create(tr::now),
[=] { PeerMenuCreatePoll(navigation, channel); });
}
if (channel->canExportChatHistory()) { if (channel->canExportChatHistory()) {
_addAction( _addAction(
(isGroup (isGroup
@ -610,7 +599,26 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
} }
} }
void Filler::addPollAction(not_null<PeerData*> 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() { void Filler::fill() {
if (_source == PeerMenuSource::ScheduledSection) {
addPollAction(_peer);
return;
}
if (showHidePromotion()) { if (showHidePromotion()) {
addHidePromotion(); addHidePromotion();
} }
@ -791,7 +799,8 @@ void PeerMenuCreatePoll(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<PeerData*> peer, not_null<PeerData*> peer,
PollData::Flags chosen, PollData::Flags chosen,
PollData::Flags disabled) { PollData::Flags disabled,
Api::SendType sendType) {
if (peer->isChannel() && !peer->isMegagroup()) { if (peer->isChannel() && !peer->isMegagroup()) {
chosen &= ~PollData::Flag::PublicVotes; chosen &= ~PollData::Flag::PublicVotes;
disabled |= PollData::Flag::PublicVotes; disabled |= PollData::Flag::PublicVotes;
@ -800,7 +809,7 @@ void PeerMenuCreatePoll(
controller, controller,
chosen, chosen,
disabled, disabled,
Api::SendType::Normal)); sendType));
const auto lock = box->lifetime().make_state<bool>(false); const auto lock = box->lifetime().make_state<bool>(false);
box->submitRequests( box->submitRequests(
) | rpl::start_with_next([=](const CreatePollBox::Result &result) { ) | rpl::start_with_next([=](const CreatePollBox::Result &result) {

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "api/api_common.h"
#include "data/data_poll.h" #include "data/data_poll.h"
class History; class History;
@ -30,6 +31,7 @@ enum class PeerMenuSource {
ChatsList, ChatsList,
History, History,
Profile, Profile,
ScheduledSection,
}; };
using PeerMenuCallback = Fn<QAction*( using PeerMenuCallback = Fn<QAction*(
@ -65,7 +67,8 @@ void PeerMenuCreatePoll(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<PeerData*> peer, not_null<PeerData*> peer,
PollData::Flags chosen = PollData::Flags(), PollData::Flags chosen = PollData::Flags(),
PollData::Flags disabled = PollData::Flags()); PollData::Flags disabled = PollData::Flags(),
Api::SendType sendType = Api::SendType::Normal);
void PeerMenuBlockUserBox( void PeerMenuBlockUserBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
not_null<Window::Controller*> window, not_null<Window::Controller*> window,