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;
}
};
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<Ui::RpWidget> 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<Ui::RpWidget> 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;
};

View file

@ -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()

View file

@ -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<ChatData*> chat);
void addChannelActions(not_null<ChannelData*> channel);
void addPollAction(not_null<PeerData*> peer);
not_null<SessionController*> _controller;
not_null<PeerData*> _peer;
FilterId _filterId = 0;
@ -484,11 +485,7 @@ void Filler::addUserActions(not_null<UserData*> 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<ChatData*> 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<ChannelData*> 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<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() {
if (_source == PeerMenuSource::ScheduledSection) {
addPollAction(_peer);
return;
}
if (showHidePromotion()) {
addHidePromotion();
}
@ -791,7 +799,8 @@ void PeerMenuCreatePoll(
not_null<Window::SessionController*> controller,
not_null<PeerData*> 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<bool>(false);
box->submitRequests(
) | rpl::start_with_next([=](const CreatePollBox::Result &result) {

View file

@ -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<QAction*(
@ -65,7 +67,8 @@ void PeerMenuCreatePoll(
not_null<Window::SessionController*> controller,
not_null<PeerData*> 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<Ui::GenericBox*> box,
not_null<Window::Controller*> window,