diff --git a/Telegram/SourceFiles/api/api_common.h b/Telegram/SourceFiles/api/api_common.h index 99f173cd1..00154cf01 100644 --- a/Telegram/SourceFiles/api/api_common.h +++ b/Telegram/SourceFiles/api/api_common.h @@ -16,6 +16,11 @@ struct SendOptions { bool removeWebPageId = false; }; +enum class SendType { + Normal, + Scheduled, +}; + struct SendAction { explicit SendAction(not_null history) : history(history) { } diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 493b60c89..86df6293e 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -19,6 +19,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "core/event_filter.h" #include "chat_helpers/emoji_suggestions_widget.h" +#include "chat_helpers/message_field.h" +#include "history/view/history_view_schedule_box.h" #include "settings/settings_common.h" #include "base/unique_qptr.h" #include "styles/style_boxes.h" @@ -592,11 +594,15 @@ void Options::checkLastOption() { } // namespace -CreatePollBox::CreatePollBox(QWidget*, not_null session) -: _session(session) { +CreatePollBox::CreatePollBox( + QWidget*, + not_null session, + Api::SendType sendType) +: _session(session) +, _sendType(sendType) { } -rpl::producer CreatePollBox::submitRequests() const { +rpl::producer CreatePollBox::submitRequests() const { return _submitRequests.events(); } @@ -703,6 +709,19 @@ object_ptr CreatePollBox::setupContent() { result.answers = options->toPollAnswers(); return result; }; + const auto send = [=](Api::SendOptions options) { + _submitRequests.fire({ collectResult(), options }); + }; + const auto sendSilent = [=] { + auto options = Api::SendOptions(); + options.silent = true; + send(options); + }; + const auto sendScheduled = [=] { + Ui::show( + HistoryView::PrepareScheduleBox(this, send), + LayerOption::KeepOther); + }; const auto updateValid = [=] { valid->fire(isValidQuestion() && options->isValid()); }; @@ -715,9 +734,16 @@ object_ptr CreatePollBox::setupContent() { ) | rpl::start_with_next([=](bool valid) { clearButtons(); if (valid) { - addButton( + const auto submit = addButton( tr::lng_polls_create_button(), - [=] { _submitRequests.fire(collectResult()); }); + [=] { send({}); }); + if (_sendType == Api::SendType::Normal) { + SetupSendMenu( + submit.data(), + [=] { return true; }, + sendSilent, + sendScheduled); + } } addButton(tr::lng_cancel(), [=] { closeBox(); }); }, lifetime()); diff --git a/Telegram/SourceFiles/boxes/create_poll_box.h b/Telegram/SourceFiles/boxes/create_poll_box.h index ae94e584b..cc38e5af3 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.h +++ b/Telegram/SourceFiles/boxes/create_poll_box.h @@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "boxes/abstract_box.h" +#include "api/api_common.h" +#include "data/data_poll.h" struct PollData; @@ -21,9 +23,17 @@ class Session; class CreatePollBox : public BoxContent { public: - CreatePollBox(QWidget*, not_null session); + struct Result { + PollData poll; + Api::SendOptions options; + }; - rpl::producer submitRequests() const; + CreatePollBox( + QWidget*, + not_null session, + Api::SendType sendType); + + rpl::producer submitRequests() const; void submitFailed(const QString &error); void setInnerFocus() override; @@ -37,8 +47,9 @@ private: not_null container); const not_null _session; + const Api::SendType _sendType = Api::SendType(); Fn _setInnerFocus; Fn()> _dataIsValidValue; - rpl::event_stream _submitRequests; + rpl::event_stream _submitRequests; }; diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 1e237ee6c..8a5ad1e88 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -1368,8 +1368,10 @@ SendFilesBox::SendFilesBox( Storage::PreparedList &&list, const TextWithTags &caption, CompressConfirm compressed, - SendLimit limit) + SendLimit limit, + Api::SendType sendType) : _controller(controller) +, _sendType(sendType) , _list(std::move(list)) , _compressConfirmInitial(compressed) , _compressConfirm(compressed) @@ -1471,11 +1473,13 @@ void SendFilesBox::setupShadows( void SendFilesBox::prepare() { _send = addButton(tr::lng_send_button(), [=] { send({}); }); - SetupSendWithoutSound( - _send, - [=] { return true; }, - [=] { sendSilent(); }, - [=] { sendScheduled(); }); + if (_sendType == Api::SendType::Normal) { + SetupSendMenu( + _send, + [=] { return true; }, + [=] { sendSilent(); }, + [=] { sendScheduled(); }); + } addButton(tr::lng_cancel(), [=] { closeBox(); }); initSendWay(); setupCaption(); @@ -1922,6 +1926,10 @@ void SendFilesBox::setInnerFocus() { void SendFilesBox::send( Api::SendOptions options, bool ctrlShiftEnter) { + if (_sendType == Api::SendType::Scheduled && !options.scheduled) { + return sendScheduled(); + } + using Way = SendFilesWay; const auto way = _sendWay ? _sendWay->value() : Way::Files; @@ -1963,14 +1971,9 @@ void SendFilesBox::sendSilent() { } void SendFilesBox::sendScheduled() { - const auto callback = crl::guard(this, [=](Api::SendOptions options) { - send(options); - }); + const auto callback = [=](Api::SendOptions options) { send(options); }; Ui::show( - Box( - HistoryView::ScheduleBox, - callback, - HistoryView::DefaultScheduleTime()), + HistoryView::PrepareScheduleBox(this, callback), LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/boxes/send_files_box.h b/Telegram/SourceFiles/boxes/send_files_box.h index a5afd7202..322cb6003 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.h +++ b/Telegram/SourceFiles/boxes/send_files_box.h @@ -18,6 +18,7 @@ class SessionController; namespace Api { struct SendOptions; +enum class SendType; } // namespace Api namespace ChatHelpers { @@ -57,7 +58,8 @@ public: Storage::PreparedList &&list, const TextWithTags &caption, CompressConfirm compressed, - SendLimit limit); + SendLimit limit, + Api::SendType sendType); void setConfirmedCallback( Fn &urls) const; bool addFiles(not_null data); - not_null _controller; + const not_null _controller; + const Api::SendType _sendType = Api::SendType(); QString _titleText; int _titleHeight = 0; diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 2b455a0b8..fb0b3787e 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -415,7 +415,7 @@ void ShareBox::createButtons() { const auto send = addButton(tr::lng_share_confirm(), [=] { submit({}); }); - SetupSendWithoutSound( + SetupSendMenu( send, [=] { return true; }, [=] { submitSilent(); }, @@ -469,14 +469,9 @@ void ShareBox::submitSilent() { } void ShareBox::submitScheduled() { - const auto callback = crl::guard(this, [=](Api::SendOptions options) { - submit(options); - }); + const auto callback = [=](Api::SendOptions options) { submit(options); }; Ui::show( - Box( - HistoryView::ScheduleBox, - callback, - HistoryView::DefaultScheduleTime()), + HistoryView::PrepareScheduleBox(this, callback), LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index a0f63de69..805a96119 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -784,7 +784,7 @@ void MessageLinksParser::apply( _list = std::move(parsed); } -void SetupSendWithoutSound( +void SetupSendMenu( not_null button, Fn enabled, Fn send, diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index e25d70b2f..cbadf01cb 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -106,7 +106,7 @@ private: }; -void SetupSendWithoutSound( +void SetupSendMenu( not_null button, Fn enabled, Fn send, diff --git a/Telegram/SourceFiles/data/data_scheduled_messages.cpp b/Telegram/SourceFiles/data/data_scheduled_messages.cpp index 7b37a1b4a..6800c2a3c 100644 --- a/Telegram/SourceFiles/data/data_scheduled_messages.cpp +++ b/Telegram/SourceFiles/data/data_scheduled_messages.cpp @@ -237,7 +237,6 @@ void ScheduledMessages::parse( auto &request = _requests[history]; request.requestId = 0; - auto element = _data.find(history); list.match([&](const MTPDmessages_messagesNotModified &data) { }, [&](const auto &data) { _session->data().processUsers(data.vusers()); @@ -245,38 +244,24 @@ void ScheduledMessages::parse( const auto &messages = data.vmessages().v; if (messages.isEmpty()) { - if (element != end(_data)) { - _data.erase(element); - element = end(_data); - _updates.fire_copy(history); - } + clearNotSending(history); return; } - element = _data.emplace(history, List()).first; auto received = base::flat_set>(); - auto &list = element->second; + auto clear = base::flat_set>(); + auto &list = _data.emplace(history, List()).first->second; for (const auto &message : messages) { if (const auto item = append(history, list, message)) { received.emplace(item); } } - auto clear = base::flat_set>(); for (const auto &owned : list.items) { const auto item = owned.get(); if (!item->isSending() && !received.contains(item)) { clear.emplace(item); } } - for (const auto item : clear) { - item->destroy(); - } - if (!list.items.empty()) { - sort(list); - } else { - _data.erase(element); - element = end(_data); - } - _updates.fire_copy(history); + updated(history, received, clear); }); if (!request.requestId) { _requests.remove(history); @@ -320,6 +305,38 @@ HistoryItem *ScheduledMessages::append( return item; } +void ScheduledMessages::clearNotSending(not_null history) { + const auto i = _data.find(history); + if (i == end(_data)) { + return; + } + auto clear = base::flat_set>(); + for (const auto &owned : i->second.items) { + if (!owned->isSending()) { + clear.emplace(owned.get()); + } + } + updated(history, {}, clear); +} + +void ScheduledMessages::updated( + not_null history, + const base::flat_set> &added, + const base::flat_set> &clear) { + if (!clear.empty()) { + for (const auto item : clear) { + item->destroy(); + } + } + const auto i = _data.find(history); + if (i != end(_data)) { + sort(i->second); + } + if (!added.empty() || !clear.empty()) { + _updates.fire_copy(history); + } +} + void ScheduledMessages::sort(List &list) { ranges::sort(list.items, ranges::less(), &HistoryItem::position); } @@ -330,11 +347,12 @@ void ScheduledMessages::remove(not_null item) { Assert(i != end(_data)); auto &list = i->second; - const auto j = list.idByItem.find(item); - Assert(j != end(list.idByItem)); - list.itemById.remove(j->second); - list.idByItem.erase(j); - + if (!item->isSending()) { + const auto j = list.idByItem.find(item); + Assert(j != end(list.idByItem)); + list.itemById.remove(j->second); + list.idByItem.erase(j); + } const auto k = ranges::find(list.items, item, &OwnedItem::get); Assert(k != list.items.end()); k->release(); diff --git a/Telegram/SourceFiles/data/data_scheduled_messages.h b/Telegram/SourceFiles/data/data_scheduled_messages.h index d29189e42..9ae0de149 100644 --- a/Telegram/SourceFiles/data/data_scheduled_messages.h +++ b/Telegram/SourceFiles/data/data_scheduled_messages.h @@ -61,6 +61,11 @@ private: not_null history, List &list, const MTPMessage &message); + void clearNotSending(not_null history); + void updated( + not_null history, + const base::flat_set> &added, + const base::flat_set> &clear); void sort(List &list); void remove(not_null item); [[nodiscard]] int32 countListHash(const List &list) const; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 6fd266f0d..df53b525f 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -300,7 +300,7 @@ HistoryWidget::HistoryWidget( _unreadMentions->addClickHandler([=] { showNextUnreadMention(); }); _fieldBarCancel->addClickHandler([=] { cancelFieldAreaState(); }); _send->addClickHandler([=] { sendButtonClicked(); }); - SetupSendWithoutSound(_send, [=] { + SetupSendMenu(_send, [=] { return (_send->type() == Ui::SendButton::Type::Send) && !_send->isDisabled(); }, [=] { sendSilent(); }, [=] { sendScheduled(); }); @@ -1747,11 +1747,11 @@ void HistoryWidget::showHistory( updateControlsGeometry(); }, _contactStatus->lifetime()); orderWidgets(); + controller()->tabbedSelector()->setCurrentPeer(_peer); } else { _contactStatus = nullptr; } refreshTabbedPanel(); - controller()->tabbedSelector()->setCurrentPeer(_peer); if (_peer) { _unblock->setText(((_peer->isUser() @@ -2970,14 +2970,9 @@ void HistoryWidget::sendScheduled() { if (!_list) { return; } - const auto callback = crl::guard(_list, [=](Api::SendOptions options) { - send(options); - }); + const auto callback = [=](Api::SendOptions options) { send(options); }; Ui::show( - Box( - HistoryView::ScheduleBox, - callback, - HistoryView::DefaultScheduleTime()), + HistoryView::PrepareScheduleBox(_list, callback), LayerOption::KeepOther); } @@ -4192,7 +4187,8 @@ bool HistoryWidget::confirmSendingFiles( std::move(list), text, boxCompressConfirm, - _peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many); + _peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many, + Api::SendType::Normal); _field->setTextWithTags({}); box->setConfirmedCallback(crl::guard(this, [=]( Storage::PreparedList &&list, diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp index 0f67629e1..71c35e7cc 100644 --- a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/special_buttons.h" #include "lang/lang_keys.h" #include "core/event_filter.h" +#include "history/history.h" #include "chat_helpers/tabbed_panel.h" #include "chat_helpers/tabbed_section.h" #include "chat_helpers/tabbed_selector.h" @@ -54,6 +55,15 @@ Main::Session &ComposeControls::session() const { return _window->session(); } +void ComposeControls::setHistory(History *history) { + if (_history == history) { + return; + } + _history = history; + _window->tabbedSelector()->setCurrentPeer( + history ? history->peer.get() : nullptr); +} + void ComposeControls::move(int x, int y) { _wrap->move(x, y); } diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/history_view_compose_controls.h index e54132114..3c686b200 100644 --- a/Telegram/SourceFiles/history/view/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.h @@ -58,6 +58,8 @@ public: [[nodiscard]] Main::Session &session() const; + void setHistory(History *history); + void move(int x, int y); void resizeToWidth(int width); [[nodiscard]] rpl::producer height() const; @@ -102,6 +104,7 @@ private: const not_null _parent; const not_null _window; + History *_history = nullptr; Mode _mode = Mode::Normal; const std::unique_ptr _wrap; diff --git a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp index 879d3bec2..4949cbbed 100644 --- a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp +++ b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp @@ -13,7 +13,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/calendar_box.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/labels.h" +#include "ui/widgets/buttons.h" #include "ui/wrap/padding_wrap.h" +#include "chat_helpers/message_field.h" #include "styles/style_boxes.h" #include "styles/style_history.h" @@ -88,6 +90,7 @@ public: bool setFocusFast(); rpl::producer value() const; + rpl::producer<> submitRequests() const; QString valueCurrent() const; void showError(); @@ -117,6 +120,7 @@ private: object_ptr> _separator1; object_ptr _minute; rpl::variable _value; + rpl::event_stream<> _submitRequests; style::cursor _cursor = style::cur_default; Ui::Animations::Simple _a_borderShown; @@ -293,6 +297,29 @@ TimeInput::TimeInput(QWidget *parent, const QString &value) ) | rpl::start_with_next([=] { setErrorShown(false); }, lifetime()); + + const auto submitHour = [=] { + if (hour()) { + _minute->setFocus(); + } + }; + const auto submitMinute = [=] { + if (minute()) { + if (hour()) { + _submitRequests.fire({}); + } else { + _hour->setFocus(); + } + } + }; + connect( + _hour, + &Ui::MaskedInputField::submitted, + submitHour); + connect( + _minute, + &Ui::MaskedInputField::submitted, + submitMinute); } void TimeInput::putNext(const object_ptr &field, QChar ch) { @@ -350,6 +377,10 @@ rpl::producer TimeInput::value() const { return _value.value(); } +rpl::producer<> TimeInput::submitRequests() const { + return _submitRequests.events(); +} + void TimeInput::paintEvent(QPaintEvent *e) { Painter p(this); @@ -584,23 +615,30 @@ void ScheduleBox( const auto shared = std::make_shared>( std::move(done)); - const auto save = [=] { - auto result = Api::SendOptions(); - + const auto collect = [=] { const auto timeValue = timeInput->valueCurrent().split(':'); if (timeValue.size() != 2) { timeInput->showError(); - return; + return 0; } const auto time = QTime(timeValue[0].toInt(), timeValue[1].toInt()); if (!time.isValid()) { timeInput->showError(); - return; + return 0; } - result.scheduled = base::unixtime::serialize( + const auto result = base::unixtime::serialize( QDateTime(date->current(), time)); - if (result.scheduled <= base::unixtime::now() + kMinimalSchedule) { + if (result <= base::unixtime::now() + kMinimalSchedule) { timeInput->showError(); + return 0; + } + return result; + }; + const auto save = [=](bool silent) { + auto result = Api::SendOptions(); + result.silent = silent; + result.scheduled = collect(); + if (!result.scheduled) { return; } @@ -608,9 +646,20 @@ void ScheduleBox( box->closeBox(); (*copy)(result); }; + timeInput->submitRequests( + ) | rpl::start_with_next([=] { + save(false); + }, timeInput->lifetime()); box->setFocusCallback([=] { timeInput->setFocusFast(); }); - box->addButton(tr::lng_settings_save(), save); + const auto submit = box->addButton(tr::lng_settings_save(), [=] { + save(false); + }); + SetupSendMenu( + submit.data(), + [=] { return true; }, + [=] { save(true); }, + nullptr); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); } diff --git a/Telegram/SourceFiles/history/view/history_view_schedule_box.h b/Telegram/SourceFiles/history/view/history_view_schedule_box.h index cde32b0ce..2b73ee5da 100644 --- a/Telegram/SourceFiles/history/view/history_view_schedule_box.h +++ b/Telegram/SourceFiles/history/view/history_view_schedule_box.h @@ -21,4 +21,14 @@ void ScheduleBox( FnMut done, TimeId time); +template +[[nodiscard]] object_ptr PrepareScheduleBox( + Guard &&guard, + Submit &&submit) { + return Box( + ScheduleBox, + crl::guard(std::forward(guard), std::forward(submit)), + DefaultScheduleTime()); +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 29e376905..e387d92d3 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -117,6 +117,8 @@ ScheduledWidget::ScheduledWidget( ScheduledWidget::~ScheduledWidget() = default; void ScheduledWidget::setupComposeControls() { + _composeControls->setHistory(_history); + _composeControls->height( ) | rpl::start_with_next([=] { updateControlsGeometry(); @@ -232,7 +234,8 @@ bool ScheduledWidget::confirmSendingFiles( std::move(list), text, boxCompressConfirm, - _history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many); + _history->peer->slowmodeApplied() ? SendLimit::One : SendLimit::Many, + Api::SendType::Scheduled); //_field->setTextWithTags({}); box->setConfirmedCallback(crl::guard(this, [=]( @@ -314,39 +317,28 @@ void ScheduledWidget::uploadFilesAfterConfirmation( ShowErrorToast(tr::lng_slowmode_no_many(tr::now)); return; } - auto callback = crl::guard(this, [ - =, - list = std::move(list), - caption = std::move(caption), - // Strange thing, otherwise std::is_copy_constructible is true. O_o - msvc_bug_workaround = std::make_unique() - ](Api::SendOptions options) mutable { - auto action = Api::SendAction(_history); - action.replyTo = replyTo; - action.options = options; - session().api().sendFiles( - std::move(list), - type, - std::move(caption), - album, - action); - }); - Ui::show( - Box(ScheduleBox, std::move(callback), DefaultScheduleTime()), - LayerOption::KeepOther); + auto action = Api::SendAction(_history); + action.replyTo = replyTo; + action.options = options; + session().api().sendFiles( + std::move(list), + type, + std::move(caption), + album, + action); } void ScheduledWidget::uploadFile( const QByteArray &fileContent, SendMediaType type) { - const auto callback = crl::guard(this, [=](Api::SendOptions options) { + const auto callback = [=](Api::SendOptions options) { auto action = Api::SendAction(_history); //action.replyTo = replyToId(); action.options = options; session().api().sendFile(fileContent, type, action); - }); + }; Ui::show( - Box(ScheduleBox, callback, DefaultScheduleTime()), + PrepareScheduleBox(this, callback), LayerOption::KeepOther); } @@ -387,11 +379,9 @@ void ScheduledWidget::send() { if (_composeControls->getTextWithAppliedMarkdown().text.isEmpty()) { return; } - const auto callback = crl::guard(this, [=](Api::SendOptions options) { - send(options); - }); + const auto callback = [=](Api::SendOptions options) { send(options); }; Ui::show( - Box(ScheduleBox, callback, DefaultScheduleTime()), + PrepareScheduleBox(this, callback), LayerOption::KeepOther); } @@ -432,11 +422,11 @@ void ScheduledWidget::send(Api::SendOptions options) { void ScheduledWidget::sendExistingDocument( not_null document) { - const auto callback = crl::guard(this, [=](Api::SendOptions options) { + const auto callback = [=](Api::SendOptions options) { sendExistingDocument(document, options); - }); + }; Ui::show( - Box(ScheduleBox, callback, DefaultScheduleTime()), + PrepareScheduleBox(this, callback), LayerOption::KeepOther); } @@ -470,11 +460,11 @@ bool ScheduledWidget::sendExistingDocument( } void ScheduledWidget::sendExistingPhoto(not_null photo) { - const auto callback = crl::guard(this, [=](Api::SendOptions options) { + const auto callback = [=](Api::SendOptions options) { sendExistingPhoto(photo, options); - }); + }; Ui::show( - Box(ScheduleBox, callback, DefaultScheduleTime()), + PrepareScheduleBox(this, callback), LayerOption::KeepOther); } @@ -507,11 +497,11 @@ void ScheduledWidget::sendInlineResult( Ui::show(Box(errorText)); return; } - const auto callback = crl::guard(this, [=](Api::SendOptions options) { + const auto callback = [=](Api::SendOptions options) { sendInlineResult(result, bot, options); - }); + }; Ui::show( - Box(ScheduleBox, callback, DefaultScheduleTime()), + PrepareScheduleBox(this, callback), LayerOption::KeepOther); } diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 6cef969e8..1e636ac52 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "mainwindow.h" #include "observer_peer.h" +#include "api/api_common.h" #include "history/history.h" #include "history/history_item.h" #include "window/window_session_controller.h" @@ -700,14 +701,17 @@ void PeerMenuShareContactBox( } void PeerMenuCreatePoll(not_null peer) { - const auto box = Ui::show(Box(&peer->session())); + const auto box = Ui::show(Box( + &peer->session(), + Api::SendType::Normal)); const auto lock = box->lifetime().make_state(false); box->submitRequests( - ) | rpl::start_with_next([=](const PollData &result) { + ) | rpl::start_with_next([=](const CreatePollBox::Result &result) { if (std::exchange(*lock, true)) { return; } auto action = Api::SendAction(peer->owner().history(peer)); + action.options = result.options; if (const auto id = App::main()->currentReplyToIdFor(action.history)) { action.replyTo = id; } @@ -715,7 +719,7 @@ void PeerMenuCreatePoll(not_null peer) { action.clearDraft = localDraft->textWithTags.text.isEmpty(); } const auto api = &peer->session().api(); - api->createPoll(result, action, crl::guard(box, [=] { + api->createPoll(result.poll, action, crl::guard(box, [=] { box->closeBox(); }), crl::guard(box, [=](const RPCError &error) { *lock = false;