diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 2d39276ac1..78a6499376 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -350,6 +350,8 @@ PRIVATE calls/calls_video_bubble.h calls/calls_video_incoming.cpp calls/calls_video_incoming.h + chat_helpers/compose/compose_show.cpp + chat_helpers/compose/compose_show.h chat_helpers/bot_command.cpp chat_helpers/bot_command.h chat_helpers/bot_keyboard.cpp @@ -934,6 +936,8 @@ PRIVATE main/main_session_settings.h main/session/send_as_peers.cpp main/session/send_as_peers.h + main/session/session_show.cpp + main/session/session_show.h media/system_media_controls_manager.h media/system_media_controls_manager.cpp media/audio/media_audio.cpp diff --git a/Telegram/SourceFiles/api/api_attached_stickers.cpp b/Telegram/SourceFiles/api/api_attached_stickers.cpp index be87544be6..0f18e76484 100644 --- a/Telegram/SourceFiles/api/api_attached_stickers.cpp +++ b/Telegram/SourceFiles/api/api_attached_stickers.cpp @@ -41,7 +41,7 @@ void AttachedStickers::request( return; } else if (result.v.size() > 1) { strongController->show( - Box(strongController, result.v)); + Box(strongController->uiShow(), result.v)); return; } // Single attached sticker pack. @@ -54,16 +54,14 @@ void AttachedStickers::request( .id = data->vid().v, .accessHash = data->vaccess_hash().v } : StickerSetIdentifier{ .shortName = qs(data->vshort_name()) }; - strongController->show( - Box( - strongController, - setId, - (data->is_emojis() - ? Data::StickersType::Emoji - : data->is_masks() - ? Data::StickersType::Masks - : Data::StickersType::Stickers)), - Ui::LayerOption::KeepOther); + strongController->show(Box( + strongController->uiShow(), + setId, + (data->is_emojis() + ? Data::StickersType::Emoji + : data->is_masks() + ? Data::StickersType::Masks + : Data::StickersType::Stickers))); }).fail([=] { _requestId = 0; if (const auto strongController = weak.get()) { diff --git a/Telegram/SourceFiles/api/api_bot.cpp b/Telegram/SourceFiles/api/api_bot.cpp index 4c19b4c850..8fa7f884c3 100644 --- a/Telegram/SourceFiles/api/api_bot.cpp +++ b/Telegram/SourceFiles/api/api_bot.cpp @@ -82,7 +82,7 @@ void SendBotCallbackData( flags |= MTPmessages_GetBotCallbackAnswer::Flag::f_password; } const auto weak = base::make_weak(controller); - const auto show = std::make_shared(controller); + const auto show = controller->uiShow(); button->requestId = api->request(MTPmessages_GetBotCallbackAnswer( MTP_flags(flags), history->peer->input, @@ -119,7 +119,7 @@ void SendBotCallbackData( if (withPassword) { show->hideLayer(); } - Ui::Toast::Show(show->toastParent(), message); + show->showToast(message); } } else if (!link.isEmpty()) { if (!isGame) { @@ -210,7 +210,7 @@ void SendBotCallbackDataWithPassword( } api->cloudPassword().reload(); const auto weak = base::make_weak(controller); - const auto show = std::make_shared(controller); + const auto show = controller->uiShow(); SendBotCallbackData(controller, item, row, column, {}, {}, [=]( const QString &error) { auto box = PrePasswordErrorBox( diff --git a/Telegram/SourceFiles/api/api_chat_filters.cpp b/Telegram/SourceFiles/api/api_chat_filters.cpp index 5bd4144c49..2b19deac33 100644 --- a/Telegram/SourceFiles/api/api_chat_filters.cpp +++ b/Telegram/SourceFiles/api/api_chat_filters.cpp @@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/confirm_box.h" #include "ui/controls/filter_link_header.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" #include "ui/widgets/buttons.h" #include "ui/filter_icons.h" #include "window/window_session_controller.h" @@ -515,13 +514,9 @@ void ShowImportError( } else if (error == u"CHATLISTS_TOO_MUCH"_q) { window->show(Box(ShareableFiltersLimitBox, session)); } else { - const auto text = (error == u"INVITE_SLUG_EXPIRED"_q) + window->showToast((error == u"INVITE_SLUG_EXPIRED"_q) ? tr::lng_group_invite_bad_link(tr::now) - : error; - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(window).toastParent(), - .text = { text }, - }); + : error); } } @@ -545,10 +540,7 @@ void ShowImportToast( : tr::lng_filters_updated_also; text.append('\n').append(phrase(tr::now, lt_count, added)); } - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(strong).toastParent(), - .text = { std::move(text) }, - }); + strong->showToast(std::move(text)); } void ProcessFilterInvite( @@ -565,10 +557,7 @@ void ProcessFilterInvite( } Core::App().hideMediaView(); if (peers.empty() && !filterId) { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(strong).toastParent(), - .text = { tr::lng_group_invite_bad_link(tr::now) }, - }); + strong->showToast(tr::lng_group_invite_bad_link(tr::now)); return; } const auto fullyAdded = (peers.empty() && filterId); @@ -661,10 +650,7 @@ void ProcessFilterInvite( const auto &list = strong->session().data().chatsFilters().list(); const auto it = ranges::find(list, filterId, &Data::ChatFilter::id); if (it == end(list)) { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(strong).toastParent(), - .text = { u"Filter not found :shrug:"_q }, - }); + strong->showToast(u"Filter not found :shrug:"_q); return; } ProcessFilterInvite( diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index 674061653e..8b395d9a9e 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -22,7 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_file_origin.h" #include "ui/boxes/confirm_box.h" -#include "ui/toasts/common_toasts.h" +#include "ui/toast/toast.h" #include "boxes/premium_limits_box.h" #include "styles/style_boxes.h" #include "styles/style_layers.h" @@ -85,20 +85,17 @@ void SubmitChatInvite( } strongController->hideLayer(); - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(strongController).toastParent(), - .text = { [&] { - if (type == u"INVITE_REQUEST_SENT"_q) { - return isGroup - ? tr::lng_group_request_sent(tr::now) - : tr::lng_group_request_sent_channel(tr::now); - } else if (type == u"USERS_TOO_MUCH"_q) { - return tr::lng_group_invite_no_room(tr::now); - } else { - return tr::lng_group_invite_bad_link(tr::now); - } - }() }, - .duration = ApiWrap::kJoinErrorDuration }); + strongController->showToast([&] { + if (type == u"INVITE_REQUEST_SENT"_q) { + return isGroup + ? tr::lng_group_request_sent(tr::now) + : tr::lng_group_request_sent_channel(tr::now); + } else if (type == u"USERS_TOO_MUCH"_q) { + return tr::lng_group_invite_no_room(tr::now); + } else { + return tr::lng_group_invite_bad_link(tr::now); + } + }(), ApiWrap::kJoinErrorDuration); }).send(); } diff --git a/Telegram/SourceFiles/api/api_report.cpp b/Telegram/SourceFiles/api/api_report.cpp index 663daf767d..7185b76f57 100644 --- a/Telegram/SourceFiles/api/api_report.cpp +++ b/Telegram/SourceFiles/api/api_report.cpp @@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "main/main_session.h" #include "ui/boxes/report_box.h" -#include "ui/toast/toast.h" +#include "ui/layers/show.h" namespace Api { @@ -39,15 +39,14 @@ MTPreportReason ReasonToTL(const Ui::ReportReason &reason) { } // namespace void SendReport( - not_null toastParent, + std::shared_ptr show, not_null peer, Ui::ReportReason reason, const QString &comment, std::variant> data) { - auto weak = Ui::MakeWeak(toastParent.get()); - auto done = crl::guard(toastParent, [=] { - Ui::Toast::Show(toastParent, tr::lng_report_thanks(tr::now)); - }); + auto done = [=] { + show->showToast(tr::lng_report_thanks(tr::now)); + }; v::match(data, [&](v::null_t) { peer->session().api().request(MTPaccount_ReportPeer( peer->input, diff --git a/Telegram/SourceFiles/api/api_report.h b/Telegram/SourceFiles/api/api_report.h index 9472221e3f..08535c00b3 100644 --- a/Telegram/SourceFiles/api/api_report.h +++ b/Telegram/SourceFiles/api/api_report.h @@ -11,13 +11,14 @@ class PeerData; class PhotoData; namespace Ui { +class Show; enum class ReportReason; } // namespace Ui namespace Api { void SendReport( - not_null toastParent, + std::shared_ptr show, not_null peer, Ui::ReportReason reason, const QString &comment, diff --git a/Telegram/SourceFiles/api/api_toggling_media.cpp b/Telegram/SourceFiles/api/api_toggling_media.cpp index 9293043a81..65d2ce317f 100644 --- a/Telegram/SourceFiles/api/api_toggling_media.cpp +++ b/Telegram/SourceFiles/api/api_toggling_media.cpp @@ -48,27 +48,26 @@ void ToggleExistingMedia( } // namespace void ToggleFavedSticker( - not_null controller, + std::shared_ptr show, not_null document, Data::FileOrigin origin) { ToggleFavedSticker( - controller, + std::move(show), document, std::move(origin), !document->owner().stickers().isFaved(document)); } void ToggleFavedSticker( - not_null controller, + std::shared_ptr show, not_null document, Data::FileOrigin origin, bool faved) { if (faved && !document->sticker()) { return; } - const auto weak = base::make_weak(controller); auto done = [=] { - document->owner().stickers().setFaved(weak.get(), document, faved); + document->owner().stickers().setFaved(show, document, faved); }; ToggleExistingMedia( document, @@ -104,17 +103,16 @@ void ToggleRecentSticker( } void ToggleSavedGif( - Window::SessionController *controller, + std::shared_ptr show, not_null document, Data::FileOrigin origin, bool saved) { if (saved && !document->isGifv()) { return; } - const auto weak = base::make_weak(controller); auto done = [=] { if (saved) { - document->owner().stickers().addSavedGif(weak.get(), document); + document->owner().stickers().addSavedGif(show, document); } }; ToggleExistingMedia( diff --git a/Telegram/SourceFiles/api/api_toggling_media.h b/Telegram/SourceFiles/api/api_toggling_media.h index a028824d5b..10f0090af2 100644 --- a/Telegram/SourceFiles/api/api_toggling_media.h +++ b/Telegram/SourceFiles/api/api_toggling_media.h @@ -7,19 +7,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -namespace Window { -class SessionController; -} // namespace Window +namespace ChatHelpers { +class Show; +} // namespace ChatHelpers namespace Api { void ToggleFavedSticker( - not_null controller, + std::shared_ptr show, not_null document, Data::FileOrigin origin); void ToggleFavedSticker( - not_null controller, + std::shared_ptr show, not_null document, Data::FileOrigin origin, bool faved); @@ -30,7 +30,7 @@ void ToggleRecentSticker( bool saved); void ToggleSavedGif( - Window::SessionController *controller, + std::shared_ptr show, not_null document, Data::FileOrigin origin, bool saved); diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index a589be4928..c60f968623 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -87,7 +87,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/emoji_config.h" #include "ui/chat/attach/attach_prepare.h" -#include "ui/toasts/common_toasts.h" +#include "ui/toast/toast.h" #include "support/support_helper.h" #include "settings/settings_premium.h" #include "storage/localimageloader.h" @@ -121,9 +121,16 @@ using UpdatedFileReferences = Data::UpdatedFileReferences; return TimeId(msgId >> 32); } -[[nodiscard]] std::shared_ptr ShowForPeer( +[[nodiscard]] std::shared_ptr ShowForPeer( not_null peer) { - return std::make_shared(Core::App().windowFor(peer)); + if (const auto window = Core::App().windowFor(peer)) { + if (const auto controller = window->sessionController()) { + if (&controller->session() == &peer->session()) { + return controller->uiShow(); + } + } + } + return nullptr; } void ShowChannelsLimitBox(not_null peer) { @@ -484,13 +491,12 @@ void ApiWrap::sendMessageFail( uint64 randomId, FullMsgId itemId) { const auto show = ShowForPeer(peer); - - if (error == u"PEER_FLOOD"_q) { + if (show && error == u"PEER_FLOOD"_q) { show->showBox( Ui::MakeInformBox( PeerFloodErrorText(&session(), PeerFloodType::Send)), Ui::LayerOption::CloseOther); - } else if (error == u"USER_BANNED_IN_CHANNEL"_q) { + } else if (show && error == u"USER_BANNED_IN_CHANNEL"_q) { const auto link = Ui::Text::Link( tr::lng_cant_more_info(tr::now), session().createInternalLinkFull(u"spambot"_q)); @@ -519,21 +525,16 @@ void ApiWrap::sendMessageFail( Assert(peer->isUser()); if (const auto item = scheduled.lookupItem(peer->id, itemId.msg)) { scheduled.removeSending(item); - show->showBox( - Ui::MakeInformBox(tr::lng_cant_do_this()), - Ui::LayerOption::CloseOther); - } - } else if (error == u"CHAT_FORWARDS_RESTRICTED"_q) { - if (show->valid()) { - Ui::ShowMultilineToast({ - .parentOverride = show->toastParent(), - .text = { peer->isBroadcast() - ? tr::lng_error_noforwards_channel(tr::now) - : tr::lng_error_noforwards_group(tr::now) - }, - .duration = kJoinErrorDuration - }); + if (show) { + show->showBox( + Ui::MakeInformBox(tr::lng_cant_do_this()), + Ui::LayerOption::CloseOther); + } } + } else if (show && error == u"CHAT_FORWARDS_RESTRICTED"_q) { + show->showToast(peer->isBroadcast() + ? tr::lng_error_noforwards_channel(tr::now) + : tr::lng_error_noforwards_group(tr::now), kJoinErrorDuration); } else if (error == u"PREMIUM_ACCOUNT_REQUIRED"_q) { Settings::ShowPremium(&session(), "premium_stickers"); } @@ -1702,12 +1703,8 @@ void ApiWrap::joinChannel(not_null channel) { } return QString(); }(); - if (!text.isEmpty() && show->valid()) { - Ui::ShowMultilineToast({ - .parentOverride = show->toastParent(), - .text = { text }, - .duration = kJoinErrorDuration, - }); + if (!text.isEmpty()) { + show->showToast(text, kJoinErrorDuration); } } _channelAmInRequests.remove(channel); @@ -2068,8 +2065,8 @@ void ApiWrap::applyAffectedMessages( } void ApiWrap::saveCurrentDraftToCloud() { + Core::App().materializeLocalDrafts(); for (const auto &controller : _session->windows()) { - controller->materializeLocalDrafts(); if (const auto thread = controller->activeChatCurrent().thread()) { const auto topic = thread->asTopic(); if (topic && topic->creating()) { diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 52908506c5..ccea61d70b 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -112,7 +112,7 @@ void ChatCreateDone( if (done) { done(chat); } else { - const auto show = std::make_shared(navigation); + const auto show = navigation->uiShow(); navigation->showPeerHistory(chat); ChatInviteForbidden( show, @@ -141,7 +141,7 @@ void MustBePublicFailed( const auto text = channel->isMegagroup() ? "Can't create a public group :(" : "Can't create a public channel :("; - Ui::Toast::Show(Window::Show(navigation).toastParent(), text); + navigation->showToast(text); MustBePublicDestroy(channel); } @@ -607,7 +607,7 @@ void GroupInfoBox::prepare() { : QString()); (*menu)->addAction( text, - [=, show = std::make_shared(this)] { + [=, show = uiShow()] { show->showBox(Box(TTLMenu::TTLBox, TTLMenu::Args{ .show = show, .startTtl = _ttlPeriod, @@ -727,19 +727,14 @@ void GroupInfoBox::createGroup( } } else if (type == u"USERS_TOO_FEW"_q) { controller->show( - Ui::MakeInformBox(tr::lng_cant_invite_privacy()), - Ui::LayerOption::KeepOther); + Ui::MakeInformBox(tr::lng_cant_invite_privacy())); } else if (type == u"PEER_FLOOD"_q) { - controller->show( - Ui::MakeInformBox( - PeerFloodErrorText( - &_navigation->session(), - PeerFloodType::InviteGroup)), - Ui::LayerOption::KeepOther); + controller->show(Ui::MakeInformBox( + PeerFloodErrorText( + &_navigation->session(), + PeerFloodType::InviteGroup))); } else if (type == u"USER_RESTRICTED"_q) { - controller->show( - Ui::MakeInformBox(tr::lng_cant_do_this()), - Ui::LayerOption::KeepOther); + controller->show(Ui::MakeInformBox(tr::lng_cant_do_this())); } }).send(); } @@ -1220,9 +1215,7 @@ void SetupChannelBox::mousePressEvent(QMouseEvent *e) { return; } else if (!_channel->inviteLink().isEmpty()) { QGuiApplication::clipboard()->setText(_channel->inviteLink()); - Ui::Toast::Show( - Ui::BoxShow(this).toastParent(), - tr::lng_create_channel_link_copied(tr::now)); + showToast(tr::lng_create_channel_link_copied(tr::now)); } else if (_channel->isFullLoaded() && !_creatingInviteLink) { _creatingInviteLink = true; _channel->session().api().inviteLinks().create(_channel); @@ -1456,12 +1449,10 @@ void SetupChannelBox::showRevokePublicLinkBoxForEdit() { const auto callback = [=] { *revoked = true; navigation->parentController()->show( - Box(navigation, channel, mustBePublic, done), - Ui::LayerOption::KeepOther); + Box(navigation, channel, mustBePublic, done)); }; const auto revoker = navigation->parentController()->show( - Box(PublicLinksLimitBox, navigation, callback), - Ui::LayerOption::KeepOther); + Box(PublicLinksLimitBox, navigation, callback)); const auto session = &navigation->session(); revoker->boxClosing( ) | rpl::start_with_next(crl::guard(session, [=] { diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index 2c7efa6cfa..e1262b4c9d 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -291,12 +291,10 @@ void BackgroundBox::chosen(const Data::WallPaper &paper) { } return; } - _controller->show( - Box( - _controller, - paper, - BackgroundPreviewArgs{ _forPeer }), - Ui::LayerOption::KeepOther); + _controller->show(Box( + _controller, + paper, + BackgroundPreviewArgs{ _forPeer })); } void BackgroundBox::resetForPeer() { @@ -332,13 +330,11 @@ void BackgroundBox::removePaper(const Data::WallPaper &paper) { paper.mtpSettings() )).send(); }; - _controller->show( - Ui::MakeConfirmBox({ - .text = tr::lng_background_sure_delete(), - .confirmed = remove, - .confirmText = tr::lng_selected_delete(), - }), - Ui::LayerOption::KeepOther); + _controller->show(Ui::MakeConfirmBox({ + .text = tr::lng_background_sure_delete(), + .confirmed = remove, + .confirmText = tr::lng_selected_delete(), + })); } BackgroundBox::Inner::Inner( diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 6f0ac7db2b..738a881655 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -640,9 +640,7 @@ void BackgroundPreviewBox::applyForEveryone() { void BackgroundPreviewBox::share() { QGuiApplication::clipboard()->setText( _paper.shareUrl(&_controller->session())); - Ui::Toast::Show( - Ui::BoxShow(this).toastParent(), - tr::lng_background_link_copied(tr::now)); + showToast(tr::lng_background_link_copied(tr::now)); } void BackgroundPreviewBox::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index bddf57c710..d9032c5a4c 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -280,15 +280,13 @@ void ChangePhone::EnterPhone::sendPhoneDone( } return 0; }(); - _controller->show( - Box( - _controller, - phoneNumber, - phoneCodeHash, - codeByFragmentUrl, - codeLength, - callTimeout), - Ui::LayerOption::KeepOther); + _controller->show(Box( + _controller, + phoneNumber, + phoneCodeHash, + codeByFragmentUrl, + codeLength, + callTimeout)); } void ChangePhone::EnterPhone::sendPhoneFail( @@ -426,17 +424,13 @@ void ChangePhone::EnterCode::submit(const QString &code) { MTP_string(_phone), MTP_string(_hash), MTP_string(code) - )).done([=, show = Window::Show(_controller)](const MTPUser &result) { + )).done([=, show = _controller->uiShow()](const MTPUser &result) { _requestId = 0; session->data().processUser(result); - if (show.valid()) { - if (weak) { - show.hideLayer(); - } - Ui::Toast::Show( - show.toastParent(), - tr::lng_change_phone_success(tr::now)); + if (weak) { + show->hideLayer(); } + show->showToast(tr::lng_change_phone_success(tr::now)); }).fail(crl::guard(this, [=](const MTP::Error &error) { _requestId = 0; sendCodeFail(error); diff --git a/Telegram/SourceFiles/boxes/choose_filter_box.cpp b/Telegram/SourceFiles/boxes/choose_filter_box.cpp index 6ea39d2e25..ef6b8ecb21 100644 --- a/Telegram/SourceFiles/boxes/choose_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/choose_filter_box.cpp @@ -17,9 +17,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "ui/filter_icons.h" #include "ui/text/text_utilities.h" // Ui::Text::Bold -#include "ui/toast/toast.h" #include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" +#include "window/window_controller.h" #include "window/window_session_controller.h" #include "styles/style_settings.h" #include "styles/style_payments.h" // paymentsSectionButton @@ -74,7 +74,7 @@ void ChangeFilterById( // We can safely show toast there. const auto account = &history->session().account(); if (const auto controller = Core::App().windowFor(account)) { - auto text = (add + controller->showToast((add ? tr::lng_filters_toast_add : tr::lng_filters_toast_remove)( tr::now, @@ -82,10 +82,7 @@ void ChangeFilterById( Ui::Text::Bold(chat), lt_folder, Ui::Text::Bold(name), - Ui::Text::WithEntities); - Ui::Toast::Show( - Window::Show(controller).toastParent(), - { .text = std::move(text), .st = &st::defaultToast }); + Ui::Text::WithEntities)); } }).fail([=](const MTP::Error &error) { // Revert filter on fail. diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 7c27f59edc..626671cb4c 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -1265,7 +1265,7 @@ object_ptr ProxiesBoxController::CreateOwningBox( object_ptr ProxiesBoxController::create() { auto result = Box(this, _settings); - _show = std::make_shared(result.data()); + _show = result->uiShow(); for (const auto &item : _list) { updateView(item); } @@ -1548,9 +1548,7 @@ void ProxiesBoxController::share(const ProxyData &proxy) { + ((proxy.type == Type::Mtproto && !proxy.password.isEmpty()) ? "&secret=" + proxy.password : ""); QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show( - _show->toastParent(), - tr::lng_username_copied(tr::now)); + _show->showToast(tr::lng_username_copied(tr::now)); } ProxiesBoxController::~ProxiesBoxController() { diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 775e5b7f55..ca1eb70f3b 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -775,7 +775,7 @@ void CreatePollBox::setInnerFocus() { } void CreatePollBox::submitFailed(const QString &error) { - Ui::Toast::Show(Ui::BoxShow(this).toastParent(), error); + showToast(error); } not_null CreatePollBox::setupQuestion( @@ -850,10 +850,7 @@ not_null CreatePollBox::setupSolution( Core::App().settings().replaceEmojiValue()); solution->setMarkdownReplacesEnabled(rpl::single(true)); solution->setEditLinkCallback( - DefaultEditLinkCallback( - std::make_shared(_controller), - session, - solution)); + DefaultEditLinkCallback(_controller->uiShow(), solution)); solution->customTab(true); const auto warning = CreateWarningLabel( @@ -988,12 +985,10 @@ object_ptr CreatePollBox::setupContent() { || (_chosen & PollData::Flag::Quiz)); multiple->events( ) | rpl::filter([=](not_null e) { - return (e->type() == QEvent::MouseButtonPress) && quiz->checked(); - }) | rpl::start_with_next([ - toastParent = Ui::BoxShow(this).toastParent()] { - Ui::Toast::Show( - toastParent, - tr::lng_polls_create_one_answer(tr::now)); + return (e->type() == QEvent::MouseButtonPress) + && quiz->checked(); + }) | rpl::start_with_next([show = uiShow()] { + show->showToast(tr::lng_polls_create_one_answer(tr::now)); }, multiple->lifetime()); } @@ -1070,10 +1065,9 @@ object_ptr CreatePollBox::setupContent() { *error &= ~Error::Solution; } }; - const auto showError = [ - toastParent = Ui::BoxShow(this).toastParent()]( + const auto showError = [show = uiShow()]( tr::phrase<> text) { - Ui::Toast::Show(toastParent, text(tr::now)); + show->showToast(text(tr::now)); }; const auto send = [=](Api::SendOptions sendOptions) { collectError(); @@ -1099,8 +1093,7 @@ object_ptr CreatePollBox::setupContent() { HistoryView::PrepareScheduleBox( this, SendMenu::Type::Scheduled, - send), - Ui::LayerOption::KeepOther); + send)); }; const auto sendWhenOnline = [=] { send(Api::DefaultSendWhenOnlineOptions()); diff --git a/Telegram/SourceFiles/boxes/delete_messages_box.cpp b/Telegram/SourceFiles/boxes/delete_messages_box.cpp index 28a4ad97ba..99fe6b8835 100644 --- a/Telegram/SourceFiles/boxes/delete_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/delete_messages_box.cpp @@ -285,7 +285,7 @@ void DeleteMessagesBox::prepare() { if (_wipeHistoryJustClear && _wipeHistoryPeer) { const auto validator = TTLMenu::TTLValidator( - std::make_shared(this), + uiShow(), _wipeHistoryPeer); if (validator.can()) { _wipeHistoryPeer->updateFull(); diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 1642a3d8a1..41f19a0b82 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -129,7 +129,7 @@ void ChooseReplacement( } const auto showError = [=](tr::phrase<> t) { if (const auto strong = weak.get()) { - strong->showToast({ t(tr::now) }); + strong->showToast(t(tr::now)); } }; @@ -304,7 +304,7 @@ void EditCaptionBox::StartMediaReplace( } const auto type = ComputeAlbumType(item); const auto showError = [=](tr::phrase<> t) { - controller->showToast({ t(tr::now) }); + controller->showToast(t(tr::now)); }; const auto checkResult = [=](const Ui::PreparedList &list) { if (list.files.size() != 1) { @@ -647,7 +647,7 @@ void EditCaptionBox::setupEmojiPanel() { _controller, object_ptr( nullptr, - _controller, + _controller->uiShow(), Window::GifPauseReason::Layer, Selector::Mode::EmojiOnly)); _emojiPanel->setDesiredHeightValues( @@ -728,9 +728,7 @@ bool EditCaptionBox::setPreparedList(Ui::PreparedList &&list) { } } if (invalidForAlbum) { - Ui::Toast::Show( - Ui::BoxShow(this).toastParent(), - tr::lng_edit_media_album_error(tr::now)); + showToast(tr::lng_edit_media_album_error(tr::now)); return false; } const auto wasSpoiler = hasSpoiler(); diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index 86e531c617..dfa6b3707c 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -167,8 +167,7 @@ void EditPrivacyBox::editExceptions( box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; _window->show( - Box(std::move(controller), std::move(initBox)), - Ui::LayerOption::KeepOther); + Box(std::move(controller), std::move(initBox))); } std::vector> &EditPrivacyBox::exceptions(Exception exception) { diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp index 9e0e67514f..e135fd691b 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp @@ -386,10 +386,7 @@ void EditExceptions( box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; window->window().show( - Box( - std::move(controller), - std::move(initBox)), - Ui::LayerOption::KeepOther); + Box(std::move(controller), std::move(initBox))); } void CreateIconSelector( @@ -812,7 +809,7 @@ void EditFilterBox( tr::lng_filters_link_about_many(), tr::lng_filters_link_about())); - const auto show = std::make_shared(box); + const auto show = box->uiShow(); const auto refreshPreviews = [=] { include->updateData( data->current().flags() & kTypes, diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp index c9ad2bcbe6..d7e2c09206 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_links.cpp @@ -25,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/controls/invite_link_buttons.h" #include "ui/controls/invite_link_label.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/popup_menu.h" @@ -118,7 +117,7 @@ void ShowSaveError( window->showToast( { tr::lng_filters_link_group_admin_error(tr::now) }); } else { - window->showToast({ error }); + window->showToast(error); } } @@ -583,27 +582,22 @@ void LinkController::addLinkBlock(not_null container) { const auto link = _data.url; const auto weak = Ui::MakeWeak(container); const auto copyLink = crl::guard(weak, [=] { - CopyInviteLink(delegate()->peerListToastParent(), link); + CopyInviteLink(delegate()->peerListUiShow(), link); }); const auto shareLink = crl::guard(weak, [=] { delegate()->peerListShowBox( - ShareInviteLinkBox(&_window->session(), link), - Ui::LayerOption::KeepOther); + ShareInviteLinkBox(&_window->session(), link)); }); const auto getLinkQr = crl::guard(weak, [=] { delegate()->peerListShowBox( - InviteLinkQrBox(link, tr::lng_filters_link_qr_about()), - Ui::LayerOption::KeepOther); + InviteLinkQrBox(link, tr::lng_filters_link_qr_about())); }); const auto editLink = crl::guard(weak, [=] { delegate()->peerListShowBox( - Box(ChatFilterLinkBox, &_window->session(), _data), - Ui::LayerOption::KeepOther); + Box(ChatFilterLinkBox, &_window->session(), _data)); }); const auto deleteLink = crl::guard(weak, [=] { - delegate()->peerListShowBox( - DeleteLinkBox(_window, _data), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(DeleteLinkBox(_window, _data)); }); const auto createMenu = [=] { @@ -702,10 +696,7 @@ void LinkController::rowClicked(not_null row) { const auto peer = row->peer(); if (const auto i = _denied.find(peer); i != end(_denied)) { if (!i->second.isEmpty()) { - Ui::ShowMultilineToast({ - .parentOverride = delegate()->peerListToastParent(), - .text = { i->second }, - }); + delegate()->peerListUiShow()->showToast(i->second); } } else { const auto checked = row->checked(); @@ -866,8 +857,7 @@ void LinksController::rebuild(const std::vector &rows) { void LinksController::rowClicked(not_null row) { const auto link = static_cast(row.get())->data(); delegate()->peerListShowBox( - ShowLinkBox(_window, _currentFilter(), link), - Ui::LayerOption::KeepOther); + ShowLinkBox(_window, _currentFilter(), link)); } void LinksController::rowRightActionClicked(not_null row) { @@ -898,27 +888,22 @@ base::unique_qptr LinksController::createRowContextMenu( const auto data = real->data(); const auto link = data.url; const auto copyLink = [=] { - CopyInviteLink(delegate()->peerListToastParent(), link); + CopyInviteLink(delegate()->peerListUiShow(), link); }; const auto shareLink = [=] { delegate()->peerListShowBox( - ShareInviteLinkBox(&_window->session(), link), - Ui::LayerOption::KeepOther); + ShareInviteLinkBox(&_window->session(), link)); }; const auto getLinkQr = [=] { delegate()->peerListShowBox( - InviteLinkQrBox(link, tr::lng_filters_link_qr_about()), - Ui::LayerOption::KeepOther); + InviteLinkQrBox(link, tr::lng_filters_link_qr_about())); }; const auto editLink = [=] { delegate()->peerListShowBox( - Box(ChatFilterLinkBox, &_window->session(), data), - Ui::LayerOption::KeepOther); + Box(ChatFilterLinkBox, &_window->session(), data)); }; const auto deleteLink = [=] { - delegate()->peerListShowBox( - DeleteLinkBox(_window, data), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(DeleteLinkBox(_window, data)); }; auto result = base::make_unique_q( parent, @@ -1008,10 +993,7 @@ bool GoodForExportFilterLink( using Flag = Data::ChatFilter::Flag; const auto listflags = Flag::Chatlist | Flag::HasMyLinks; if (!filter.never().empty() || (filter.flags() & ~listflags)) { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(window).toastParent(), - .text = { tr::lng_filters_link_cant(tr::now) }, - }); + window->showToast(tr::lng_filters_link_cant(tr::now)); return false; } return true; @@ -1151,7 +1133,7 @@ void SetupFilterLinks( Fn currentFilter) { auto &lifetime = container->lifetime(); const auto delegate = lifetime.make_state( - std::make_shared(window)); + window->uiShow()); const auto controller = lifetime.make_state( window, std::move(value), diff --git a/Telegram/SourceFiles/boxes/language_box.cpp b/Telegram/SourceFiles/boxes/language_box.cpp index 7ce2731d1e..dca50a08c2 100644 --- a/Telegram/SourceFiles/boxes/language_box.cpp +++ b/Telegram/SourceFiles/boxes/language_box.cpp @@ -1248,7 +1248,7 @@ void LanguageBox::setupTop(not_null container) { st::settingsButtonNoIcon); translateSkip->setClickedCallback([=] { - Ui::BoxShow(this).showBox(Ui::EditSkipTranslationLanguages()); + uiShow()->showBox(Ui::EditSkipTranslationLanguages()); }); Settings::AddSkip(container); Settings::AddDividerText( diff --git a/Telegram/SourceFiles/boxes/max_invite_box.cpp b/Telegram/SourceFiles/boxes/max_invite_box.cpp index 7c8f290926..b6230b673e 100644 --- a/Telegram/SourceFiles/boxes/max_invite_box.cpp +++ b/Telegram/SourceFiles/boxes/max_invite_box.cpp @@ -91,9 +91,7 @@ void MaxInviteBox::mousePressEvent(QMouseEvent *e) { if (_linkOver) { if (!_channel->inviteLink().isEmpty()) { QGuiApplication::clipboard()->setText(_channel->inviteLink()); - Ui::Toast::Show( - Ui::BoxShow(this).toastParent(), - tr::lng_create_channel_link_copied(tr::now)); + showToast(tr::lng_create_channel_link_copied(tr::now)); } else if (_channel->isFullLoaded() && !_creatingInviteLink) { _creatingInviteLink = true; _channel->session().api().inviteLinks().create(_channel); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index b59145ec0e..66f10501a2 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/peer_list_box.h" +#include "main/session/session_show.h" #include "main/main_session.h" #include "mainwidget.h" #include "ui/widgets/multi_select.h" @@ -74,7 +75,7 @@ PaintRoundImageCallback ForceRoundUserpicCallback(not_null peer) { } PeerListContentDelegateShow::PeerListContentDelegateShow( - std::shared_ptr show) + std::shared_ptr show) : _show(show) { } @@ -88,15 +89,16 @@ void PeerListContentDelegateShow::peerListHideLayer() { _show->hideLayer(); } -not_null PeerListContentDelegateShow::peerListToastParent() { - return _show->toastParent(); +auto PeerListContentDelegateShow::peerListUiShow() +-> std::shared_ptr{ + return _show; } PeerListBox::PeerListBox( QWidget*, std::unique_ptr controller, Fn)> init) -: _show(this) +: _show(Main::MakeSessionShow(uiShow(), &controller->session())) , _controller(std::move(controller)) , _init(std::move(init)) { Expects(_controller != nullptr); @@ -311,18 +313,20 @@ void PeerListBox::peerListSetSearchMode(PeerListSearchMode mode) { void PeerListBox::peerListShowBox( object_ptr content, Ui::LayerOptions options) { - _show.showBox(std::move(content), options); + _show->showBox(std::move(content), options); } void PeerListBox::peerListHideLayer() { - _show.hideLayer(); + _show->hideLayer(); } -not_null PeerListBox::peerListToastParent() { - return _show.toastParent(); +std::shared_ptr PeerListBox::peerListUiShow() { + return _show; } -PeerListController::PeerListController(std::unique_ptr searchController) : _searchController(std::move(searchController)) { +PeerListController::PeerListController( + std::unique_ptr searchController) +: _searchController(std::move(searchController)) { if (_searchController) { _searchController->setDelegate(this); } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index c641fc33c2..28cb695341 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -24,6 +24,7 @@ struct MultiSelect; namespace Main { class Session; +class SessionShow; } // namespace Main namespace Ui { @@ -329,7 +330,7 @@ public: object_ptr content, Ui::LayerOptions options = Ui::LayerOption::KeepOther) = 0; virtual void peerListHideLayer() = 0; - virtual not_null peerListToastParent() = 0; + virtual std::shared_ptr peerListUiShow() = 0; template void peerListAddSelectedPeers(PeerDataRange &&range) { @@ -999,22 +1000,24 @@ public: void peerListHideLayer() override { Unexpected("...DelegateSimple::peerListHideLayer"); } - not_null peerListToastParent() override { - Unexpected("...DelegateSimple::peerListToastParent"); + std::shared_ptr peerListUiShow() override { + Unexpected("...DelegateSimple::peerListUiShow"); } }; class PeerListContentDelegateShow : public PeerListContentDelegateSimple { public: - PeerListContentDelegateShow(std::shared_ptr show); + explicit PeerListContentDelegateShow( + std::shared_ptr show); void peerListShowBox( object_ptr content, Ui::LayerOptions options = Ui::LayerOption::KeepOther) override; void peerListHideLayer() override; - not_null peerListToastParent() override; + std::shared_ptr peerListUiShow() override; + private: - std::shared_ptr _show; + std::shared_ptr _show; }; @@ -1050,7 +1053,7 @@ public: object_ptr content, Ui::LayerOptions options = Ui::LayerOption::KeepOther) override; void peerListHideLayer() override; - not_null peerListToastParent() override; + std::shared_ptr peerListUiShow() override; void setAddedTopScrollSkip(int skip); @@ -1092,7 +1095,7 @@ private: object_ptr> _select = { nullptr }; - const Ui::BoxShow _show; + const std::shared_ptr _show; std::unique_ptr _controller; Fn _init; bool _scrollBottomFixed = false; diff --git a/Telegram/SourceFiles/boxes/peer_lists_box.cpp b/Telegram/SourceFiles/boxes/peer_lists_box.cpp index 9c65f294bc..e445a21e22 100644 --- a/Telegram/SourceFiles/boxes/peer_lists_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_lists_box.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "ui/widgets/multi_select.h" #include "ui/widgets/scroll_area.h" +#include "main/session/session_show.h" #include "main/main_session.h" #include "data/data_session.h" #include "data/data_peer.h" @@ -301,7 +302,7 @@ PeerListsBox::Delegate::Delegate( not_null controller) : _box(box) , _controller(controller) -, _show(_box) { +, _show(Main::MakeSessionShow(_box->uiShow(), &_controller->session())) { } void PeerListsBox::Delegate::peerListSetTitle(rpl::producer title) { @@ -374,15 +375,16 @@ void PeerListsBox::Delegate::peerListFinishSelectedRowsBunch() { void PeerListsBox::Delegate::peerListShowBox( object_ptr content, Ui::LayerOptions options) { - _show.showBox(std::move(content), options); + _show->showBox(std::move(content), options); } void PeerListsBox::Delegate::peerListHideLayer() { - _show.hideLayer(); + _show->hideLayer(); } -not_null PeerListsBox::Delegate::peerListToastParent() { - return _show.toastParent(); +auto PeerListsBox::Delegate::peerListUiShow() +-> std::shared_ptr { + return _show; } bool PeerListsBox::Delegate::peerListIsRowChecked( diff --git a/Telegram/SourceFiles/boxes/peer_lists_box.h b/Telegram/SourceFiles/boxes/peer_lists_box.h index fcbbd984e7..94732b3e24 100644 --- a/Telegram/SourceFiles/boxes/peer_lists_box.h +++ b/Telegram/SourceFiles/boxes/peer_lists_box.h @@ -58,12 +58,12 @@ private: object_ptr content, Ui::LayerOptions options = Ui::LayerOption::KeepOther) override; void peerListHideLayer() override; - not_null peerListToastParent() override; + std::shared_ptr peerListUiShow() override; private: const not_null _box; const not_null _controller; - const Ui::BoxShow _show; + const std::shared_ptr _show; }; struct List { diff --git a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp index 6f11e05937..1bffcb2eed 100644 --- a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp @@ -182,8 +182,7 @@ void AddBotToGroupBoxController::addBotToGroup(not_null chat) { if (const auto megagroup = chat->asMegagroup()) { if (!megagroup->canAddMembers()) { _controller->show( - Ui::MakeInformBox(tr::lng_error_cant_add_member()), - Ui::LayerOption::KeepOther); + Ui::MakeInformBox(tr::lng_error_cant_add_member())); return; } } @@ -243,18 +242,16 @@ void AddBotToGroupBoxController::addBotToGroup(not_null chat) { _token, _existingRights.value_or(ChatAdminRights()) }); box->setSaveCallback(saveCallback); - controller->show(std::move(box), Ui::LayerOption::KeepOther); + controller->show(std::move(box)); } else { auto callback = crl::guard(this, [=] { AddBotToGroup(bot, chat, _token); controller->hideLayer(); }); - controller->show( - Ui::MakeConfirmBox({ - tr::lng_bot_sure_invite(tr::now, lt_group, chat->name()), - std::move(callback), - }), - Ui::LayerOption::KeepOther); + controller->show(Ui::MakeConfirmBox({ + tr::lng_bot_sure_invite(tr::now, lt_group, chat->name()), + std::move(callback), + })); } } diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index a7b3a6a2fd..b40e1a0d29 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -202,9 +202,7 @@ void InviteForbiddenController::send( int(list.size()), Ui::Text::RichLangValue); close(); - Ui::Toast::Show( - show->toastParent(), - { .text = std::move(text), .st = &st::defaultToast }); + show->showToast(std::move(text)); return true; }; const auto sendForFull = [=] { @@ -368,7 +366,7 @@ bool AddParticipantsBoxController::needsInviteLinkButton() { QPointer AddParticipantsBoxController::showBox( object_ptr box) const { const auto weak = Ui::MakeWeak(box.data()); - delegate()->peerListShowBox(std::move(box), Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(std::move(box)); return weak; } @@ -425,7 +423,7 @@ void AddParticipantsBoxController::inviteSelectedUsers( if (users.empty()) { return; } - const auto show = std::make_shared(box); + const auto show = box->uiShow(); const auto request = [=](bool checked) { _peer->session().api().chatParticipants().add( _peer, @@ -493,9 +491,8 @@ void AddParticipantsBoxController::Start( }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; - Window::Show(navigation).showBox( - Box(std::move(controller), std::move(initBox)), - Ui::LayerOption::KeepOther); + parent->show( + Box(std::move(controller), std::move(initBox))); } void AddParticipantsBoxController::Start( @@ -538,9 +535,8 @@ void AddParticipantsBoxController::Start( }, box->lifetime()); } }; - Window::Show(navigation).showBox( - Box(std::move(controller), std::move(initBox)), - Ui::LayerOption::KeepOther); + parent->show( + Box(std::move(controller), std::move(initBox))); } void AddParticipantsBoxController::Start( @@ -616,7 +612,7 @@ bool ChatInviteForbidden( box->addButton(tr::lng_via_link_send(), [=] { weak->send( box->collectSelectedRows(), - std::make_shared(box), + box->uiShow(), crl::guard(box, [=] { box->closeBox(); })); }); } @@ -626,8 +622,7 @@ bool ChatInviteForbidden( }, box->lifetime()); }; show->showBox( - Box(std::move(controller), std::move(initBox)), - Ui::LayerOption::KeepOther); + Box(std::move(controller), std::move(initBox))); return true; } @@ -673,7 +668,7 @@ void AddSpecialBoxController::migrate( QPointer AddSpecialBoxController::showBox( object_ptr box) const { const auto weak = Ui::MakeWeak(box.data()); - delegate()->peerListShowBox(std::move(box), Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(std::move(box)); return weak; } diff --git a/Telegram/SourceFiles/boxes/peers/choose_peer_box.cpp b/Telegram/SourceFiles/boxes/peers/choose_peer_box.cpp index 91ce22ef89..60031e0cef 100644 --- a/Telegram/SourceFiles/boxes/peers/choose_peer_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/choose_peer_box.cpp @@ -505,5 +505,5 @@ void ShowChoosePeerBox( bot, query, std::move(callback)), - std::move(initBox)), Ui::LayerOption::KeepOther); + std::move(initBox))); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp index 89115f0bf5..0aa24c79e1 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp @@ -69,8 +69,7 @@ void SendRequest( } if (box) { if (!wasContact) { - Ui::Toast::Show( - Ui::BoxShow(box.data()).toastParent(), + box->showToast( tr::lng_new_contact_add_done(tr::now, lt_user, first)); } box->closeBox(); diff --git a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp index 400fcb95ac..9727f6c615 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp @@ -274,12 +274,9 @@ struct IconSelector { }; const auto selector = body->add( object_ptr(body, EmojiListDescriptor{ - .session = &controller->session(), + .show = controller->uiShow(), .mode = EmojiListWidget::Mode::TopicIcon, - .controller = controller, - .paused = Window::PausedIn( - controller, - Window::GifPauseReason::Layer), + .paused = Window::PausedIn(controller, PauseReason::Layer), .customRecentList = recent(), .customRecentFactory = std::move(factory), .st = &st::reactPanelEmojiPan, diff --git a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp index cdba89701e..9e0bfa2d9f 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp @@ -18,7 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" // Ui::Text::ToUpper #include "boxes/peer_list_box.h" #include "ui/boxes/confirm_box.h" -#include "ui/toasts/common_toasts.h" #include "boxes/add_contact_box.h" #include "apiwrap.h" #include "main/main_session.h" @@ -168,13 +167,11 @@ void Controller::choose(not_null chat) { const auto onstack = _callback; onstack(chat); }; - delegate()->peerListShowBox( - Ui::MakeConfirmBox({ - .text = text, - .confirmed = sure, - .confirmText = tr::lng_manage_discussion_group_link(tr::now), - }), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(Ui::MakeConfirmBox({ + .text = text, + .confirmed = sure, + .confirmText = tr::lng_manage_discussion_group_link(tr::now), + })); } void Controller::choose(not_null chat) { @@ -201,13 +198,11 @@ void Controller::choose(not_null chat) { }; chat->session().api().migrateChat(chat, crl::guard(this, done)); }; - delegate()->peerListShowBox( - Ui::MakeConfirmBox({ - .text = text, - .confirmed = sure, - .confirmText = tr::lng_manage_discussion_group_link(tr::now), - }), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(Ui::MakeConfirmBox({ + .text = text, + .confirmed = sure, + .confirmText = tr::lng_manage_discussion_group_link(tr::now), + })); } [[nodiscard]] rpl::producer About( @@ -279,13 +274,11 @@ void Controller::choose(not_null chat) { { &st::settingsIconChat, Settings::kIconLightBlue } )->addClickHandler([=, parent = above.data()] { const auto guarded = crl::guard(parent, callback); - Window::Show(navigation).showBox( - Box( - navigation, - GroupInfoBox::Type::Megagroup, - channel->name() + " Chat", - guarded), - Ui::LayerOption::KeepOther); + navigation->uiShow()->showBox(Box( + navigation, + GroupInfoBox::Type::Megagroup, + channel->name() + " Chat", + guarded)); }); } box->peerListSetAboveWidget(std::move(above)); @@ -363,10 +356,8 @@ object_ptr EditLinkedChatBox( void ShowForumForDiscussionError( not_null navigation) { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(navigation).toastParent(), - .text = tr::lng_forum_topics_no_discussion( + navigation->showToast( + tr::lng_forum_topics_no_discussion( tr::now, - Ui::Text::RichLangValue), - }); + Ui::Text::RichLangValue)); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 7006606ce3..f47beae756 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -203,7 +203,6 @@ EditAdminBox::EditAdminBox( peer, user, (rights.flags != 0)) -, _show(this) , _oldRights(rights) , _oldRank(rank) , _addingBot(std::move(addingBot)) { @@ -399,7 +398,7 @@ void EditAdminBox::prepare() { Ui::Text::Bold(peer()->name()), Ui::Text::WithEntities), crl::guard(this, [=] { finishAddAdmin(); }) - }), Ui::LayerOption::KeepOther); + })); } else { _finishSave(); } @@ -623,16 +622,15 @@ void EditAdminBox::sendTransferRequestFrom( if (!box && !weak) { return; } - - Ui::Toast::Show( - (box ? Ui::BoxShow(box) : weak->_show).toastParent(), + const auto show = box ? box->uiShow() : weak->uiShow(); + show->showToast( (channel->isBroadcast() ? tr::lng_rights_transfer_done_channel : tr::lng_rights_transfer_done_group)( tr::now, lt_user, user->shortName())); - (box ? Ui::BoxShow(box) : weak->_show).hideLayer(); + show->hideLayer(); }).fail(crl::guard(this, [=](const MTP::Error &error) { if (weak) { _transferRequestId = 0; @@ -694,7 +692,6 @@ EditRestrictedBox::EditRestrictedBox( bool hasAdminRights, ChatRestrictionsInfo rights) : EditParticipantBox(nullptr, peer, user, hasAdminRights) -, _show(this) , _oldRights(rights) { } @@ -788,7 +785,7 @@ ChatRestrictionsInfo EditRestrictedBox::defaultRights() const { } void EditRestrictedBox::showRestrictUntil() { - _show.showBox(Box([=](not_null box) { + uiShow()->showBox(Box([=](not_null box) { const auto save = [=](TimeId result) { if (!result) { return; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.h b/Telegram/SourceFiles/boxes/peers/edit_participant_box.h index 4deda7ac90..b770730d5f 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.h @@ -114,7 +114,6 @@ private: not_null container, bool isGroup); - const Ui::BoxShow _show; const ChatAdminRightsInfo _oldRights; const QString _oldRank; Fn _saveCallback; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index c9d759cdd8..94caec1503 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1254,7 +1254,7 @@ void ParticipantsBoxController::rebuild() { QPointer ParticipantsBoxController::showBox( object_ptr box) const { const auto weak = Ui::MakeWeak(box.data()); - delegate()->peerListShowBox(std::move(box), Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(std::move(box)); return weak; } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 41b37a17ee..febf08ed66 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -48,7 +48,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/controls/userpic_button.h" #include "ui/rp_widget.h" #include "ui/toast/toast.h" -#include "ui/toasts/common_toasts.h" #include "ui/text/text_utilities.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" @@ -241,9 +240,7 @@ void ShowEditPermissions( }; ShowEditPeerPermissionsBox(box, navigation, peer, std::move(done)); }; - navigation->parentController()->show( - Box(std::move(createBox)), - Ui::LayerOption::KeepOther); + navigation->parentController()->show(Box(std::move(createBox))); } } // namespace @@ -606,8 +603,7 @@ object_ptr Controller::createStickersEdit() { rpl::single(QString()), //Empty count. [=, controller = _navigation->parentController()] { controller->show( - Box(controller, channel), - Ui::LayerOption::KeepOther); + Box(controller->uiShow(), channel)); }, { &st::settingsIconStickers, Settings::kIconLightOrange }); @@ -674,8 +670,7 @@ void Controller::showEditPeerTypeBox( _channelHasLocationOriginalValue, boxCallback, _typeDataSavedValue, - error), - Ui::LayerOption::KeepOther); + error)); box->boxClosing( ) | rpl::start_with_next([peer = _peer] { peer->session().api().usernames().requestToCache(peer); @@ -709,14 +704,12 @@ void Controller::showEditLinkedChatBox() { || channel->canEditPreHistoryHidden())); if (const auto chat = *_linkedChatSavedValue) { - *box = _navigation->parentController()->show( - EditLinkedChatBox( - _navigation, - channel, - chat, - canEdit, - callback), - Ui::LayerOption::KeepOther); + *box = _navigation->parentController()->show(EditLinkedChatBox( + _navigation, + channel, + chat, + canEdit, + callback)); return; } else if (!canEdit || _linkedChatsRequestId) { return; @@ -743,13 +736,11 @@ void Controller::showEditLinkedChatBox() { for (const auto &item : list) { chats.emplace_back(_peer->owner().processChat(item)); } - *box = _navigation->parentController()->show( - EditLinkedChatBox( - _navigation, - channel, - std::move(chats), - callback), - Ui::LayerOption::KeepOther); + *box = _navigation->parentController()->show(EditLinkedChatBox( + _navigation, + channel, + std::move(chats), + callback)); }).fail([=] { _linkedChatsRequestId = 0; }).send(); @@ -887,14 +878,12 @@ void Controller::fillForumButton() { if (_linkedChatSavedValue && *_linkedChatSavedValue) { ShowForumForDiscussionError(_navigation); } else { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(_navigation).toastParent(), - .text = tr::lng_forum_topics_not_enough( + _navigation->showToast( + tr::lng_forum_topics_not_enough( tr::now, lt_count, EnableForumMinMembers(_peer), - Ui::Text::RichLangValue), - }); + Ui::Text::RichLangValue)); } } else { _forumSavedValue = toggled; @@ -1231,14 +1220,12 @@ void Controller::fillManageSection() { tr::lng_manage_peer_invite_links(), rpl::duplicate(count) | ToPositiveNumberString(), [=] { - _navigation->parentController()->show( - Box( - ManageInviteLinksBox, - _peer, - _peer->session().user(), - 0, - 0), - Ui::LayerOption::KeepOther); + _navigation->parentController()->show(Box( + ManageInviteLinksBox, + _peer, + _peer->session().user(), + 0, + 0)); }, { &st::infoRoundedIconInviteLinks, Settings::kIconLightOrange }); wrap->toggle(true, anim::type::instant); @@ -1407,9 +1394,7 @@ void Controller::fillBotUsernamesButton() { std::move(leftLabel), std::move(rightLabel), [=] { - Window::Show(_navigation).showBox( - Box(UsernamesBox, user), - Ui::LayerOption::KeepOther); + _navigation->uiShow()->showBox(Box(UsernamesBox, user)); }, { &st::infoRoundedIconInviteLinks, Settings::kIconLightOrange }); } @@ -2120,8 +2105,7 @@ void Controller::deleteWithConfirmation() { .confirmed = deleteCallback, .confirmText = tr::lng_box_delete(), .confirmStyle = &st::attentionBoxButton, - }), - Ui::LayerOption::KeepOther); + })); } void Controller::deleteChannel() { diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp index 0d38443627..00f9eac3f2 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp @@ -26,7 +26,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/abstract_button.h" #include "ui/toast/toast.h" -#include "ui/toasts/common_toasts.h" #include "ui/text/text_utilities.h" #include "ui/boxes/edit_invite_link.h" #include "ui/painter.h" @@ -275,12 +274,12 @@ void QrBox( not_null box, const QString &link, rpl::producer about, - Fn)> share) { + Fn)> share) { box->setTitle(tr::lng_group_invite_qr_title()); box->addButton(tr::lng_about_done(), [=] { box->closeBox(); }); - const auto copyCallback = [=, show = std::make_shared(box)] { + const auto copyCallback = [=, show = box->uiShow()] { share(QrForShare(link), show); }; @@ -346,32 +345,23 @@ void Controller::addHeaderBlock(not_null container) { const auto admin = current.admin; const auto weak = Ui::MakeWeak(container); const auto copyLink = crl::guard(weak, [=] { - CopyInviteLink(delegate()->peerListToastParent(), link); + CopyInviteLink(delegate()->peerListUiShow(), link); }); const auto shareLink = crl::guard(weak, [=] { - delegate()->peerListShowBox( - ShareInviteLinkBox(_peer, link), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(ShareInviteLinkBox(_peer, link)); }); const auto getLinkQr = crl::guard(weak, [=] { delegate()->peerListShowBox( - InviteLinkQrBox(link, tr::lng_group_invite_qr_about()), - Ui::LayerOption::KeepOther); + InviteLinkQrBox(link, tr::lng_group_invite_qr_about())); }); const auto revokeLink = crl::guard(weak, [=] { - delegate()->peerListShowBox( - RevokeLinkBox(_peer, admin, link), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(RevokeLinkBox(_peer, admin, link)); }); const auto editLink = crl::guard(weak, [=] { - delegate()->peerListShowBox( - EditLinkBox(_peer, _data.current()), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(EditLinkBox(_peer, _data.current())); }); const auto deleteLink = crl::guard(weak, [=] { - delegate()->peerListShowBox( - DeleteLinkBox(_peer, admin, link), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(DeleteLinkBox(_peer, admin, link)); }); const auto createMenu = [=] { @@ -809,16 +799,13 @@ void Controller::processRequest( delegate()->peerListRefreshRows(); } if (approved) { - Ui::ShowMultilineToast({ - .parentOverride = delegate()->peerListToastParent(), - .text = (_peer->isBroadcast() - ? tr::lng_group_requests_was_added_channel - : tr::lng_group_requests_was_added)( - tr::now, - lt_user, - Ui::Text::Bold(user->name()), - Ui::Text::WithEntities) - }); + delegate()->peerListUiShow()->showToast((_peer->isBroadcast() + ? tr::lng_group_requests_was_added_channel + : tr::lng_group_requests_was_added)( + tr::now, + lt_user, + Ui::Text::Bold(user->name()), + Ui::Text::WithEntities)); } }); const auto fail = crl::guard(this, [=] { @@ -961,30 +948,24 @@ void AddPermanentLinkBlock( const auto weak = Ui::MakeWeak(container); const auto copyLink = crl::guard(weak, [=] { if (const auto current = value->current(); !current.link.isEmpty()) { - CopyInviteLink(show->toastParent(), current.link); + CopyInviteLink(show, current.link); } }); const auto shareLink = crl::guard(weak, [=] { if (const auto current = value->current(); !current.link.isEmpty()) { - show->showBox( - ShareInviteLinkBox(peer, current.link), - Ui::LayerOption::KeepOther); + show->showBox(ShareInviteLinkBox(peer, current.link)); } }); const auto getLinkQr = crl::guard(weak, [=] { if (const auto current = value->current(); !current.link.isEmpty()) { - show->showBox( - InviteLinkQrBox( - current.link, - tr::lng_group_invite_qr_about()), - Ui::LayerOption::KeepOther); + show->showBox(InviteLinkQrBox( + current.link, + tr::lng_group_invite_qr_about())); } }); const auto revokeLink = crl::guard(weak, [=] { if (const auto current = value->current(); !current.link.isEmpty()) { - show->showBox( - RevokeLinkBox(peer, admin, current.link, true), - Ui::LayerOption::KeepOther); + show->showBox(RevokeLinkBox(peer, admin, current.link, true)); } }); @@ -1111,9 +1092,7 @@ void AddPermanentLinkBlock( st::inviteLinkJoinedRowPadding )->setClickedCallback([=] { if (!currentLinkFields->link.isEmpty()) { - show->showBox( - ShowInviteLinkBox(peer, *currentLinkFields), - Ui::LayerOption::KeepOther); + show->showBox(ShowInviteLinkBox(peer, *currentLinkFields)); } }); @@ -1128,9 +1107,9 @@ void AddPermanentLinkBlock( })); } -void CopyInviteLink(not_null toastParent, const QString &link) { +void CopyInviteLink(std::shared_ptr show, const QString &link) { QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show(toastParent, tr::lng_group_invite_copied(tr::now)); + show->showToast(tr::lng_group_invite_copied(tr::now)); } object_ptr ShareInviteLinkBox( @@ -1147,7 +1126,7 @@ object_ptr ShareInviteLinkBox( const auto showToast = [=](const QString &text) { if (*box) { - Ui::Toast::Show(Ui::BoxShow(*box).toastParent(), text); + (*box)->showToast(text); } }; @@ -1184,9 +1163,7 @@ object_ptr ShareInviteLinkBox( } text.append(error.first); if (*box) { - Ui::BoxShow(*box).showBox( - Ui::MakeInformBox(text), - Ui::LayerOption::KeepOther); + (*box)->uiShow()->showBox(Ui::MakeInformBox(text)); } return; } @@ -1232,14 +1209,11 @@ object_ptr InviteLinkQrBox( rpl::producer about) { return Box(QrBox, link, std::move(about), [=]( const QImage &image, - std::shared_ptr show) { + std::shared_ptr show) { auto mime = std::make_unique(); mime->setImageData(image); QGuiApplication::clipboard()->setMimeData(mime.release()); - - Ui::Toast::Show( - show->toastParent(), - tr::lng_group_invite_qr_copied(tr::now)); + show->showToast(tr::lng_group_invite_qr_copied(tr::now)); }); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.h b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.h index 40654776e0..b4f54ef709 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.h @@ -38,7 +38,7 @@ void AddPermanentLinkBlock( not_null admin, rpl::producer fromList); -void CopyInviteLink(not_null toastParent, const QString &link); +void CopyInviteLink(std::shared_ptr show, const QString &link); [[nodiscard]] object_ptr ShareInviteLinkBox( not_null peer, const QString &link); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp index 82a46aff61..45a4c0ea0c 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_chat.h" #include "data/data_channel.h" #include "data/data_session.h" +#include "main/session/session_show.h" #include "main/main_session.h" #include "api/api_invite_links.h" #include "ui/wrap/slide_wrap.h" @@ -543,8 +544,7 @@ void LinksController::appendSlice(const InviteLinksSlice &slice) { void LinksController::rowClicked(not_null row) { delegate()->peerListShowBox( - ShowInviteLinkBox(_peer, static_cast(row.get())->data()), - Ui::LayerOption::KeepOther); + ShowInviteLinkBox(_peer, static_cast(row.get())->data())); } void LinksController::rowRightActionClicked(not_null row) { @@ -579,33 +579,25 @@ base::unique_qptr LinksController::createRowContextMenu( st::popupMenuWithIcons); if (data.revoked) { result->addAction(tr::lng_group_invite_context_delete(tr::now), [=] { - delegate()->peerListShowBox( - DeleteLinkBox(_peer, _admin, link), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(DeleteLinkBox(_peer, _admin, link)); }, &st::menuIconDelete); } else { result->addAction(tr::lng_group_invite_context_copy(tr::now), [=] { - CopyInviteLink(delegate()->peerListToastParent(), link); + CopyInviteLink(delegate()->peerListUiShow(), link); }, &st::menuIconCopy); result->addAction(tr::lng_group_invite_context_share(tr::now), [=] { delegate()->peerListShowBox( - ShareInviteLinkBox(_peer, link), - Ui::LayerOption::KeepOther); + ShareInviteLinkBox(_peer, link)); }, &st::menuIconShare); result->addAction(tr::lng_group_invite_context_qr(tr::now), [=] { delegate()->peerListShowBox( - InviteLinkQrBox(link, tr::lng_group_invite_qr_about()), - Ui::LayerOption::KeepOther); + InviteLinkQrBox(link, tr::lng_group_invite_qr_about())); }, &st::menuIconQrCode); result->addAction(tr::lng_group_invite_context_edit(tr::now), [=] { - delegate()->peerListShowBox( - EditLinkBox(_peer, data), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(EditLinkBox(_peer, data)); }, &st::menuIconEdit); result->addAction(tr::lng_group_invite_context_revoke(tr::now), [=] { - delegate()->peerListShowBox( - RevokeLinkBox(_peer, _admin, link), - Ui::LayerOption::KeepOther); + delegate()->peerListShowBox(RevokeLinkBox(_peer, _admin, link)); }, &st::menuIconRemove); } return result; @@ -813,8 +805,7 @@ void AdminsController::loadMoreRows() { void AdminsController::rowClicked(not_null row) { delegate()->peerListShowBox( - Box(ManageInviteLinksBox, _peer, row->peer()->asUser(), 0, 0), - Ui::LayerOption::KeepOther); + Box(ManageInviteLinksBox, _peer, row->peer()->asUser(), 0, 0)); } Main::Session &AdminsController::session() const { @@ -836,7 +827,7 @@ struct LinksList { }; LinksList AddLinksList( - std::shared_ptr show, + std::shared_ptr show, not_null container, not_null peer, not_null admin, @@ -861,7 +852,7 @@ LinksList AddLinksList( } not_null AddAdminsList( - std::shared_ptr show, + std::shared_ptr show, not_null container, not_null peer, not_null admin) { @@ -889,7 +880,9 @@ void ManageInviteLinksBox( int revokedCount) { using namespace Settings; - const auto show = std::make_shared(box); + const auto show = Main::MakeSessionShow( + box->uiShow(), + &peer->session()); box->setTitle(tr::lng_group_invite_title()); box->setWidth(st::boxWideWidth); @@ -925,8 +918,7 @@ void ManageInviteLinksBox( const auto add = AddCreateLinkButton(container); add->setClickedCallback([=] { show->showBox( - EditLinkBox(peer, InviteLinkData{ .admin = admin }), - Ui::LayerOption::KeepOther); + EditLinkBox(peer, InviteLinkData{ .admin = admin })); }); } else { otherHeader = container->add(object_ptr>( @@ -1006,8 +998,8 @@ void ManageInviteLinksBox( top + st::inviteLinkRevokedTitlePadding.top(), outerWidth); }, deleteAll->lifetime()); - deleteAll->setClickedCallback([=, show = Ui::BoxShow(box)] { - show.showBox(DeleteAllRevokedBox(peer, admin)); + deleteAll->setClickedCallback([=, show = box->uiShow()] { + show->showBox(DeleteAllRevokedBox(peer, admin)); }); rpl::combine( diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index ed7ba6df58..420d5dc524 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -21,7 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/continuous_sliders.h" #include "ui/widgets/box_content_divider.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" +#include "ui/toast/toast.h" #include "info/profile/info_profile_icon.h" #include "info/profile/info_profile_values.h" #include "boxes/peers/edit_participants_box.h" @@ -417,10 +417,7 @@ not_null AddInnerToggle( const auto handleLocked = [=] { if (locked.has_value()) { - Ui::ShowMultilineToast({ - .parentOverride = container, - .text = { *locked }, - }); + Ui::Toast::Show(container, *locked); return true; } return false; @@ -597,8 +594,7 @@ template ) | rpl::start_with_next([=](bool checked) { if (checked && state->forceDisabled.current()) { if (!state->toast) { - state->toast = Ui::ShowMultilineToast({ - .parentOverride = container, + state->toast = Ui::Toast::Show(container, { .text = { state->forceDisabledMessage.current() }, .duration = kForceDisableTooltipDuration, }); @@ -607,8 +603,7 @@ template } else if (locked.has_value()) { if (checked != toggled) { if (!state->toast) { - state->toast = Ui::ShowMultilineToast({ - .parentOverride = container, + state->toast = Ui::Toast::Show(container, { .text = { *locked }, .duration = kForceDisableTooltipDuration, }); @@ -970,23 +965,20 @@ Fn AboutGigagroupCallback( channel->inputChannel )).done([=](const MTPUpdates &result) { channel->session().api().applyUpdates(result); - if (const auto strongController = weak.get()) { - strongController->window().hideSettingsAndLayer(); - Ui::ShowMultilineToast({ - .parentOverride = strongController->widget(), - .text = { tr::lng_gigagroup_done(tr::now) }, - }); + if (const auto strong = weak.get()) { + strong->window().hideSettingsAndLayer(); + strong->showToast(tr::lng_gigagroup_done(tr::now)); } }).fail([=] { *converting = false; }).send(); }; const auto convertWarn = [=] { - const auto strongController = weak.get(); - if (*converting || !strongController) { + const auto strong = weak.get(); + if (*converting || !strong) { return; } - strongController->show(Box([=](not_null box) { + strong->show(Box([=](not_null box) { box->setTitle(tr::lng_gigagroup_warning_title()); box->addRow( object_ptr( @@ -996,14 +988,14 @@ Fn AboutGigagroupCallback( st::infoAboutGigagroup)); box->addButton(tr::lng_gigagroup_convert_sure(), convertSure); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); - }), Ui::LayerOption::KeepOther); + })); }; return [=] { - const auto strongController = weak.get(); - if (*converting || !strongController) { + const auto strong = weak.get(); + if (*converting || !strong) { return; } - strongController->show(Box([=](not_null box) { + strong->show(Box([=](not_null box) { box->setTitle(tr::lng_gigagroup_convert_title()); const auto addFeature = [&](rpl::producer text) { using namespace rpl::mappers; @@ -1024,7 +1016,7 @@ Fn AboutGigagroupCallback( addFeature(tr::lng_gigagroup_convert_feature3()); box->addButton(tr::lng_gigagroup_convert_sure(), convertWarn); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); - }), Ui::LayerOption::KeepOther); + })); }; } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_requests_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_requests_box.cpp index 9280329238..0f21d164b4 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_requests_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_requests_box.cpp @@ -22,7 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "mtproto/sender.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" #include "ui/painter.h" #include "lang/lang_keys.h" #include "window/window_session_controller.h" @@ -382,16 +381,13 @@ void RequestsBoxController::processRequest( const auto done = crl::guard(this, [=] { remove(); if (approved) { - Ui::ShowMultilineToast({ - .parentOverride = delegate()->peerListToastParent(), - .text = (_peer->isBroadcast() - ? tr::lng_group_requests_was_added_channel - : tr::lng_group_requests_was_added)( - tr::now, - lt_user, - Ui::Text::Bold(user->name()), - Ui::Text::WithEntities) - }); + delegate()->peerListUiShow()->showToast((_peer->isBroadcast() + ? tr::lng_group_requests_was_added_channel + : tr::lng_group_requests_was_added)( + tr::now, + lt_user, + Ui::Text::Bold(user->name()), + Ui::Text::WithEntities)); } }); const auto fail = crl::guard(this, remove); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index de5a5c0e75..2739eb1255 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -52,7 +52,7 @@ class Controller : public base::has_weak_ptr { public: Controller( Window::SessionNavigation *navigation, - std::shared_ptr show, + std::shared_ptr show, not_null container, not_null peer, bool useLocationPhrases, @@ -140,7 +140,7 @@ private: rpl::producer about); Window::SessionNavigation *_navigation = nullptr; - std::shared_ptr _show; + std::shared_ptr _show; not_null _peer; bool _linkOnly = false; @@ -168,7 +168,7 @@ private: Controller::Controller( Window::SessionNavigation *navigation, - std::shared_ptr show, + std::shared_ptr show, not_null container, not_null peer, bool useLocationPhrases, @@ -601,9 +601,7 @@ void Controller::askUsernameRevoke() { _controls.privacy->setValue(Privacy::HasUsername); checkUsernameAvailability(); }); - _show->showBox( - Box(PublicLinksLimitBox, _navigation, revokeCallback), - Ui::LayerOption::KeepOther); + _show->showBox(Box(PublicLinksLimitBox, _navigation, revokeCallback)); } void Controller::usernameChanged() { @@ -735,7 +733,7 @@ void EditPeerTypeBox::prepare() { const auto controller = Ui::CreateChild( this, _navigation, - std::make_shared(this), + uiShow(), content.data(), _peer, _useLocationPhrases, diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_usernames_list.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_usernames_list.cpp index aa0a26afb1..c5da087152 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_usernames_list.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_usernames_list.cpp @@ -117,8 +117,7 @@ UsernamesList::Row::Row( tr::lng_group_invite_context_copy(tr::now), [=] { QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show( - show->toastParent(), + show->showToast( tr::lng_create_channel_link_copied(tr::now)); }, &st::menuIconCopy); @@ -307,8 +306,7 @@ void UsernamesList::rebuild(const Data::Usernames &usernames) { tr::lng_usernames_activate_error( lt_count, rpl::single(kMaxUsernames), - Ui::Text::RichLangValue)), - Ui::LayerOption::KeepOther); + Ui::Text::RichLangValue))); } load(); _toggleLifetime.destroy(); @@ -321,9 +319,7 @@ void UsernamesList::rebuild(const Data::Usernames &usernames) { }), .confirmText = std::move(confirmText), }; - _show->showBox( - Ui::MakeConfirmBox(std::move(args)), - Ui::LayerOption::KeepOther); + _show->showBox(Ui::MakeConfirmBox(std::move(args))); }); } diff --git a/Telegram/SourceFiles/boxes/premium_limits_box.cpp b/Telegram/SourceFiles/boxes/premium_limits_box.cpp index 9658bad064..55fbe0a35a 100644 --- a/Telegram/SourceFiles/boxes/premium_limits_box.cpp +++ b/Telegram/SourceFiles/boxes/premium_limits_box.cpp @@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/checkbox.h" #include "ui/wrap/padding_wrap.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" #include "main/main_session.h" #include "main/main_account.h" #include "main/main_domain.h" @@ -133,7 +132,7 @@ public: object_ptr content, Ui::LayerOptions options = Ui::LayerOption::KeepOther) override; void peerListHideLayer() override; - not_null peerListToastParent() override; + std::shared_ptr peerListUiShow() override; void peerListSetRowChecked( not_null row, bool checked) override; @@ -205,8 +204,8 @@ void InactiveDelegate::peerListShowBox( void InactiveDelegate::peerListHideLayer() { } -not_null InactiveDelegate::peerListToastParent() { - Unexpected("...InactiveDelegate::peerListToastParent"); +std::shared_ptr InactiveDelegate::peerListUiShow() { + Unexpected("...InactiveDelegate::peerListUiShow"); } rpl::producer InactiveDelegate::selectedCountChanges() const { @@ -385,8 +384,7 @@ void PublicsController::rowRightActionClicked(not_null row) { .text = text, .confirmed = std::move(callback), .confirmText = confirmText, - }), - Ui::LayerOption::KeepOther); + })); } void PublicsController::appendRow(not_null participant) { @@ -602,10 +600,7 @@ void ChannelsLimitBox( session->api().leaveChannel(channel); } } - Ui::ShowMultilineToast({ - .parentOverride = Ui::BoxShow(box).toastParent(), - .text = { tr::lng_channels_leave_done(tr::now) }, - }); + box->showToast(tr::lng_channels_leave_done(tr::now)); box->closeBox(); }; box->clearButtons(); diff --git a/Telegram/SourceFiles/boxes/reactions_settings_box.cpp b/Telegram/SourceFiles/boxes/reactions_settings_box.cpp index baf0f157eb..8c3845efea 100644 --- a/Telegram/SourceFiles/boxes/reactions_settings_box.cpp +++ b/Telegram/SourceFiles/boxes/reactions_settings_box.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_theme.h" #include "ui/effects/scroll_content_shadow.h" #include "ui/layers/generic_box.h" -#include "ui/toasts/common_toasts.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/widgets/scroll_area.h" diff --git a/Telegram/SourceFiles/boxes/report_messages_box.cpp b/Telegram/SourceFiles/boxes/report_messages_box.cpp index 73223c1fd4..291e0617bf 100644 --- a/Telegram/SourceFiles/boxes/report_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/report_messages_box.cpp @@ -39,13 +39,12 @@ namespace { return Ui::ReportSource::Bot; }); return Box([=](not_null box) { + const auto show = box->uiShow(); Ui::ReportReasonBox(box, source, [=](Ui::ReportReason reason) { - Ui::BoxShow(box).showBox(Box([=](not_null box) { - const auto show = Ui::BoxShow(box); + show->showBox(Box([=](not_null box) { Ui::ReportDetailsBox(box, [=](const QString &text) { - const auto toastParent = show.toastParent(); - Api::SendReport(toastParent, peer, reason, text, data); - show.hideLayer(); + Api::SendReport(show, peer, reason, text, data); + show->hideLayer(); }); })); }); @@ -79,7 +78,7 @@ void ShowReportPeerBox( const auto send = [=](const QString &text) { window->clearChooseReportMessages(); Api::SendReport( - Window::Show(window).toastParent(), + window->uiShow(), peer, reason, text, diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index c49ec87ed5..baceecfe50 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -83,9 +83,9 @@ void FileDialogCallback( Fn checkResult, Fn callback, bool premium, - not_null toastParent) { + std::shared_ptr show) { auto showError = [=](tr::phrase<> text) { - Ui::Toast::Show(toastParent, text(tr::now)); + show->showToast(text(tr::now)); }; auto list = Storage::PreparedFileFromFilesDialog( @@ -143,7 +143,7 @@ SendFilesCheck DefaultCheckForPeer( bool silent) { const auto error = Data::FileRestrictionError(peer, file, compress); if (error && !silent) { - controller->showToast({ *error }); + controller->showToast(*error); } return !error.has_value(); }; @@ -468,12 +468,12 @@ void SendFilesBox::refreshAllAfterChanges(int fromItem, Fn perform) { } void SendFilesBox::openDialogToAddFileToAlbum() { - const auto toastParent = Ui::BoxShow(this).toastParent(); + const auto show = uiShow(); const auto checkResult = [=](const Ui::PreparedList &list) { if (!(_limits & SendFilesAllow::OnlyOne)) { return true; } else if (!_list.canBeSentInSlowmodeWith(list)) { - Ui::Toast::Show(toastParent, tr::lng_slowmode_no_many(tr::now)); + showToast(tr::lng_slowmode_no_many(tr::now)); return false; } return true; @@ -485,7 +485,7 @@ void SendFilesBox::openDialogToAddFileToAlbum() { checkResult, [=](Ui::PreparedList list) { addFiles(std::move(list)); }, premium, - toastParent); + show); }; FileDialog::GetOpenPaths( @@ -748,7 +748,7 @@ void SendFilesBox::pushBlock(int from, int till) { }); }, widget->lifetime()); - const auto toastParent = Ui::BoxShow(this).toastParent(); + const auto show = uiShow(); block.itemReplaceRequest( ) | rpl::start_with_next([=](int index) { const auto replace = [=](Ui::PreparedList list) { @@ -770,9 +770,7 @@ void SendFilesBox::pushBlock(int from, int till) { _list.files.push_back(std::move(removing)); std::swap(_list.files[index], _list.files.back()); if (!result) { - Ui::Toast::Show( - toastParent, - tr::lng_slowmode_no_many(tr::now)); + show->showToast(tr::lng_slowmode_no_many(tr::now)); return false; } return true; @@ -815,7 +813,7 @@ void SendFilesBox::pushBlock(int from, int till) { checkResult, replace, premium, - toastParent); + show); }; FileDialog::GetOpenPath( @@ -1024,7 +1022,7 @@ void SendFilesBox::setupEmojiPanel() { _controller, object_ptr( nullptr, - _controller, + _controller->uiShow(), Window::GifPauseReason::Layer, Selector::Mode::EmojiOnly)); _emojiPanel->setDesiredHeightValues( @@ -1388,8 +1386,7 @@ void SendFilesBox::sendScheduled() { : _sendMenuType; const auto callback = [=](Api::SendOptions options) { send(options); }; _controller->show( - HistoryView::PrepareScheduleBox(this, type, callback), - Ui::LayerOption::KeepOther); + HistoryView::PrepareScheduleBox(this, type, callback)); } void SendFilesBox::sendWhenOnline() { diff --git a/Telegram/SourceFiles/boxes/sessions_box.cpp b/Telegram/SourceFiles/boxes/sessions_box.cpp index a60927da40..55b5f499c3 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.cpp +++ b/Telegram/SourceFiles/boxes/sessions_box.cpp @@ -846,7 +846,7 @@ void SessionsContent::terminate(Fn terminateRequest, QString message) { .confirmStyle = &st::attentionBoxButton, }); _terminateBox = Ui::MakeWeak(box.data()); - _controller->show(std::move(box), Ui::LayerOption::KeepOther); + _controller->show(std::move(box)); } void SessionsContent::terminateOne(uint64 hash) { @@ -928,7 +928,7 @@ void SessionsContent::Inner::setupContent() { rename->moveToRight(x, y, outer.width()); }, rename->lifetime()); rename->setClickedCallback([=] { - _controller->show(Box(RenameBox), Ui::LayerOption::KeepOther); + _controller->show(Box(RenameBox)); }); const auto session = &_controller->session(); diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index c46b76354e..d23e6142cb 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -63,7 +63,7 @@ public: Inner( QWidget *parent, const Descriptor &descriptor, - std::shared_ptr show); + std::shared_ptr show); void setPeerSelectedChangedCallback( Fn thread, bool selected)> callback); @@ -146,7 +146,7 @@ private: void refresh(); const Descriptor &_descriptor; - const std::shared_ptr _show; + const std::shared_ptr _show; const style::PeerList &_st; float64 _columnSkip = 0.; @@ -181,7 +181,6 @@ private: ShareBox::ShareBox(QWidget*, Descriptor &&descriptor) : _descriptor(std::move(descriptor)) , _api(&_descriptor.session->mtp()) -, _show(std::make_shared(this)) , _select( this, (_descriptor.stMultiSelect @@ -231,10 +230,10 @@ void ShareBox::prepareCommentField() { connect(field, &Ui::InputField::submitted, [=] { submit({}); }); - if (_show->valid()) { + if (const auto show = uiShow(); show->valid()) { InitMessageFieldHandlers( _descriptor.session, - _show, + Main::MakeSessionShow(show, _descriptor.session), field, nullptr, nullptr, @@ -257,7 +256,7 @@ void ShareBox::prepare() { setTitle(tr::lng_share_title()); _inner = setInnerWidget( - object_ptr(this, _descriptor, _show), + object_ptr(this, _descriptor, uiShow()), getTopScrollSkip(), getBottomScrollSkip()); @@ -590,14 +589,13 @@ void ShareBox::submitSilent() { void ShareBox::submitScheduled() { const auto callback = [=](Api::SendOptions options) { submit(options); }; - _show->showBox( + uiShow()->showBox( HistoryView::PrepareScheduleBox( this, sendMenuType(), callback, HistoryView::DefaultScheduleTime(), - _descriptor.scheduleBoxStyle), - Ui::LayerOption::KeepOther); + _descriptor.scheduleBoxStyle)); } void ShareBox::submitWhenOnline() { @@ -643,7 +641,7 @@ void ShareBox::scrollAnimationCallback() { ShareBox::Inner::Inner( QWidget *parent, const Descriptor &descriptor, - std::shared_ptr show) + std::shared_ptr show) : RpWidget(parent) , _descriptor(descriptor) , _show(std::move(show)) @@ -1373,9 +1371,7 @@ ShareBox::SubmitCallback ShareBox::DefaultForwardCallback( ).append("\n\n"); } text.append(error.first); - show->showBox( - Ui::MakeInformBox(text), - Ui::LayerOption::KeepOther); + show->showBox(Ui::MakeInformBox(text)); return; } @@ -1441,23 +1437,18 @@ ShareBox::SubmitCallback ShareBox::DefaultForwardCallback( state->requests.remove(reqId); if (state->requests.empty()) { if (show->valid()) { - Ui::Toast::Show( - show->toastParent(), - tr::lng_share_done(tr::now)); + show->showToast(tr::lng_share_done(tr::now)); show->hideLayer(); } } finish(); }).fail([=](const MTP::Error &error) { if (error.type() == u"VOICE_MESSAGES_FORBIDDEN"_q) { - if (show->valid()) { - Ui::Toast::Show( - show->toastParent(), - tr::lng_restricted_send_voice_messages( - tr::now, - lt_user, - peer->name())); - } + show->showToast( + tr::lng_restricted_send_voice_messages( + tr::now, + lt_user, + peer->name())); } finish(); }).afterRequest(history->sendRequestId).send(); @@ -1471,7 +1462,7 @@ ShareBox::SubmitCallback ShareBox::DefaultForwardCallback( void FastShareMessage( not_null controller, not_null item) { - const auto show = std::make_shared(controller); + const auto show = controller->uiShow(); const auto history = item->history(); const auto owner = &history->owner(); const auto session = &history->session(); @@ -1493,7 +1484,7 @@ void FastShareMessage( return item->media() && item->media()->forceForwardedInfo(); }); - auto copyCallback = [=, toastParent = show->toastParent()] { + auto copyCallback = [=] { const auto item = owner->message(msgIds[0]); if (!item) { return; @@ -1509,8 +1500,7 @@ void FastShareMessage( QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show( - toastParent, + show->showToast( tr::lng_share_game_link_copied(tr::now)); } } diff --git a/Telegram/SourceFiles/boxes/share_box.h b/Telegram/SourceFiles/boxes/share_box.h index adaa634c4a..b136385778 100644 --- a/Telegram/SourceFiles/boxes/share_box.h +++ b/Telegram/SourceFiles/boxes/share_box.h @@ -147,8 +147,6 @@ private: Descriptor _descriptor; MTP::Sender _api; - std::shared_ptr _show; - object_ptr _select; object_ptr> _comment; object_ptr _bottomWidget; diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 0b2748191f..0f661181a0 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -38,10 +38,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/cached_round_corners.h" #include "lottie/lottie_multi_player.h" #include "lottie/lottie_animation.h" +#include "chat_helpers/compose/compose_show.h" #include "chat_helpers/stickers_lottie.h" #include "chat_helpers/stickers_list_widget.h" #include "media/clip/media_clip_reader.h" -#include "window/window_session_controller.h" #include "window/window_controller.h" #include "settings/settings_premium.h" #include "base/unixtime.h" @@ -230,7 +230,7 @@ class StickerSetBox::Inner final : public Ui::RpWidget { public: Inner( QWidget *parent, - not_null controller, + std::shared_ptr show, const StickerSetIdentifier &set, Data::StickersType type); @@ -322,11 +322,14 @@ private: not_null getLottiePlayer(); void showPreview(); + void showPreviewAt(QPoint globalPos); void updateItems(); void repaintItems(crl::time now = 0); - const not_null _controller; + const std::shared_ptr _show; + const not_null _session; + MTP::Sender _api; std::vector _elements; std::unique_ptr _lottiePlayer; @@ -381,33 +384,35 @@ private: }; StickerSetBox::StickerSetBox( - QWidget*, - not_null controller, + QWidget *parent, + std::shared_ptr show, const StickerSetIdentifier &set, Data::StickersType type) -: _controller(controller) +: _show(std::move(show)) +, _session(&_show->session()) , _set(set) , _type(type) { } StickerSetBox::StickerSetBox( QWidget *parent, - not_null controller, + std::shared_ptr show, not_null set) -: StickerSetBox(parent, controller, set->identifier(), set->type()) { +: StickerSetBox(parent, std::move(show), set->identifier(), set->type()) { } QPointer StickerSetBox::Show( - not_null controller, + std::shared_ptr show, not_null document) { if (const auto sticker = document->sticker()) { if (sticker->set) { - return controller->show( - Box( - controller, - sticker->set, - sticker->setType), - Ui::LayerOption::KeepOther).data(); + auto box = Box( + show, + sticker->set, + sticker->setType); + const auto result = QPointer(box.data()); + show->showBox(std::move(box)); + return result; } } return nullptr; @@ -417,9 +422,9 @@ void StickerSetBox::prepare() { setTitle(tr::lng_contacts_loading()); _inner = setInnerWidget( - object_ptr(this, _controller, _set, _type), + object_ptr(this, _show, _set, _type), st::stickersScroll); - _controller->session().data().stickers().updated( + _session->data().stickers().updated( _type ) | rpl::start_with_next([=] { updateButtons(); @@ -441,14 +446,12 @@ void StickerSetBox::prepare() { _inner->setInstalled( ) | rpl::start_with_next([=](uint64 setId) { if (_inner->setType() == Data::StickersType::Masks) { - Ui::Toast::Show( - Ui::BoxShow(this).toastParent(), - tr::lng_masks_installed(tr::now)); + showToast(tr::lng_masks_installed(tr::now)); } else if (_inner->setType() == Data::StickersType::Emoji) { - auto &stickers = _controller->session().data().stickers(); + auto &stickers = _session->data().stickers(); stickers.notifyEmojiSetInstalled(setId); } else if (_inner->setType() == Data::StickersType::Stickers) { - auto &stickers = _controller->session().data().stickers(); + auto &stickers = _session->data().stickers(); stickers.notifyStickerSetInstalled(setId); } closeBox(); @@ -466,20 +469,18 @@ void StickerSetBox::prepare() { return; } - Ui::Toast::Show( - Ui::BoxShow(this).toastParent(), - (type == Data::StickersType::Masks) + showToast((type == Data::StickersType::Masks) ? tr::lng_masks_has_been_archived(tr::now) : tr::lng_stickers_has_been_archived(tr::now)); auto &order = (type == Data::StickersType::Masks) - ? _controller->session().data().stickers().maskSetsOrderRef() - : _controller->session().data().stickers().setsOrderRef(); + ? _session->data().stickers().maskSetsOrderRef() + : _session->data().stickers().setsOrderRef(); const auto index = order.indexOf(setId); if (index != -1) { order.removeAt(index); - auto &local = _controller->session().local(); + auto &local = _session->local(); if (type == Data::StickersType::Masks) { local.writeInstalledMasks(); local.writeArchivedMasks(); @@ -489,7 +490,7 @@ void StickerSetBox::prepare() { } } - _controller->session().data().stickers().notifyUpdated(type); + _session->data().stickers().notifyUpdated(type); closeBox(); }, lifetime()); @@ -501,7 +502,7 @@ void StickerSetBox::addStickers() { void StickerSetBox::copyStickersLink() { const auto part = _inner->isEmojiSet() ? u"addemoji"_q : "addstickers"; - const auto url = _controller->session().createInternalLinkFull( + const auto url = _session->createInternalLinkFull( part + '/' + _inner->shortName()); QGuiApplication::clipboard()->setText(url); } @@ -513,7 +514,7 @@ void StickerSetBox::handleError(Error error) { switch (error) { case Error::NotFound: - _controller->show( + _show->showBox( Ui::MakeInformBox(tr::lng_stickers_not_found(tr::now))); break; default: Unexpected("Error in StickerSetBox::handleError."); @@ -531,15 +532,13 @@ void StickerSetBox::updateButtons() { const auto type = _inner->setType(); const auto share = [=] { copyStickersLink(); - Ui::Toast::Show( - Ui::BoxShow(this).toastParent(), - (type == Data::StickersType::Emoji + showToast(type == Data::StickersType::Emoji ? tr::lng_stickers_copied_emoji(tr::now) - : tr::lng_stickers_copied(tr::now))); + : tr::lng_stickers_copied(tr::now)); }; if (_inner->notInstalled()) { - if (!_controller->session().premium() - && _controller->session().premiumPossible() + if (!_session->premium() + && _session->premiumPossible() && _inner->premiumEmojiSet()) { const auto &st = st::premiumPreviewDoubledLimitsBox; setStyle(st); @@ -550,7 +549,11 @@ void StickerSetBox::updateButtons() { - st.buttonPadding.left() - st.buttonPadding.left()); button->setClickedCallback([=] { - Settings::ShowPremium(_controller, u"animated_emoji"_q); + using namespace ChatHelpers; + const auto usage = WindowUsage::PremiumPromo; + if (const auto window = _show->resolveWindow(usage)) { + Settings::ShowPremium(window, u"animated_emoji"_q); + } }); addButton(std::move(button)); } else { @@ -600,14 +603,12 @@ void StickerSetBox::updateButtons() { _inner->archiveStickers(); }; const auto remove = [=] { - const auto session = &_controller->session(); + const auto session = &_show->session(); auto box = ChatHelpers::MakeConfirmRemoveSetBox( session, _inner->setId()); if (box) { - _controller->show( - std::move(box), - Ui::LayerOption::KeepOther); + _show->showBox(std::move(box)); } }; const auto menu = @@ -647,12 +648,13 @@ void StickerSetBox::resizeEvent(QResizeEvent *e) { StickerSetBox::Inner::Inner( QWidget *parent, - not_null controller, + std::shared_ptr show, const StickerSetIdentifier &set, Data::StickersType type) : RpWidget(parent) -, _controller(controller) -, _api(&_controller->session().mtp()) +, _show(std::move(show)) +, _session(&_show->session()) +, _api(&_session->mtp()) , _setId(set.id) , _setAccessHash(set.accessHash) , _setShortName(set.shortName) @@ -660,7 +662,7 @@ StickerSetBox::Inner::Inner( st::windowBgRipple, st::windowBgOver, [=] { repaintItems(); })) -, _premiumMark(&controller->session()) +, _premiumMark(_session) , _updateItemsTimer([=] { updateItems(); }) , _input(set) , _padding((type == Data::StickersType::Emoji) @@ -679,9 +681,9 @@ StickerSetBox::Inner::Inner( _errors.fire(Error::NotFound); }).send(); - _controller->session().api().updateStickers(); + _session->api().updateStickers(); - _controller->session().downloaderTaskFinished( + _session->downloaderTaskFinished( ) | rpl::start_with_next([=] { updateItems(); }, lifetime()); @@ -695,8 +697,8 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) { _elements.clear(); _selected = -1; setCursor(style::cur_default); - const auto owner = &_controller->session().data(); - const auto premiumPossible = _controller->session().premiumPossible(); + const auto owner = &_session->data(); + const auto premiumPossible = _session->premiumPossible(); set.match([&](const MTPDmessages_stickerSet &data) { const auto &v = data.vdocuments().v; _pack.reserve(v.size()); @@ -724,7 +726,7 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) { auto p = StickersPack(); p.reserve(stickers.size()); for (auto j = 0, c = int(stickers.size()); j != c; ++j) { - auto doc = _controller->session().data().document(stickers[j].v); + auto doc = _session->data().document(stickers[j].v); if (!doc || !doc->sticker()) continue; p.push_back(doc); @@ -734,7 +736,7 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) { }); } data.vset().match([&](const MTPDstickerSet &set) { - _setTitle = _controller->session().data().stickers().getSetTitle( + _setTitle = _session->data().stickers().getSetTitle( set); _setShortName = qs(set.vshort_name()); _setId = set.vid().v; @@ -748,7 +750,7 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) { if (const auto thumbs = set.vthumbs()) { for (const auto &thumb : thumbs->v) { const auto result = Images::FromPhotoSize( - &_controller->session(), + _session, set, thumb); if (result.location.valid()) { @@ -758,7 +760,7 @@ void StickerSetBox::Inner::gotSet(const MTPmessages_StickerSet &set) { } return ImageWithLocation(); }(); - const auto &sets = _controller->session().data().stickers().sets(); + const auto &sets = _session->data().stickers().sets(); const auto it = sets.find(_setId); if (it != sets.cend()) { const auto set = it->second.get(); @@ -814,7 +816,7 @@ rpl::producer StickerSetBox::Inner::errors() const { void StickerSetBox::Inner::installDone( const MTPmessages_StickerSetInstallResult &result) { - auto &stickers = _controller->session().data().stickers(); + auto &stickers = _session->data().stickers(); auto &sets = stickers.setsRef(); const auto type = setType(); @@ -837,7 +839,7 @@ void StickerSetBox::Inner::installDone( it = sets.emplace( _setId, std::make_unique( - &_controller->session().data(), + &_session->data(), _setId, _setAccessHash, _setHash, @@ -887,7 +889,7 @@ void StickerSetBox::Inner::installDone( stickers.applyArchivedResult( result.c_messages_stickerSetInstallResultArchive()); } else { - auto &storage = _controller->session().local(); + auto &storage = _session->local(); if (wasArchived && type != Data::StickersType::Emoji) { if (type == Data::StickersType::Masks) { storage.writeArchivedMasks(); @@ -921,13 +923,19 @@ void StickerSetBox::Inner::mousePressEvent(QMouseEvent *e) { void StickerSetBox::Inner::mouseMoveEvent(QMouseEvent *e) { updateSelected(); if (_previewShown >= 0) { - int index = stickerFromGlobalPos(e->globalPos()); - if (index >= 0 && index < _pack.size() && index != _previewShown) { - _previewShown = index; - _controller->widget()->showMediaPreview( - Data::FileOriginStickerSet(_setId, _setAccessHash), - _pack[_previewShown]); - } + showPreviewAt(e->globalPos()); + } +} + +void StickerSetBox::Inner::showPreviewAt(QPoint globalPos) { + const auto index = stickerFromGlobalPos(globalPos); + if (index >= 0 + && index < _pack.size() + && index != _previewShown) { + _previewShown = index; + _show->showMediaPreview( + Data::FileOriginStickerSet(_setId, _setAccessHash), + _pack[_previewShown]); } } @@ -955,16 +963,13 @@ void StickerSetBox::Inner::chosen( int index, not_null sticker, Api::SendOptions options) { - const auto controller = _controller; const auto animation = options.scheduled ? Ui::MessageSendingAnimationFrom() : messageSentAnimationInfo(index, sticker); - Ui::PostponeCall(controller, [=] { - controller->stickerOrEmojiChosen({ - .document = sticker, - .options = options, - .messageSendingFrom = animation, - }); + _show->processChosenSticker({ + .document = sticker, + .options = options, + .messageSendingFrom = animation, }); } @@ -988,7 +993,7 @@ auto StickerSetBox::Inner::messageSentAnimationInfo( (rect.height() - size.height()) / 2); return { .type = Ui::MessageSendingAnimationFrom::Type::Sticker, - .localId = _controller->session().data().nextLocalMessageId(), + .localId = _session->data().nextLocalMessageId(), .globalStartGeometry = mapToGlobal( QRect(rect.topLeft() + innerPos, size)), }; @@ -1005,7 +1010,7 @@ void StickerSetBox::Inner::contextMenuEvent(QContextMenuEvent *e) { _menu = base::make_unique_q( this, st::popupMenuWithIcons); - const auto type = _controller->content()->sendMenuType(); + const auto type = _show->sendMenuType(); if (setType() == Data::StickersType::Emoji) { if (const auto t = PrepareTextFromEmoji(_pack[index]); !t.empty()) { _menu->addAction(tr::lng_mediaview_copy(tr::now), [=] { @@ -1026,10 +1031,10 @@ void StickerSetBox::Inner::contextMenuEvent(QContextMenuEvent *e) { SendMenu::DefaultScheduleCallback(this, type, sendSelected), SendMenu::DefaultWhenOnlineCallback(sendSelected)); - const auto controller = _controller; + const auto show = _show; const auto toggleFavedSticker = [=] { Api::ToggleFavedSticker( - controller, + show, document, Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0)); }; @@ -1078,13 +1083,8 @@ void StickerSetBox::Inner::startOverAnimation(int index, float64 from, float64 t } void StickerSetBox::Inner::showPreview() { - int index = stickerFromGlobalPos(QCursor::pos()); - if (index >= 0 && index < _pack.size()) { - _previewShown = index; - _controller->widget()->showMediaPreview( - Data::FileOriginStickerSet(_setId, _setAccessHash), - _pack[_previewShown]); - } + _previewShown = -1; + showPreviewAt(QCursor::pos()); } not_null StickerSetBox::Inner::getLottiePlayer() { @@ -1128,7 +1128,7 @@ void StickerSetBox::Inner::paintEvent(QPaintEvent *e) { const auto now = crl::now(); const auto paused = On(PowerSaving::kStickersPanel) - || _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Layer); + || _show->paused(ChatHelpers::PauseReason::Layer); for (int32 i = from; i < to; ++i) { for (int32 j = 0; j < _perRow; ++j) { int32 index = i * _perRow + j; @@ -1392,7 +1392,7 @@ bool StickerSetBox::Inner::notInstalled() const { if (!_loaded) { return false; } - const auto &sets = _controller->session().data().stickers().sets(); + const auto &sets = _session->data().stickers().sets(); const auto it = sets.find(_setId); if ((it == sets.cend()) || !(it->second->flags & SetFlag::Installed) @@ -1436,7 +1436,6 @@ void StickerSetBox::Inner::install() { } void StickerSetBox::Inner::archiveStickers() { - const auto toastParent = Window::Show(_controller).toastParent(); _api.request(MTPmessages_InstallStickerSet( Data::InputStickerSet(_input), MTP_boolTrue() @@ -1444,9 +1443,9 @@ void StickerSetBox::Inner::archiveStickers() { if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) { _setArchived.fire_copy(_setId); } - }).fail(crl::guard(toastParent, [=] { - Ui::Toast::Show(toastParent, Lang::Hard::ServerError()); - })).send(); + }).fail([=] { + _show->showToast(Lang::Hard::ServerError()); + }).send(); } void StickerSetBox::Inner::updateItems() { diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.h b/Telegram/SourceFiles/boxes/sticker_set_box.h index 73d99dc7de..f1992fa668 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.h +++ b/Telegram/SourceFiles/boxes/sticker_set_box.h @@ -23,6 +23,15 @@ namespace Data { class StickersSet; } // namespace Data +namespace SendMenu { +enum class Type; +} // namespace SendMenu + +namespace ChatHelpers { +struct FileChosen; +class Show; +} // namespace ChatHelpers + class StickerPremiumMark final { public: explicit StickerPremiumMark(not_null session); @@ -51,16 +60,16 @@ class StickerSetBox final : public Ui::BoxContent { public: StickerSetBox( QWidget*, - not_null controller, + std::shared_ptr show, const StickerSetIdentifier &set, Data::StickersType type); StickerSetBox( QWidget*, - not_null controller, + std::shared_ptr show, not_null set); static QPointer Show( - not_null controller, + std::shared_ptr show, not_null document); protected: @@ -79,7 +88,8 @@ private: void copyStickersLink(); void handleError(Error error); - const not_null _controller; + const std::shared_ptr _show; + const not_null _session; const StickerSetIdentifier _set; const Data::StickersType _type; diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index cb38b11df6..29a16c78e9 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "storage/storage_account.h" #include "lottie/lottie_single_player.h" +#include "chat_helpers/compose/compose_show.h" #include "chat_helpers/stickers_lottie.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" @@ -35,7 +36,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/cached_round_corners.h" #include "ui/painter.h" #include "ui/unread_badge_paint.h" -#include "window/window_session_controller.h" #include "media/clip/media_clip_reader.h" #include "main/main_session.h" #include "styles/style_layers.h" @@ -77,11 +77,11 @@ public: Inner( QWidget *parent, - not_null controller, + std::shared_ptr show, Section section); Inner( QWidget *parent, - not_null controller, + std::shared_ptr show, not_null megagroup); [[nodiscard]] Main::Session &session() const; @@ -250,7 +250,8 @@ private: int countMaxNameWidth() const; [[nodiscard]] bool skipPremium() const; - const not_null _controller; + const std::shared_ptr _show; + const not_null _session; MTP::Sender _api; const Section _section; @@ -380,35 +381,37 @@ void StickersBox::Tab::saveScrollTop() { StickersBox::StickersBox( QWidget*, - not_null controller, + std::shared_ptr show, Section section, bool masks) -: _controller(controller) -, _api(&controller->session().mtp()) +: _show(std::move(show)) +, _session(&_show->session()) +, _api(&_session->mtp()) , _tabs(this, st::stickersTabs) , _unreadBadge( this, - controller->session().data().stickers().featuredSetsUnreadCountValue()) + _session->data().stickers().featuredSetsUnreadCountValue()) , _section(section) , _isMasks(masks) , _isEmoji(false) -, _installed(_isMasks ? Tab() : Tab(0, this, controller, Section::Installed)) -, _masks(_isMasks ? Tab(0, this, controller, Section::Masks) : Tab()) -, _featured(_isMasks ? Tab() : Tab(1, this, controller, Section::Featured)) -, _archived((_isMasks ? 1 : 2), this, controller, Section::Archived) { +, _installed(_isMasks ? Tab() : Tab(0, this, _show, Section::Installed)) +, _masks(_isMasks ? Tab(0, this, _show, Section::Masks) : Tab()) +, _featured(_isMasks ? Tab() : Tab(1, this, _show, Section::Featured)) +, _archived((_isMasks ? 1 : 2), this, _show, Section::Archived) { _tabs->setRippleTopRoundRadius(st::boxRadius); } StickersBox::StickersBox( QWidget*, - not_null controller, + std::shared_ptr show, not_null megagroup) -: _controller(controller) -, _api(&controller->session().mtp()) +: _show(std::move(show)) +, _session(&_show->session()) +, _api(&_session->mtp()) , _section(Section::Installed) , _isMasks(false) , _isEmoji(false) -, _installed(0, this, controller, megagroup) +, _installed(0, this, _show, megagroup) , _megagroupSet(megagroup) { _installed.widget()->scrollsToY( ) | rpl::start_with_next([=](int y) { @@ -418,34 +421,36 @@ StickersBox::StickersBox( StickersBox::StickersBox( QWidget*, - not_null controller, + std::shared_ptr show, const QVector &attachedSets) -: _controller(controller) -, _api(&controller->session().mtp()) +: _show(std::move(show)) +, _session(&_show->session()) +, _api(&_session->mtp()) , _section(Section::Attached) , _isMasks(false) , _isEmoji(false) -, _attached(0, this, controller, Section::Attached) +, _attached(0, this, _show, Section::Attached) , _attachedType(Data::StickersType::Stickers) , _attachedSets(attachedSets) { } StickersBox::StickersBox( QWidget*, - not_null controller, + std::shared_ptr show, const std::vector &emojiSets) -: _controller(controller) -, _api(&controller->session().mtp()) +: _show(std::move(show)) +, _session(&_show->session()) +, _api(&_session->mtp()) , _section(Section::Attached) , _isMasks(false) , _isEmoji(true) -, _attached(0, this, controller, Section::Attached) +, _attached(0, this, _show, Section::Attached) , _attachedType(Data::StickersType::Emoji) , _emojiSets(emojiSets) { } Main::Session &StickersBox::session() const { - return _controller->session(); + return *_session; } void StickersBox::showAttachedStickers() { @@ -1121,11 +1126,12 @@ bool StickersBox::Inner::Row::isArchived() const { StickersBox::Inner::Inner( QWidget *parent, - not_null controller, + std::shared_ptr show, StickersBox::Section section) : RpWidget(parent) -, _controller(controller) -, _api(&_controller->session().mtp()) +, _show(std::move(show)) +, _session(&_show->session()) +, _api(&_session->mtp()) , _section(section) , _isInstalled(_section == Section::Installed || _section == Section::Masks) , _buttonBgOver( @@ -1152,11 +1158,12 @@ StickersBox::Inner::Inner( StickersBox::Inner::Inner( QWidget *parent, - not_null controller, + std::shared_ptr show, not_null megagroup) : RpWidget(parent) -, _controller(controller) -, _api(&_controller->session().mtp()) +, _show(std::move(show)) +, _session(&_show->session()) +, _api(&_session->mtp()) , _section(StickersBox::Section::Installed) , _isInstalled(_section == Section::Installed || _section == Section::Masks) , _buttonBgOver( @@ -1181,11 +1188,11 @@ StickersBox::Inner::Inner( st::groupStickersField, rpl::single(u"stickerset"_q), QString(), - _controller->session().createInternalLink(QString())) + _session->createInternalLink(QString())) , _megagroupDivider(this) , _megagroupSubTitle(this, tr::lng_stickers_group_from_your(tr::now), st::boxTitle) { _megagroupSetField->setLinkPlaceholder( - _controller->session().createInternalLink(u"addstickers/"_q)); + _session->createInternalLink(u"addstickers/"_q)); _megagroupSetField->setPlaceholderHidden(false); _megagroupSetAddressChangedTimer.setCallback([this] { handleMegagroupSetAddressChange(); }); connect( @@ -1207,7 +1214,7 @@ StickersBox::Inner::Inner( } Main::Session &StickersBox::Inner::session() const { - return _controller->session(); + return *_session; } void StickersBox::Inner::setup() { @@ -1429,8 +1436,7 @@ void StickersBox::Inner::paintRowThumbnail( : row->stickerMedia ? row->stickerMedia->thumbnail() : nullptr; - const auto paused = _controller->isGifPausedAtLeastFor( - Window::GifPauseReason::Layer); + const auto paused = _show->paused(ChatHelpers::PauseReason::Layer); const auto x = left + (st::contactsPhotoSize - row->pixw) / 2; const auto y = st::contactsPadding.top() + (st::contactsPhotoSize - row->pixh) / 2; if (row->lottie && row->lottie->ready()) { @@ -1858,9 +1864,7 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) { }(); const auto showSetByRow = [&](const Row &row) { setSelected(SelectedRow()); - _controller->show( - Box(_controller, row.set), - Ui::LayerOption::KeepOther); + _show->showBox(Box(_show, row.set)); }; if (selectedIndex >= 0 && !_inDragArea) { const auto row = _rows[selectedIndex].get(); @@ -2252,7 +2256,7 @@ bool StickersBox::Inner::appendSet(not_null set) { } bool StickersBox::Inner::skipPremium() const { - return !_controller->session().premiumPossible(); + return !_session->premiumPossible(); } int StickersBox::Inner::countMaxNameWidth() const { diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index c9709b07b7..fa3647691a 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -27,9 +27,9 @@ class CrossButton; class BoxContentDivider; } // namespace Ui -namespace Window { -class SessionController; -} // namespace Window +namespace ChatHelpers { +class Show; +} // namespace ChatHelpers namespace Main { class Session; @@ -60,20 +60,20 @@ public: StickersBox( QWidget*, - not_null controller, + std::shared_ptr show, Section section, bool masks = false); StickersBox( QWidget*, - not_null controller, + std::shared_ptr show, not_null megagroup); StickersBox( QWidget*, - not_null controller, + std::shared_ptr show, const QVector &attachedSets); StickersBox( QWidget*, - not_null controller, + std::shared_ptr show, const std::vector &emojiSets); ~StickersBox(); @@ -142,7 +142,8 @@ private: std::array widgets() const; - const not_null _controller; + const std::shared_ptr _show; + const not_null _session; MTP::Sender _api; object_ptr _tabs = { nullptr }; diff --git a/Telegram/SourceFiles/boxes/translate_box.cpp b/Telegram/SourceFiles/boxes/translate_box.cpp index de64a704e8..662cf51e59 100644 --- a/Telegram/SourceFiles/boxes/translate_box.cpp +++ b/Telegram/SourceFiles/boxes/translate_box.cpp @@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/loading_element.h" #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" #include "ui/painter.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" @@ -263,7 +262,7 @@ void TranslateBox( if (loading->toggled()) { return; } - Ui::BoxShow(box).showBox(ChooseTranslateToBox( + box->uiShow()->showBox(ChooseTranslateToBox( state->to.current(), crl::guard(box, [=](LanguageId id) { state->to = id; }))); }); @@ -314,11 +313,9 @@ object_ptr EditSkipTranslationLanguages() { } if (already && selected->empty()) { if (const auto strong = weak->data()) { - Ui::ShowMultilineToast({ - .parentOverride = BoxShow(strong).toastParent(), - .text = { tr::lng_translate_settings_one(tr::now) }, - .duration = kSkipAtLeastOneDuration, - }); + strong->showToast( + tr::lng_translate_settings_one(tr::now), + kSkipAtLeastOneDuration); } return false; } diff --git a/Telegram/SourceFiles/boxes/username_box.cpp b/Telegram/SourceFiles/boxes/username_box.cpp index 6e4e10a9da..8e7ccd2444 100644 --- a/Telegram/SourceFiles/boxes/username_box.cpp +++ b/Telegram/SourceFiles/boxes/username_box.cpp @@ -375,7 +375,7 @@ void UsernamesBox( object_ptr( box, peer, - std::make_shared(box), + box->uiShow(), !isBot ? [=] { box->scrollToY(0); editor->setInnerFocus(); } : Fn(nullptr)), diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index ad9eff91a8..66a4e01f5b 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -568,8 +568,7 @@ base::unique_qptr BoxController::rowContextMenu( st::popupMenuWithIcons); result->addAction(tr::lng_context_delete_selected(tr::now), [=] { _window->show( - Box(session, base::duplicate(ids)), - Ui::LayerOption::KeepOther); + Box(session, base::duplicate(ids))); }, &st::menuIconDelete); return result; } diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index c66805f434..e43af9373c 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -292,8 +292,7 @@ void TopBar::initControls() { call->setMuted(!call->muted()); } else if (const auto group = _groupCall.get()) { if (group->mutedByAdmin()) { - Ui::Toast::Show( - _show->toastParent(), + _show->showToast( tr::lng_group_call_force_muted_sub(tr::now)); } else { group->setMuted((group->muted() == MuteState::Muted) diff --git a/Telegram/SourceFiles/calls/group/calls_choose_join_as.cpp b/Telegram/SourceFiles/calls/group/calls_choose_join_as.cpp index 2ac7902889..a3f57de101 100644 --- a/Telegram/SourceFiles/calls/group/calls_choose_join_as.cpp +++ b/Telegram/SourceFiles/calls/group/calls_choose_join_as.cpp @@ -406,9 +406,7 @@ void ChooseJoinAsProcess::processList( auto info = JoinInfo{ .peer = peer, .joinAs = self }; const auto selectedId = peer->groupCallDefaultJoinAs(); if (list.empty()) { - Ui::Toast::Show( - _request->show->toastParent(), - Lang::Hard::ServerError()); + _request->show->showToast(Lang::Hard::ServerError()); return; } info.joinAs = [&]() -> not_null { diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index f62573c906..49dd3db915 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "lang/lang_hardcoded.h" #include "boxes/peers/edit_participants_box.h" // SubscribeToMigration. -#include "ui/toasts/common_toasts.h" +#include "ui/toast/toast.h" #include "base/unixtime.h" #include "core/application.h" #include "core/core_settings.h" @@ -1413,11 +1413,9 @@ void GroupCall::rejoin(not_null as) { } hangup(); - Ui::ShowMultilineToast({ - .text = { type == u"GROUPCALL_FORBIDDEN"_q - ? tr::lng_group_not_accessible(tr::now) - : Lang::Hard::ServerError() }, - }); + Ui::Toast::Show((type == u"GROUPCALL_FORBIDDEN"_q) + ? tr::lng_group_not_accessible(tr::now) + : Lang::Hard::ServerError()); }).send(); }); }); diff --git a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp index fd02256346..ffb685968b 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp @@ -259,9 +259,7 @@ object_ptr PrepareInviteBox( finish(); }; const auto done = [=] { - const auto show = (*shared) - ? std::make_shared(*shared) - : nullptr; + const auto show = (*shared) ? (*shared)->uiShow() : nullptr; inviteWithAdd(show, users, nonMembers, finishWithConfirm); }; auto box = ConfirmBox({ diff --git a/Telegram/SourceFiles/calls/group/calls_group_members.cpp b/Telegram/SourceFiles/calls/group/calls_group_members.cpp index 10e1123cd4..cc3c33ddb4 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_members.cpp @@ -1983,8 +1983,8 @@ void Members::peerListShowBox( void Members::peerListHideLayer() { } -not_null Members::peerListToastParent() { - Unexpected("...Members::peerListToastParent"); +std::shared_ptr Members::peerListUiShow() { + Unexpected("...Members::peerListUiShow"); } } // namespace Calls::Group diff --git a/Telegram/SourceFiles/calls/group/calls_group_members.h b/Telegram/SourceFiles/calls/group/calls_group_members.h index 312161b3a0..f8b4c8c52d 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_members.h +++ b/Telegram/SourceFiles/calls/group/calls_group_members.h @@ -92,7 +92,7 @@ private: object_ptr content, Ui::LayerOptions options = Ui::LayerOption::KeepOther) override; void peerListHideLayer() override; - not_null peerListToastParent() override; + std::shared_ptr peerListUiShow() override; void setupAddMember(not_null call); void resizeToList(); diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index 7214a344c8..31758718d5 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -32,7 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" #include "ui/toast/toast.h" -#include "ui/toasts/common_toasts.h" #include "ui/image/image_prepare.h" #include "ui/painter.h" #include "ui/round_rect.h" @@ -46,6 +45,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_group_call.h" #include "data/data_session.h" #include "data/data_changes.h" +#include "main/session/session_show.h" #include "main/main_session.h" #include "base/event_filter.h" #include "base/unixtime.h" @@ -75,6 +75,67 @@ constexpr auto kControlsBackgroundOpacity = 0.8; constexpr auto kOverrideActiveColorBgAlpha = 172; constexpr auto kHideControlsTimeout = 5 * crl::time(1000); +class Show final : public Main::SessionShow { +public: + explicit Show(not_null panel); + ~Show(); + + void showBox( + object_ptr content, + Ui::LayerOptions options + = Ui::LayerOption::KeepOther) const override; + void hideLayer() const override; + [[nodiscard]] not_null toastParent() const override; + [[nodiscard]] bool valid() const override; + operator bool() const override; + + [[nodiscard]] Main::Session &session() const override; + +private: + const base::weak_ptr _panel; + +}; + +Show::Show(not_null panel) +: _panel(base::make_weak(panel)) { +} + +Show::~Show() = default; + +void Show::showBox( + object_ptr content, + Ui::LayerOptions options) const { + if (const auto panel = _panel.get()) { + panel->showBox(std::move(content), options); + } +} + +void Show::hideLayer() const { + if (const auto panel = _panel.get()) { + panel->hideLayer(); + } +} + +not_null Show::toastParent() const { + const auto panel = _panel.get(); + Assert(panel != nullptr); + return panel->widget(); +} + +bool Show::valid() const { + return !_panel.empty(); +} + +Show::operator bool() const { + return valid(); +} + +Main::Session &Show::session() const { + const auto panel = _panel.get(); + Assert(panel != nullptr); + return panel->call()->peer()->session(); +} + } // namespace struct Panel::ControlsBackgroundNarrow { @@ -176,15 +237,25 @@ bool Panel::isActive() const { && !(window()->windowState() & Qt::WindowMinimized); } -void Panel::showToast(TextWithEntities &&text, crl::time duration) { - if (const auto strong = _lastToast.get()) { - strong->hideAnimated(); - } - _lastToast = Ui::ShowMultilineToast({ - .parentOverride = widget(), - .text = std::move(text), - .duration = duration, - }); +base::weak_ptr Panel::showToast( + const QString &text, + crl::time duration) { + return Show(this).showToast(text, duration); +} + +base::weak_ptr Panel::showToast( + TextWithEntities &&text, + crl::time duration) { + return Show(this).showToast(std::move(text), duration); +} + +base::weak_ptr Panel::showToast( + Ui::Toast::Config &&config) { + return Show(this).showToast(std::move(config)); +} + +std::shared_ptr Panel::uiShow() { + return std::make_shared(this); } void Panel::minimize() { @@ -634,16 +705,9 @@ void Panel::hideNiceTooltip() { } void Panel::initShareAction() { - const auto showBoxCallback = [=](object_ptr next) { - showBox(std::move(next)); - }; - const auto showToastCallback = [=](QString text) { - showToast({ text }); - }; auto [shareLinkCallback, shareLinkLifetime] = ShareInviteLinkAction( _peer, - showBoxCallback, - showToastCallback); + uiShow()); _callShareLinkCallback = [=, callback = std::move(shareLinkCallback)] { if (_call->lookupReal()) { callback(); @@ -1467,6 +1531,10 @@ void Panel::hideLayer(anim::type animated) { _layerBg->hideAll(animated); } +bool Panel::isLayerShown() const { + return _layerBg->topShownLayer() != nullptr; +} + void Panel::kickParticipantSure(not_null participantPeer) { if (const auto chat = _peer->asChat()) { chat->session().api().chatParticipants().kick(chat, participantPeer); @@ -2550,38 +2618,4 @@ not_null Panel::widget() const { return _window.widget(); } -Show::Show(not_null panel) -: _panel(base::make_weak(panel)) { -} - -Show::~Show() = default; - -void Show::showBox( - object_ptr content, - Ui::LayerOptions options) const { - if (const auto panel = _panel.get()) { - panel->showBox(std::move(content), options); - } -} - -void Show::hideLayer() const { - if (const auto panel = _panel.get()) { - panel->hideLayer(); - } -} - -not_null Show::toastParent() const { - const auto panel = _panel.get(); - Assert(panel != nullptr); - return panel->widget(); -} - -bool Show::valid() const { - return !_panel.empty(); -} - -Show::operator bool() const { - return valid(); -} - } // namespace Calls::Group diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.h b/Telegram/SourceFiles/calls/group/calls_group_panel.h index e607d0c95c..2a05232c5a 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.h +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.h @@ -52,14 +52,21 @@ class ScrollArea; class GenericBox; class LayerManager; class GroupCallScheduledLeft; -namespace Toast { -class Instance; -} // namespace Toast -namespace Platform { -struct SeparateTitleControls; -} // namespace Platform } // namespace Ui +namespace Ui::Toast { +class Instance; +struct Config; +} // namespace Ui::Toast + +namespace Ui::Platform { +struct SeparateTitleControls; +} // namespace Ui::Platform + +namespace Main { +class SessionShow; +} // namespace Main + namespace style { struct CallSignalBars; struct CallBodyLayout; @@ -85,13 +92,22 @@ public: [[nodiscard]] not_null call() const; [[nodiscard]] bool isActive() const; - void showToast(TextWithEntities &&text, crl::time duration = 0); + base::weak_ptr showToast( + const QString &text, + crl::time duration = 0); + base::weak_ptr showToast( + TextWithEntities &&text, + crl::time duration = 0); + base::weak_ptr showToast( + Ui::Toast::Config &&config); + void showBox(object_ptr box); void showBox( object_ptr box, Ui::LayerOptions options, anim::type animated = anim::type::normal); void hideLayer(anim::type animated = anim::type::normal); + [[nodiscard]] bool isLayerShown() const; void minimize(); void toggleFullScreen(); @@ -99,6 +115,8 @@ public: void showAndActivate(); void closeBeforeDestroy(); + [[nodiscard]] std::shared_ptr uiShow(); + rpl::lifetime &lifetime(); private: @@ -260,7 +278,6 @@ private: Fn _callShareLinkCallback; const std::unique_ptr _toasts; - base::weak_ptr _lastToast; std::unique_ptr _micLevelTester; @@ -272,21 +289,4 @@ private: }; -class Show : public Ui::Show { -public: - explicit Show(not_null panel); - ~Show(); - void showBox( - object_ptr content, - Ui::LayerOptions options = Ui::LayerOption::KeepOther) const override; - void hideLayer() const override; - [[nodiscard]] not_null toastParent() const override; - [[nodiscard]] bool valid() const override; - operator bool() const override; - -private: - const base::weak_ptr _panel; - -}; - } // namespace Calls::Group diff --git a/Telegram/SourceFiles/calls/group/calls_group_rtmp.cpp b/Telegram/SourceFiles/calls/group/calls_group_rtmp.cpp index 1891a2ca07..69cd78107f 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_rtmp.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_rtmp.cpp @@ -151,9 +151,7 @@ void StartRtmpProcess::requestUrl(bool revoke) { }); processUrl(std::move(data)); }).fail([=] { - Ui::Toast::Show( - _request->show->toastParent(), - Lang::Hard::ServerError()); + _request->show->showToast(Lang::Hard::ServerError()); }).send(); } @@ -229,7 +227,7 @@ void StartRtmpProcess::FillRtmpRows( ) | rpl::map([=](const auto &d) { return d.url; }); const auto showToast = [=](const QString &text) { - Ui::Toast::Show(show->toastParent(), text); + show->showToast(text); }; const auto addButton = [&]( bool key, diff --git a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp index 831fcd3c22..59ed26a62c 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp @@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/wrap/slide_wrap.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" #include "lang/lang_keys.h" #include "boxes/share_box.h" #include "history/view/history_view_schedule_box.h" @@ -108,7 +107,7 @@ object_ptr ShareInviteLinkBox( not_null peer, const QString &linkSpeaker, const QString &linkListener, - Fn showToast) { + std::shared_ptr show) { const auto sending = std::make_shared(); const auto box = std::make_shared>(); @@ -130,7 +129,7 @@ object_ptr ShareInviteLinkBox( }; auto copyCallback = [=] { QGuiApplication::clipboard()->setText(currentLink()); - showToast(tr::lng_group_invite_copied(tr::now)); + show->showToast(tr::lng_group_invite_copied(tr::now)); }; auto submitCallback = [=]( std::vector> &&result, @@ -191,7 +190,7 @@ object_ptr ShareInviteLinkBox( if (*box) { (*box)->closeBox(); } - showToast(tr::lng_share_done(tr::now)); + show->showToast(tr::lng_share_done(tr::now)); }; auto filterCallback = [](not_null thread) { return Data::CanSend(thread, ChatRestriction::SendOther); @@ -591,15 +590,11 @@ void SettingsBox( box->getDelegate()->show(std::move(next)); }); const auto showToast = crl::guard(box, [=](QString text) { - Ui::ShowMultilineToast({ - .parentOverride = Ui::BoxShow(box).toastParent(), - .text = { text }, - }); + box->showToast(text); }); auto [shareLinkCallback, shareLinkLifetime] = ShareInviteLinkAction( peer, - showBox, - showToast); + box->uiShow()); shareLink = std::move(shareLinkCallback); box->lifetime().add(std::move(shareLinkLifetime)); } else { @@ -635,10 +630,8 @@ void SettingsBox( } QGuiApplication::clipboard()->setText(link); if (weakBox) { - Ui::ShowMultilineToast({ - .parentOverride = Ui::BoxShow(box).toastParent(), - .text = { tr::lng_create_channel_link_copied(tr::now) }, - }); + box->showToast( + tr::lng_create_channel_link_copied(tr::now)); } return true; }; @@ -735,7 +728,7 @@ void SettingsBox( StartRtmpProcess::FillRtmpRows( layout, false, - std::make_shared(box), + box->uiShow(), state->data.events(), &st::groupCallBoxLabel, &st::groupCallSettingsRtmpShowButton, @@ -795,8 +788,7 @@ void SettingsBox( std::pair, rpl::lifetime> ShareInviteLinkAction( not_null peer, - Fn)> showBox, - Fn showToast) { + std::shared_ptr show) { auto lifetime = rpl::lifetime(); struct State { State(not_null session) : session(session) { @@ -823,11 +815,11 @@ std::pair, rpl::lifetime> ShareInviteLinkAction( || state->linkListener.isEmpty()) { return false; } - showBox(ShareInviteLinkBox( + show->showBox(ShareInviteLinkBox( peer, *state->linkSpeaker, state->linkListener, - showToast)); + show)); return true; }; auto callback = [=] { diff --git a/Telegram/SourceFiles/calls/group/calls_group_settings.h b/Telegram/SourceFiles/calls/group/calls_group_settings.h index a4a829e908..598814ed2d 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_settings.h +++ b/Telegram/SourceFiles/calls/group/calls_group_settings.h @@ -25,8 +25,7 @@ void SettingsBox( [[nodiscard]] std::pair, rpl::lifetime> ShareInviteLinkAction( not_null peer, - Fn)> showBox, - Fn showToast); + std::shared_ptr show); class MicLevelTester final { public: diff --git a/Telegram/SourceFiles/calls/group/calls_group_toasts.cpp b/Telegram/SourceFiles/calls/group/calls_group_toasts.cpp index 4abaab3ece..55e67be95e 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_toasts.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_toasts.cpp @@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer.h" #include "data/data_group_call.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" +#include "ui/toast/toast.h" #include "lang/lang_keys.h" namespace Calls::Group { @@ -83,15 +83,13 @@ void Toasts::setupAllowedToSpeak() { _call->allowedToSpeakNotifications( ) | rpl::start_with_next([=] { if (_panel->isActive()) { - _panel->showToast({ - tr::lng_group_call_can_speak_here(tr::now), - }); + _panel->showToast(tr::lng_group_call_can_speak_here(tr::now)); } else { const auto real = _call->lookupReal(); const auto name = (real && !real->title().isEmpty()) ? real->title() : _call->peer()->name(); - Ui::ShowMultilineToast({ + Ui::Toast::Show({ .text = tr::lng_group_call_can_speak( tr::now, lt_chat, @@ -139,7 +137,7 @@ void Toasts::setupPinnedVideo() { : tr::lng_group_call_unpinned_screen); return key(tr::now, lt_user, peer->shortName()); }(); - _panel->showToast({ text }); + _panel->showToast(text); }, _lifetime); } @@ -148,9 +146,8 @@ void Toasts::setupRequestedToSpeak() { ) | rpl::combine_previous( ) | rpl::start_with_next([=](MuteState was, MuteState now) { if (was == MuteState::ForceMuted && now == MuteState::RaisedHand) { - _panel->showToast({ - tr::lng_group_call_tooltip_raised_hand(tr::now), - }); + _panel->showToast( + tr::lng_group_call_tooltip_raised_hand(tr::now)); } }, _lifetime); } diff --git a/Telegram/SourceFiles/chat_helpers/compose/compose_show.cpp b/Telegram/SourceFiles/chat_helpers/compose/compose_show.cpp new file mode 100644 index 0000000000..9a27c6f823 --- /dev/null +++ b/Telegram/SourceFiles/chat_helpers/compose/compose_show.cpp @@ -0,0 +1,46 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "chat_helpers/compose/compose_show.h" + +#include "core/application.h" +#include "main/main_session.h" +#include "window/window_controller.h" +#include "window/window_session_controller.h" + +namespace ChatHelpers { + +rpl::producer Show::adjustShadowLeft() const { + return rpl::single(false); +} + +Window::SessionController *Show::resolveWindow(WindowUsage usage) const { + const auto session = &this->session(); + const auto check = [&](Window::Controller *window) { + if (const auto controller = window->sessionController()) { + if (&controller->session() == session) { + return controller; + } + } + return (Window::SessionController*)nullptr; + }; + auto &app = Core::App(); + if (const auto a = check(app.activeWindow())) { + return a; + } else if (const auto b = check(app.activePrimaryWindow())) { + return b; + } else if (const auto c = check(app.windowFor(&session->account()))) { + return c; + } else if (const auto d = check( + app.ensureSeparateWindowForAccount( + &session->account()))) { + return d; + } + return nullptr; +} + +} // namespace ChatHelpers diff --git a/Telegram/SourceFiles/chat_helpers/compose/compose_show.h b/Telegram/SourceFiles/chat_helpers/compose/compose_show.h new file mode 100644 index 0000000000..ba2f391df6 --- /dev/null +++ b/Telegram/SourceFiles/chat_helpers/compose/compose_show.h @@ -0,0 +1,68 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "base/flags.h" +#include "main/session/session_show.h" + +class PhotoData; +class DocumentData; + +namespace Data { +struct FileOrigin; +} // namespace Data + +namespace Window { +class SessionController; +} // namespace Window + +namespace SendMenu { +enum class Type; +} // namespace SendMenu + +namespace ChatHelpers { + +struct FileChosen; + +enum class PauseReason { + Any = 0, + InlineResults = (1 << 0), + TabbedPanel = (1 << 1), + Layer = (1 << 2), + RoundPlaying = (1 << 3), + MediaPreview = (1 << 4), +}; +using PauseReasons = base::flags; +inline constexpr bool is_flag_type(PauseReason) { return true; }; + +enum class WindowUsage { + PremiumPromo, +}; + +class Show : public Main::SessionShow { +public: + [[nodiscard]] virtual bool paused(PauseReason reason) const = 0; + [[nodiscard]] virtual rpl::producer<> pauseChanged() const = 0; + + [[nodiscard]] virtual rpl::producer adjustShadowLeft() const; + [[nodiscard]] virtual SendMenu::Type sendMenuType() const = 0; + + virtual bool showMediaPreview( + Data::FileOrigin origin, + not_null document) const = 0; + virtual bool showMediaPreview( + Data::FileOrigin origin, + not_null photo) const = 0; + + virtual void processChosenSticker(FileChosen chosen) const = 0; + + [[nodiscard]] virtual Window::SessionController *resolveWindow( + WindowUsage) const; +}; + +} // namespace ChatHelpers diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 2183be4062..19dd9c827f 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -370,12 +370,11 @@ void EmojiColorPicker::drawVariant(QPainter &p, int variant) { EmojiListWidget::EmojiListWidget( QWidget *parent, not_null controller, - Window::GifPauseReason level, + PauseReason level, Mode mode) : EmojiListWidget(parent, { - .session = &controller->session(), + .show = controller->uiShow(), .mode = mode, - .controller = controller, .paused = Window::PausedIn(controller, level), }) { } @@ -386,9 +385,9 @@ EmojiListWidget::EmojiListWidget( : Inner( parent, descriptor.st ? *descriptor.st : st::defaultEmojiPan, - descriptor.session, + descriptor.show, std::move(descriptor.paused)) -, _controller(descriptor.controller) +, _show(std::move(descriptor.show)) , _mode(descriptor.mode) , _staticCount(_mode == Mode::Full ? kEmojiSectionCount : 1) , _premiumIcon(_mode == Mode::EmojiStatus @@ -466,7 +465,7 @@ EmojiListWidget::~EmojiListWidget() { } void EmojiListWidget::setupSearch() { - const auto session = &_controller->session(); + const auto session = &_show->session(); _search = MakeSearch(this, st(), [=](std::vector &&query) { _nextSearchQuery = std::move(query); InvokeQueued(this, [=] { @@ -1419,26 +1418,27 @@ void EmojiListWidget::mouseReleaseEvent(QMouseEvent *e) { Assert(button->section >= _staticCount && button->section < _staticCount + _custom.size()); const auto id = _custom[button->section - _staticCount].id; + const auto usage = ChatHelpers::WindowUsage::PremiumPromo; if (hasRemoveButton(button->section)) { removeSet(id); } else if (hasAddButton(button->section)) { _localSetsManager->install(id); - } else if (_controller) { + } else if (const auto resolved = _show->resolveWindow(usage)) { _jumpedToPremium.fire({}); switch (_mode) { case Mode::Full: case Mode::UserpicBuilder: - Settings::ShowPremium(_controller, u"animated_emoji"_q); + Settings::ShowPremium(resolved, u"animated_emoji"_q); break; case Mode::FullReactions: case Mode::RecentReactions: - Settings::ShowPremium(_controller, u"infinite_reactions"_q); + Settings::ShowPremium(resolved, u"infinite_reactions"_q); break; case Mode::EmojiStatus: - Settings::ShowPremium(_controller, u"emoji_status"_q); + Settings::ShowPremium(resolved, u"emoji_status"_q); break; case Mode::TopicIcon: - Settings::ShowPremium(_controller, u"forum_topic_icon"_q); + Settings::ShowPremium(resolved, u"forum_topic_icon"_q); break; } } @@ -1448,20 +1448,14 @@ void EmojiListWidget::mouseReleaseEvent(QMouseEvent *e) { void EmojiListWidget::displaySet(uint64 setId) { const auto &sets = session().data().stickers().sets(); auto it = sets.find(setId); - if (it != sets.cend() && _controller) { - checkHideWithBox(_controller->show( - Box(_controller, it->second.get()), - Ui::LayerOption::KeepOther).data()); + if (it != sets.cend()) { + checkHideWithBox(Box(_show, it->second.get())); } } void EmojiListWidget::removeSet(uint64 setId) { if (auto box = MakeConfirmRemoveSetBox(&session(), setId)) { - if (_controller) { - checkHideWithBox(_controller->show( - std::move(box), - Ui::LayerOption::KeepOther)); - } + checkHideWithBox(std::move(box)); } } diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h index e928bda692..fd307eda8c 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.h @@ -76,9 +76,8 @@ enum class EmojiListMode { }; struct EmojiListDescriptor { - not_null session; + std::shared_ptr show; EmojiListMode mode = EmojiListMode::Full; - Window::SessionController *controller = nullptr; Fn paused; std::vector customRecentList; Fn( @@ -87,7 +86,7 @@ struct EmojiListDescriptor { const style::EmojiPan *st = nullptr; }; -class EmojiListWidget +class EmojiListWidget final : public TabbedSelector::Inner , public Ui::AbstractTooltipShower { public: @@ -96,7 +95,7 @@ public: EmojiListWidget( QWidget *parent, not_null controller, - Window::GifPauseReason level, + PauseReason level, Mode mode); EmojiListWidget(QWidget *parent, EmojiListDescriptor &&descriptor); ~EmojiListWidget(); @@ -345,7 +344,7 @@ private: void applyNextSearchQuery(); - Window::SessionController *_controller = nullptr; + const std::shared_ptr _show; Mode _mode = Mode::Full; std::unique_ptr _search; const int _staticCount = 0; diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 724b347946..8b24df18a8 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -51,11 +51,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include +namespace { + [[nodiscard]] QString PrimaryUsername(not_null user) { const auto &usernames = user->usernames(); return usernames.empty() ? user->username() : usernames.front(); } +} // namespace + class FieldAutocomplete::Inner final : public Ui::RpWidget { public: struct ScrollTo { @@ -64,7 +68,7 @@ public: }; Inner( - not_null controller, + std::shared_ptr show, not_null parent, not_null mrows, not_null hrows, @@ -120,7 +124,8 @@ private: Media::Clip::Notification notification, not_null document); - const not_null _controller; + const std::shared_ptr _show; + const not_null _session; const not_null _parent; const not_null _mrows; const not_null _hrows; @@ -140,7 +145,7 @@ private: bool _previewShown = false; - bool _isOneColumn = false; + bool _adjustShadowLeft = false; const std::unique_ptr _pathGradient; StickerPremiumMark _premiumMark; @@ -182,8 +187,15 @@ struct FieldAutocomplete::BotCommandRow { FieldAutocomplete::FieldAutocomplete( QWidget *parent, not_null controller) +: FieldAutocomplete(parent, controller->uiShow()) { +} + +FieldAutocomplete::FieldAutocomplete( + QWidget *parent, + std::shared_ptr show) : RpWidget(parent) -, _controller(controller) +, _show(std::move(show)) +, _session(&_show->session()) , _scroll(this) { hide(); @@ -191,7 +203,7 @@ FieldAutocomplete::FieldAutocomplete( _inner = _scroll->setOwnedWidget( object_ptr( - _controller, + _show, this, &_mrows, &_hrows, @@ -215,8 +227,8 @@ FieldAutocomplete::FieldAutocomplete( }), lifetime()); } -not_null FieldAutocomplete::controller() const { - return _controller; +std::shared_ptr FieldAutocomplete::uiShow() const { + return _show; } auto FieldAutocomplete::mentionChosen() const @@ -365,7 +377,7 @@ inline int indexOfInFirstN(const T &v, const U &elem, int last) { } FieldAutocomplete::StickerRows FieldAutocomplete::getStickerSuggestions() { - const auto data = &_controller->session().data().stickers(); + const auto data = &_session->data().stickers(); const auto list = data->getListByEmoji({ _emoji }, _stickersSeed); auto result = ranges::views::all( list @@ -804,13 +816,14 @@ bool FieldAutocomplete::eventFilter(QObject *obj, QEvent *e) { } FieldAutocomplete::Inner::Inner( - not_null controller, + std::shared_ptr show, not_null parent, not_null mrows, not_null hrows, not_null brows, not_null srows) -: _controller(controller) +: _show(std::move(show)) +, _session(&_show->session()) , _parent(parent) , _mrows(mrows) , _hrows(hrows) @@ -820,16 +833,16 @@ FieldAutocomplete::Inner::Inner( st::windowBgRipple, st::windowBgOver, [=] { update(); })) -, _premiumMark(&controller->session()) +, _premiumMark(_session) , _previewTimer([=] { showPreview(); }) { - controller->session().downloaderTaskFinished( + _session->downloaderTaskFinished( ) | rpl::start_with_next([=] { update(); }, lifetime()); - controller->adaptive().value( - ) | rpl::start_with_next([=] { - _isOneColumn = controller->adaptive().isOneColumn(); + _show->adjustShadowLeft( + ) | rpl::start_with_next([=](bool adjust) { + _adjustShadowLeft = adjust; update(); }, lifetime()); } @@ -891,8 +904,8 @@ void FieldAutocomplete::Inner::paintEvent(QPaintEvent *e) { } media->checkStickerSmall(); - const auto paused = _controller->isGifPausedAtLeastFor( - Window::GifPauseReason::TabbedPanel); + const auto paused = _show->paused( + ChatHelpers::PauseReason::TabbedPanel); const auto size = ChatHelpers::ComputeStickerSize( document, stickerBoundingBox()); @@ -1062,9 +1075,19 @@ void FieldAutocomplete::Inner::paintEvent(QPaintEvent *e) { } } } - p.fillRect(_isOneColumn ? 0 : st::lineWidth, _parent->innerBottom() - st::lineWidth, width() - (_isOneColumn ? 0 : st::lineWidth), st::lineWidth, st::shadowFg); + p.fillRect( + _adjustShadowLeft ? st::lineWidth : 0, + _parent->innerBottom() - st::lineWidth, + width() - (_adjustShadowLeft ? st::lineWidth : 0), + st::lineWidth, + st::shadowFg); } - p.fillRect(_isOneColumn ? 0 : st::lineWidth, _parent->innerTop(), width() - (_isOneColumn ? 0 : st::lineWidth), st::lineWidth, st::shadowFg); + p.fillRect( + _adjustShadowLeft ? st::lineWidth : 0, + _parent->innerTop(), + width() - (_adjustShadowLeft ? st::lineWidth : 0), + st::lineWidth, + st::shadowFg); } void FieldAutocomplete::Inner::resizeEvent(QResizeEvent *e) { @@ -1158,7 +1181,7 @@ bool FieldAutocomplete::Inner::chooseAtIndex( contentRect.moveCenter(bounding.center()); return { Ui::MessageSendingAnimationFrom::Type::Sticker, - _controller->session().data().nextLocalMessageId(), + _show->session().data().nextLocalMessageId(), mapToGlobal(std::move(contentRect)), }; }; @@ -1231,7 +1254,7 @@ void FieldAutocomplete::Inner::mousePressEvent(QMouseEvent *e) { } } if (removed) { - _controller->session().local().writeRecentHashtagsAndBots(); + _show->session().local().writeRecentHashtagsAndBots(); } _parent->updateFiltered(); @@ -1483,11 +1506,7 @@ void FieldAutocomplete::Inner::selectByMouse(QPoint globalPosition) { setSel(sel); if (_down >= 0 && _sel >= 0 && _down != _sel) { _down = _sel; - if (_down >= 0 && _down < _srows->size()) { - _controller->widget()->showMediaPreview( - (*_srows)[_down].document->stickerSetOrigin(), - (*_srows)[_down].document); - } + showPreview(); } } } @@ -1504,9 +1523,8 @@ void FieldAutocomplete::Inner::onParentGeometryChanged() { void FieldAutocomplete::Inner::showPreview() { if (_down >= 0 && _down < _srows->size()) { - _controller->widget()->showMediaPreview( - (*_srows)[_down].document->stickerSetOrigin(), - (*_srows)[_down].document); + const auto document = (*_srows)[_down].document; + _show->showMediaPreview(document->stickerSetOrigin(), document); _previewShown = true; } } diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h index a03d4c8402..1bb75f122e 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h @@ -25,6 +25,10 @@ class SinglePlayer; class FrameRenderer; } // namespace Lottie; +namespace Main { +class Session; +} // namespace Main + namespace Window { class SessionController; } // namespace Window @@ -39,6 +43,7 @@ enum class Type; namespace ChatHelpers { struct FileChosen; +class Show; } // namespace ChatHelpers class FieldAutocomplete final : public Ui::RpWidget { @@ -46,9 +51,12 @@ public: FieldAutocomplete( QWidget *parent, not_null controller); + FieldAutocomplete( + QWidget *parent, + std::shared_ptr show); ~FieldAutocomplete(); - [[nodiscard]] not_null controller() const; + [[nodiscard]] std::shared_ptr uiShow() const; bool clearFilteredBotCommands(); void showFiltered( @@ -112,6 +120,8 @@ public: void setSendMenuType(Fn &&callback); void hideFast(); + void showAnimated(); + void hideAnimated(); rpl::producer mentionChosen() const; rpl::producer hashtagChosen() const; @@ -119,10 +129,6 @@ public: rpl::producer stickerChosen() const; rpl::producer choosingProcesses() const; -public Q_SLOTS: - void showAnimated(); - void hideAnimated(); - protected: void paintEvent(QPaintEvent *e) override; @@ -145,7 +151,8 @@ private: void recount(bool resetScroll = false); StickerRows getStickerSuggestions(); - const not_null _controller; + const std::shared_ptr _show; + const not_null _session; QPixmap _cache; MentionRows _mrows; HashtagRows _hrows; diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 668dc02310..d8ba04cf51 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -56,7 +56,7 @@ constexpr auto kMinAfterScrollDelay = crl::time(33); void AddGifAction( Fn &&, const style::icon*)> callback, - Window::SessionController *controller, + std::shared_ptr show, not_null document) { if (!document->isGifv()) { return; @@ -69,7 +69,7 @@ void AddGifAction( : tr::lng_context_save_gif)(tr::now); callback(text, [=] { Api::ToggleSavedGif( - controller, + show, document, Data::FileOriginSavedGifs(), !saved); @@ -86,13 +86,22 @@ void AddGifAction( GifsListWidget::GifsListWidget( QWidget *parent, not_null controller, - Window::GifPauseReason level) + PauseReason level) +: GifsListWidget(parent, { + .show = controller->uiShow(), + .paused = Window::PausedIn(controller, level), +}) { +} + +GifsListWidget::GifsListWidget( + QWidget *parent, + GifsListDescriptor &&descriptor) : Inner( parent, st::defaultEmojiPan, - &controller->session(), - Window::PausedIn(controller, level)) -, _controller(controller) + descriptor.show, + descriptor.paused) +, _show(std::move(descriptor.show)) , _api(&session().mtp()) , _section(Section::Gifs) , _updateInlineItems([=] { updateInlineItems(); }) @@ -120,7 +129,7 @@ GifsListWidget::GifsListWidget( updateInlineItems(); }, lifetime()); - controller->gifPauseLevelChanged( + _show->pauseChanged( ) | rpl::start_with_next([=] { if (!paused()) { updateInlineItems(); @@ -395,7 +404,7 @@ base::unique_qptr GifsListWidget::fillContextMenu( const style::icon *icon) { menu->addAction(text, std::move(done), icon); }; - AddGifAction(std::move(callback), _controller, document); + AddGifAction(std::move(callback), _show, document); } } return menu; @@ -425,7 +434,7 @@ void GifsListWidget::mouseReleaseEvent(QMouseEvent *e) { ActivateClickHandler(window(), activated, { e->button(), QVariant::fromValue(ClickHandlerContext{ - .sessionWindow = base::make_weak(_controller), + .show = _show, }) }); } @@ -794,7 +803,7 @@ bool GifsListWidget::refreshInlineRows(int32 *added) { } void GifsListWidget::setupSearch() { - const auto session = &_controller->session(); + const auto session = &_show->session(); _search = MakeSearch(this, st(), [=](std::vector &&query) { const auto accumulated = ranges::accumulate(query, QString(), []( QString a, @@ -939,13 +948,11 @@ void GifsListWidget::updateSelected() { _pressed = _selected; if (item) { if (const auto preview = item->getPreviewDocument()) { - _controller->widget()->showMediaPreview( + _show->showMediaPreview( Data::FileOriginSavedGifs(), preview); } else if (const auto preview = item->getPreviewPhoto()) { - _controller->widget()->showMediaPreview( - Data::FileOrigin(), - preview); + _show->showMediaPreview(Data::FileOrigin(), preview); } } } @@ -961,11 +968,11 @@ void GifsListWidget::showPreview() { } if (const auto layout = _mosaic.maybeItemAt(_pressed)) { if (const auto previewDocument = layout->getPreviewDocument()) { - _previewShown = _controller->widget()->showMediaPreview( + _previewShown = _show->showMediaPreview( Data::FileOriginSavedGifs(), previewDocument); } else if (const auto previewPhoto = layout->getPreviewPhoto()) { - _previewShown = _controller->widget()->showMediaPreview( + _previewShown = _show->showMediaPreview( Data::FileOrigin(), previewPhoto); } diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h index c4e007f731..d21c8e5315 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h @@ -47,21 +47,28 @@ namespace ChatHelpers { void AddGifAction( Fn &&, const style::icon*)> callback, - Window::SessionController *controller, + std::shared_ptr show, not_null document); class StickersListFooter; struct StickerIcon; struct GifSection; -class GifsListWidget +struct GifsListDescriptor { + std::shared_ptr show; + Fn paused; + const style::EmojiPan *st = nullptr; +}; + +class GifsListWidget final : public TabbedSelector::Inner , public InlineBots::Layout::Context { public: GifsListWidget( QWidget *parent, not_null controller, - Window::GifPauseReason level); + PauseReason level); + GifsListWidget(QWidget *parent, GifsListDescriptor &&descriptor); rpl::producer fileChosen() const; rpl::producer photoChosen() const; @@ -162,7 +169,7 @@ private: Api::SendOptions options, bool forceSend = false); - not_null _controller; + const std::shared_ptr _show; std::unique_ptr _search; MTP::Sender _api; diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index ddceac33f5..36696ccab0 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -125,8 +125,7 @@ QString FieldTagMimeProcessor::operator()(QStringView mimeTag) { void EditLinkBox( not_null box, - std::shared_ptr show, - not_null session, + std::shared_ptr show, const QString &startText, const QString &startLink, Fn callback, @@ -149,8 +148,8 @@ void EditLinkBox( Ui::Emoji::SuggestionsController::Init( box->getDelegate()->outerContainer(), text, - session); - InitSpellchecker(std::move(show), session, text, fieldStyle != nullptr); + &show->session()); + InitSpellchecker(show, text, fieldStyle != nullptr); const auto placeholder = content->add( object_ptr(content), @@ -284,8 +283,7 @@ Fn DefaultEditLinkCallback( - std::shared_ptr show, - not_null session, + std::shared_ptr show, not_null field, const style::InputField *fieldStyle) { const auto weak = Ui::MakeWeak(field); @@ -303,23 +301,20 @@ FncommitMarkdownLinkEdit(selection, text, link); } }; - show->showBox( - Box( - EditLinkBox, - show, - session, - text, - link, - std::move(callback), - fieldStyle), - Ui::LayerOption::KeepOther); + show->showBox(Box( + EditLinkBox, + show, + text, + link, + std::move(callback), + fieldStyle)); return true; }; } void InitMessageFieldHandlers( not_null session, - std::shared_ptr show, + std::shared_ptr show, not_null field, Fn customEmojiPaused, Fn)> allowPremiumEmoji, @@ -338,19 +333,19 @@ void InitMessageFieldHandlers( field->setMarkdownReplacesEnabled(rpl::single(true)); if (show) { field->setEditLinkCallback( - DefaultEditLinkCallback(show, session, field, fieldStyle)); - InitSpellchecker(show, session, field, fieldStyle != nullptr); + DefaultEditLinkCallback(show, field, fieldStyle)); + InitSpellchecker(show, field, fieldStyle != nullptr); } } void InitMessageFieldHandlers( not_null controller, not_null field, - Window::GifPauseReason pauseReasonLevel, + ChatHelpers::PauseReason pauseReasonLevel, Fn)> allowPremiumEmoji) { InitMessageFieldHandlers( &controller->session(), - std::make_shared(controller), + controller->uiShow(), field, [=] { return controller->isGifPausedAtLeastFor(pauseReasonLevel); }, allowPremiumEmoji); @@ -366,25 +361,36 @@ void InitMessageFieldGeometry(not_null field) { } void InitMessageField( - not_null controller, + std::shared_ptr show, not_null field, Fn)> allowPremiumEmoji) { InitMessageFieldHandlers( - controller, + &show->session(), + show, field, - Window::GifPauseReason::Any, - allowPremiumEmoji); + [=] { return show->paused(ChatHelpers::PauseReason::Any); }, + std::move(allowPremiumEmoji)); InitMessageFieldGeometry(field); field->customTab(true); } +void InitMessageField( + not_null controller, + not_null field, + Fn)> allowPremiumEmoji) { + return InitMessageField( + controller->uiShow(), + field, + std::move(allowPremiumEmoji)); +} + void InitSpellchecker( - std::shared_ptr show, - not_null session, + std::shared_ptr show, not_null field, bool skipDictionariesManager) { #ifndef TDESKTOP_DISABLE_SPELLCHECK using namespace Spellchecker; + const auto session = &show->session(); const auto menuItem = skipDictionariesManager ? std::nullopt : std::make_optional(SpellingHighlighter::CustomContextMenuItem{ @@ -856,7 +862,7 @@ base::unique_qptr CreateDisabledFieldView( *toast = Ui::Toast::Show(parent, { .text = { tr::lng_send_text_no_about(tr::now, lt_types, types) }, .st = &st::defaultMultilineToast, - .durationMs = kTypesDuration, + .duration = kTypesDuration, .multiline = true, .slideSide = RectPart::Bottom, }); diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index 8efa27c2c8..727e51a5b5 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -20,16 +20,20 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Main { class Session; +class SessionShow; } // namespace Main namespace Window { class SessionController; -enum class GifPauseReason; } // namespace Window +namespace ChatHelpers { +enum class PauseReason; +class Show; +} // namespace ChatHelpers + namespace Ui { class PopupMenu; -class Show; } // namespace Ui QString PrepareMentionTag(not_null user); @@ -40,13 +44,12 @@ Fn DefaultEditLinkCallback( - std::shared_ptr show, - not_null session, + std::shared_ptr show, not_null field, const style::InputField *fieldStyle = nullptr); void InitMessageFieldHandlers( not_null session, - std::shared_ptr show, + std::shared_ptr show, // may be null not_null field, Fn customEmojiPaused, Fn)> allowPremiumEmoji = nullptr, @@ -54,16 +57,19 @@ void InitMessageFieldHandlers( void InitMessageFieldHandlers( not_null controller, not_null field, - Window::GifPauseReason pauseReasonLevel, + ChatHelpers::PauseReason pauseReasonLevel, Fn)> allowPremiumEmoji = nullptr); +void InitMessageField( + std::shared_ptr show, + not_null field, + Fn)> allowPremiumEmoji); void InitMessageField( not_null controller, not_null field, Fn)> allowPremiumEmoji); void InitSpellchecker( - std::shared_ptr show, - not_null session, + std::shared_ptr show, not_null field, bool skipDictionariesManager = false); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 55a356ba53..349980b6c8 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -165,19 +165,29 @@ void StickersListWidget::Sticker::ensureMediaCreated() { StickersListWidget::StickersListWidget( QWidget *parent, not_null controller, - Window::GifPauseReason level, + PauseReason level, Mode mode) +: StickersListWidget(parent, { + .show = controller->uiShow(), + .mode = mode, + .paused = Window::PausedIn(controller, level), +}) { +} + +StickersListWidget::StickersListWidget( + QWidget *parent, + StickersListDescriptor &&descriptor) : Inner( parent, st::defaultEmojiPan, - &controller->session(), - Window::PausedIn(controller, level)) -, _mode(mode) -, _controller(controller) + descriptor.show, + descriptor.paused) +, _mode(descriptor.mode) +, _show(std::move(descriptor.show)) , _api(&session().mtp()) , _localSetsManager(std::make_unique(&session())) , _section(Section::Stickers) -, _isMasks(mode == Mode::Masks) +, _isMasks(_mode == Mode::Masks) , _updateItemsTimer([=] { updateItems(); }) , _updateSetsTimer([=] { updateSets(); }) , _trendingAddBgOver( @@ -210,9 +220,8 @@ StickersListWidget::StickersListWidget( _settings->addClickHandler([=] { using Section = StickersBox::Section; - controller->show( - Box(controller, Section::Installed, _isMasks), - Ui::LayerOption::KeepOther); + _show->showBox( + Box(_show, Section::Installed, _isMasks)); }); session().downloaderTaskFinished( @@ -287,15 +296,14 @@ object_ptr StickersListWidget::createFooter() { _footer->openSettingsRequests( ) | rpl::start_with_next([=] { const auto onlyFeatured = _footer->hasOnlyFeaturedSets(); - _controller->show(Box( - _controller, + _show->showBox(Box( + _show, (onlyFeatured ? StickersBox::Section::Featured : _isMasks ? StickersBox::Section::Masks : StickersBox::Section::Installed), - onlyFeatured ? false : _isMasks), - Ui::LayerOption::KeepOther); + onlyFeatured ? false : _isMasks)); }, _footer->lifetime()); return result; @@ -1569,7 +1577,10 @@ QPoint StickersListWidget::buttonRippleTopLeft(int section) const { void StickersListWidget::showStickerSetBox(not_null document) { if (document->sticker() && document->sticker()->set) { - checkHideWithBox(StickerSetBox::Show(_controller, document)); + checkHideWithBox(Box( + _show, + document->sticker()->set, + document->sticker()->setType)); } } @@ -1611,10 +1622,10 @@ base::unique_qptr StickersListWidget::fillContextMenu( SendMenu::DefaultScheduleCallback(this, type, send), SendMenu::DefaultWhenOnlineCallback(send)); - const auto window = _controller; + const auto show = _show; const auto toggleFavedSticker = [=] { Api::ToggleFavedSticker( - window, + show, document, Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0)); }; @@ -1716,7 +1727,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) { removeSet(sets[button->section].id); } } else if (std::get_if(&pressed)) { - _controller->show(Box(_controller, _megagroupSet)); + _show->showBox(Box(_show, _megagroupSet)); } } } @@ -1774,9 +1785,9 @@ void StickersListWidget::removeFavedSticker(int section, int index) { clearSelection(); const auto &sticker = _mySets[section].stickers[index]; const auto document = sticker.document; - session().data().stickers().setFaved(_controller, document, false); + session().data().stickers().setFaved(_show, document, false); Api::ToggleFavedSticker( - _controller, + _show, document, Data::FileOriginStickerSet(Data::Stickers::FavedSetId, 0), false); @@ -2427,9 +2438,7 @@ void StickersListWidget::setSelected(OverState newSelected) { const auto &set = sets[sticker->section]; Assert(sticker->index >= 0 && sticker->index < set.stickers.size()); const auto document = set.stickers[sticker->index].document; - _controller->widget()->showMediaPreview( - document->stickerSetOrigin(), - document); + _show->showMediaPreview(document->stickerSetOrigin(), document); } } } @@ -2442,9 +2451,7 @@ void StickersListWidget::showPreview() { const auto &set = sets[sticker->section]; Assert(sticker->index >= 0 && sticker->index < set.stickers.size()); const auto document = set.stickers[sticker->index].document; - _controller->widget()->showMediaPreview( - document->stickerSetOrigin(), - document); + _show->showMediaPreview(document->stickerSetOrigin(), document); _previewShown = true; } } @@ -2565,7 +2572,7 @@ void StickersListWidget::beforeHiding() { } void StickersListWidget::setupSearch() { - const auto session = &_controller->session(); + const auto session = &_show->session(); _search = MakeSearch(this, st(), [=](std::vector &&query) { auto set = base::flat_set(); auto text = ranges::accumulate(query, QString(), []( @@ -2580,9 +2587,7 @@ void StickersListWidget::setupSearch() { void StickersListWidget::displaySet(uint64 setId) { if (setId == Data::Stickers::MegagroupSetId) { if (_megagroupSet->canEditStickers()) { - checkHideWithBox(_controller->show( - Box(_controller, _megagroupSet), - Ui::LayerOption::KeepOther).data()); + checkHideWithBox(Box(_show, _megagroupSet)); return; } else if (_megagroupSet->mgInfo->stickerSet.id) { setId = _megagroupSet->mgInfo->stickerSet.id; @@ -2593,9 +2598,7 @@ void StickersListWidget::displaySet(uint64 setId) { const auto &sets = session().data().stickers().sets(); auto it = sets.find(setId); if (it != sets.cend()) { - checkHideWithBox(_controller->show( - Box(_controller, it->second.get()), - Ui::LayerOption::KeepOther).data()); + checkHideWithBox(Box(_show, it->second.get())); } } @@ -2606,10 +2609,7 @@ void StickersListWidget::removeMegagroupSet(bool locally) { refreshStickers(); return; } - const auto cancelled = [](Fn &&close) { - close(); - }; - checkHideWithBox(_controller->show(Ui::MakeConfirmBox({ + checkHideWithBox(Ui::MakeConfirmBox({ .text = tr::lng_stickers_remove_group_set(), .confirmed = crl::guard(this, [this, group = _megagroupSet]( Fn &&close) { @@ -2620,8 +2620,8 @@ void StickersListWidget::removeMegagroupSet(bool locally) { } close(); }), - .cancelled = cancelled, - }))); + .cancelled = [](Fn &&close) { close(); }, + })); } void StickersListWidget::removeSet(uint64 setId) { @@ -2633,9 +2633,7 @@ void StickersListWidget::removeSet(uint64 setId) { || !_megagroupSet->canEditStickers(); removeMegagroupSet(removeLocally); } else if (auto box = MakeConfirmRemoveSetBox(&session(), setId)) { - checkHideWithBox(_controller->show( - std::move(box), - Ui::LayerOption::KeepOther)); + checkHideWithBox(std::move(box)); } } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 1c0d8445c9..afde28b81e 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -65,6 +65,13 @@ enum class StickersListMode { UserpicBuilder, }; +struct StickersListDescriptor { + std::shared_ptr show; + StickersListMode mode = StickersListMode::Full; + Fn paused; + const style::EmojiPan *st = nullptr; +}; + class StickersListWidget final : public TabbedSelector::Inner { public: using Mode = StickersListMode; @@ -72,8 +79,11 @@ public: StickersListWidget( QWidget *parent, not_null controller, - Window::GifPauseReason level, + PauseReason level, Mode mode = Mode::Full); + StickersListWidget( + QWidget *parent, + StickersListDescriptor &&descriptor); rpl::producer chosen() const; rpl::producer<> scrollUpdated() const; @@ -340,8 +350,7 @@ private: not_null document); const Mode _mode; - - not_null _controller; + const std::shared_ptr _show; std::unique_ptr _search; MTP::Sender _api; std::unique_ptr _localSetsManager; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index 606145eec8..5321e649e4 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -37,25 +37,31 @@ TabbedPanel::TabbedPanel( QWidget *parent, not_null controller, not_null selector) -: TabbedPanel(parent, controller, { nullptr }, selector) { +: TabbedPanel(parent, { + .regularWindow = controller, + .nonOwnedSelector = selector, +}) { } TabbedPanel::TabbedPanel( QWidget *parent, not_null controller, object_ptr selector) -: TabbedPanel(parent, controller, std::move(selector), nullptr) { +: TabbedPanel(parent, { + .regularWindow = controller, + .ownedSelector = std::move(selector), +}) { } TabbedPanel::TabbedPanel( QWidget *parent, - not_null controller, - object_ptr ownedSelector, - TabbedSelector *nonOwnedSelector) + TabbedPanelDescriptor &&descriptor) : RpWidget(parent) -, _controller(controller) -, _ownedSelector(std::move(ownedSelector)) -, _selector(nonOwnedSelector ? nonOwnedSelector : _ownedSelector.data()) +, _regularWindow(descriptor.regularWindow) +, _ownedSelector(std::move(descriptor.ownedSelector)) +, _selector(descriptor.nonOwnedSelector + ? descriptor.nonOwnedSelector + : _ownedSelector.data()) , _heightRatio(st::emojiPanHeightRatio) , _minContentHeight(st::emojiPanMinHeight) , _maxContentHeight(st::emojiPanMaxHeight) { @@ -64,17 +70,25 @@ TabbedPanel::TabbedPanel( _selector->setParent(this); _selector->setRoundRadius(st::emojiPanRadius); _selector->setAfterShownCallback([=](SelectorTab tab) { - _controller->enableGifPauseReason(_selector->level()); + if (_regularWindow) { + _regularWindow->enableGifPauseReason(_selector->level()); + } + _pauseAnimations.fire(true); }); _selector->setBeforeHidingCallback([=](SelectorTab tab) { - _controller->disableGifPauseReason(_selector->level()); + if (_regularWindow) { + _regularWindow->disableGifPauseReason(_selector->level()); + } + _pauseAnimations.fire(false); }); _selector->showRequests( ) | rpl::start_with_next([=] { showFromSelector(); }, lifetime()); - resize(QRect(0, 0, st::emojiPanWidth, st::emojiPanMaxHeight).marginsAdded(innerPadding()).size()); + resize( + QRect(0, 0, st::emojiPanWidth, st::emojiPanMaxHeight).marginsAdded( + innerPadding()).size()); _contentMaxHeight = st::emojiPanMaxHeight; _contentHeight = _contentMaxHeight; @@ -122,6 +136,10 @@ not_null TabbedPanel::selector() const { return _selector; } +rpl::producer TabbedPanel::pauseAnimations() const { + return _pauseAnimations.events(); +} + bool TabbedPanel::isSelectorStolen() const { return (_selector->parent() != this); } @@ -478,8 +496,8 @@ bool TabbedPanel::overlaps(const QRect &globalRect) const { TabbedPanel::~TabbedPanel() { hideFast(); - if (!_ownedSelector) { - _controller->takeTabbedSelectorOwnershipFrom(this); + if (!_ownedSelector && _regularWindow) { + _regularWindow->takeTabbedSelectorOwnershipFrom(this); } } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h index c592c4a489..153c19581b 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h @@ -26,6 +26,12 @@ class TabbedSelector; extern const char kOptionTabbedPanelShowOnClick[]; +struct TabbedPanelDescriptor { + Window::SessionController *regularWindow = nullptr; + object_ptr ownedSelector = { nullptr }; + TabbedSelector *nonOwnedSelector = nullptr; +};; + class TabbedPanel : public Ui::RpWidget { public: TabbedPanel( @@ -36,9 +42,11 @@ public: QWidget *parent, not_null controller, object_ptr selector); + TabbedPanel(QWidget *parent, TabbedPanelDescriptor &&descriptor); [[nodiscard]] bool isSelectorStolen() const; [[nodiscard]] not_null selector() const; + [[nodiscard]] rpl::producer pauseAnimations() const; void moveBottomRight(int bottom, int right); void moveTopRight(int top, int right); @@ -71,12 +79,6 @@ protected: bool eventFilter(QObject *obj, QEvent *e) override; private: - TabbedPanel( - QWidget *parent, - not_null controller, - object_ptr ownedSelector, - TabbedSelector *nonOwnedSelector); - void hideByTimerOrLeave(); void moveHorizontally(); void showFromSelector(); @@ -99,9 +101,10 @@ private: bool preventAutoHide() const; void updateContentHeight(); - const not_null _controller; + Window::SessionController * const _regularWindow = nullptr; const object_ptr _ownedSelector = { nullptr }; const not_null _selector; + rpl::event_stream _pauseAnimations; int _contentMaxHeight = 0; int _contentHeight = 0; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index d34884edfe..463b35f165 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -322,12 +322,12 @@ std::unique_ptr MakeSearch( TabbedSelector::TabbedSelector( QWidget *parent, - not_null controller, - Window::GifPauseReason level, + std::shared_ptr show, + PauseReason level, Mode mode) : RpWidget(parent) , _st((mode == Mode::EmojiStatus) ? st::statusEmojiPan : st::defaultEmojiPan) -, _controller(controller) +, _show(std::move(show)) , _level(level) , _mode(mode) , _panelRounding(Ui::PrepareCornerPixmaps(st::emojiPanRadius, _st.bg)) @@ -470,38 +470,59 @@ TabbedSelector::TabbedSelector( TabbedSelector::~TabbedSelector() = default; Main::Session &TabbedSelector::session() const { - return _controller->session(); + return _show->session(); } -Window::GifPauseReason TabbedSelector::level() const { +PauseReason TabbedSelector::level() const { return _level; } TabbedSelector::Tab TabbedSelector::createTab(SelectorTab type, int index) { auto createWidget = [&]() -> object_ptr { + const auto paused = [show = _show, level = _level] { + return show->paused(level); + }; switch (type) { - case SelectorTab::Emoji: + case SelectorTab::Emoji: { using EmojiMode = EmojiListWidget::Mode; using Descriptor = EmojiListDescriptor; return object_ptr(this, Descriptor{ - .session = &_controller->session(), + .show = _show, .mode = (_mode == Mode::EmojiStatus ? EmojiMode::EmojiStatus : EmojiMode::Full), - .controller = _controller, - .paused = Window::PausedIn(_controller, _level), + .paused = paused, .st = &_st, }); - case SelectorTab::Stickers: - return object_ptr(this, _controller, _level); - case SelectorTab::Gifs: - return object_ptr(this, _controller, _level); - case SelectorTab::Masks: - return object_ptr( - this, - _controller, - _level, - StickersListWidget::Mode::Masks); + } + case SelectorTab::Stickers: { + using StickersMode = StickersListWidget::Mode; + using Descriptor = StickersListDescriptor; + return object_ptr(this, Descriptor{ + .show = _show, + .mode = StickersMode::Full, + .paused = paused, + .st = &_st, + }); + } + case SelectorTab::Gifs: { + using Descriptor = GifsListDescriptor; + return object_ptr(this, Descriptor{ + .show = _show, + .paused = paused, + .st = &_st, + }); + } + case SelectorTab::Masks: { + using StickersMode = StickersListWidget::Mode; + using Descriptor = StickersListDescriptor; + return object_ptr(this, Descriptor{ + .show = _show, + .mode = StickersMode::Masks, + .paused = paused, + .st = &_st, + }); + } } Unexpected("Type in TabbedSelector::createTab."); }; @@ -1237,23 +1258,24 @@ not_null TabbedSelector::currentTab() const { TabbedSelector::Inner::Inner( QWidget *parent, - not_null controller, - Window::GifPauseReason level) + std::shared_ptr show, + PauseReason level) : Inner( parent, st::defaultEmojiPan, - &controller->session(), - Window::PausedIn(controller, level)) { + show, + [show, level] { return show->paused(level); }) { } TabbedSelector::Inner::Inner( QWidget *parent, const style::EmojiPan &st, - not_null session, + std::shared_ptr show, Fn paused) : RpWidget(parent) , _st(st) -, _session(session) +, _show(std::move(show)) +, _session(&_show->session()) , _paused(paused) { } @@ -1273,12 +1295,15 @@ void TabbedSelector::Inner::disableScroll(bool disabled) { _disableScrollRequests.fire_copy(disabled); } -void TabbedSelector::Inner::checkHideWithBox(QPointer box) { - if (!box) { +void TabbedSelector::Inner::checkHideWithBox( + object_ptr box) { + const auto raw = QPointer(box.data()); + _show->showBox(std::move(box)); + if (!raw) { return; } _preventHideWithBox = true; - connect(box, &QObject::destroyed, this, [=] { + connect(raw, &QObject::destroyed, this, [=] { _preventHideWithBox = false; _checkForHide.fire({}); }); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 74036ab302..f7f65811a7 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -34,11 +34,6 @@ class BoxContent; class TabbedSearch; } // namespace Ui -namespace Window { -class SessionController; -enum class GifPauseReason; -} // namespace Window - namespace SendMenu { enum class Type; } // namespace SendMenu @@ -49,9 +44,11 @@ struct EmojiPan; namespace ChatHelpers { +class Show; class EmojiListWidget; class StickersListWidget; class GifsListWidget; +enum class PauseReason; enum class SelectorTab { Emoji, @@ -102,31 +99,32 @@ public: TabbedSelector( QWidget *parent, - not_null controller, - Window::GifPauseReason level, + std::shared_ptr show, + PauseReason level, Mode mode = Mode::Full); ~TabbedSelector(); - Main::Session &session() const; - Window::GifPauseReason level() const; + [[nodiscard]] Main::Session &session() const; + [[nodiscard]] PauseReason level() const; - rpl::producer emojiChosen() const; - rpl::producer customEmojiChosen() const; - rpl::producer fileChosen() const; - rpl::producer photoChosen() const; - rpl::producer inlineResultChosen() const; + [[nodiscard]] rpl::producer emojiChosen() const; + [[nodiscard]] rpl::producer customEmojiChosen() const; + [[nodiscard]] rpl::producer fileChosen() const; + [[nodiscard]] rpl::producer photoChosen() const; + [[nodiscard]] rpl::producer inlineResultChosen() const; - rpl::producer<> cancelled() const; - rpl::producer<> checkForHide() const; - rpl::producer<> slideFinished() const; - rpl::producer<> contextMenuRequested() const; - rpl::producer choosingStickerUpdated() const; + [[nodiscard]] rpl::producer<> cancelled() const; + [[nodiscard]] rpl::producer<> checkForHide() const; + [[nodiscard]] rpl::producer<> slideFinished() const; + [[nodiscard]] rpl::producer<> contextMenuRequested() const; + [[nodiscard]] rpl::producer choosingStickerUpdated() const; void setAllowEmojiWithoutPremium(bool allow); void setRoundRadius(int radius); void refreshStickers(); void setCurrentPeer(PeerData *peer); - void provideRecentEmoji(const std::vector &customRecentList); + void provideRecentEmoji( + const std::vector &customRecentList); void hideFinished(); void showStarted(); @@ -256,8 +254,8 @@ private: not_null masks() const; const style::EmojiPan &_st; - const not_null _controller; - const Window::GifPauseReason _level = {}; + const std::shared_ptr _show; + const PauseReason _level = {}; Mode _mode = Mode::Full; int _roundRadius = 0; @@ -299,12 +297,12 @@ class TabbedSelector::Inner : public Ui::RpWidget { public: Inner( QWidget *parent, - not_null controller, - Window::GifPauseReason level); + std::shared_ptr show, + PauseReason level); Inner( QWidget *parent, const style::EmojiPan &st, - not_null session, + std::shared_ptr show, Fn paused); [[nodiscard]] Main::Session &session() const { @@ -374,7 +372,7 @@ protected: void scrollTo(int y); void disableScroll(bool disabled); - void checkHideWithBox(QPointer box); + void checkHideWithBox(object_ptr box); void paintEmptySearchResults( Painter &p, @@ -383,6 +381,7 @@ protected: private: const style::EmojiPan &_st; + const std::shared_ptr _show; const not_null _session; const Fn _paused; diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 21a54c785d..cc40406122 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -917,6 +917,14 @@ rpl::producer Application::appDeactivatedValue() const { }); } +void Application::materializeLocalDrafts() { + _materializeLocalDraftsRequests.fire({}); +} + +rpl::producer<> Application::materializeLocalDraftsRequests() const { + return _materializeLocalDraftsRequests.events(); +} + void Application::switchDebugMode() { if (Logs::DebugEnabled()) { Logs::SetDebugEnabled(false); diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 3ad642c6bf..0a90308b96 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -314,6 +314,9 @@ public: void handleAppDeactivated(); [[nodiscard]] rpl::producer appDeactivatedValue() const; + void materializeLocalDrafts(); + [[nodiscard]] rpl::producer<> materializeLocalDraftsRequests() const; + void switchDebugMode(); void writeInstallBetaVersionsSetting(); @@ -444,6 +447,8 @@ private: rpl::event_stream _openInMediaViewRequests; + rpl::event_stream<> _materializeLocalDraftsRequests; + rpl::lifetime _lifetime; crl::time _lastNonIdleTime = 0; diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 39ba3369ec..02472e4371 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -146,7 +146,7 @@ void HiddenUrlClickHandler::Open(QString url, QVariant context) { if (my.show) { my.show->showBox(std::move(box)); } else if (use) { - use->show(std::move(box), Ui::LayerOption::KeepOther); + use->show(std::move(box)); } } else { open(); @@ -335,16 +335,13 @@ void MonospaceClickHandler::onClick(ClickContext context) const { const auto hasCopyRestriction = item && (!item->history()->peer->allowsForwarding() || item->forbidsForward()); - const auto toastParent = Window::Show(controller).toastParent(); if (hasCopyRestriction) { - Ui::Toast::Show( - toastParent, - item->history()->peer->isBroadcast() - ? tr::lng_error_nocopy_channel(tr::now) - : tr::lng_error_nocopy_group(tr::now)); + controller->showToast(item->history()->peer->isBroadcast() + ? tr::lng_error_nocopy_channel(tr::now) + : tr::lng_error_nocopy_group(tr::now)); return; } - Ui::Toast::Show(toastParent, tr::lng_text_copied(tr::now)); + controller->showToast(tr::lng_text_copied(tr::now)); } TextUtilities::SetClipboardText(TextForMimeData::Simple(_text.trimmed())); } diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 5ef839888e..60f65f2304 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -100,7 +100,7 @@ bool ShowStickerSet( } Core::App().hideMediaView(); controller->show(Box( - controller, + controller->uiShow(), StickerSetIdentifier{ .shortName = match->captured(2) }, (match->captured(1) == "addemoji" ? Data::StickersType::Emoji @@ -607,9 +607,7 @@ bool ShowInviteLink( return false; } QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show( - Window::Show(controller).toastParent(), - tr::lng_group_invite_copied(tr::now)); + controller->showToast(tr::lng_group_invite_copied(tr::now)); return true; } @@ -626,12 +624,12 @@ void ExportTestChatTheme( not_null controller, not_null theme) { const auto session = &controller->session(); - const auto show = std::make_shared(controller); + const auto show = controller->uiShow(); const auto inputSettings = [&](Data::CloudThemeType type) -> std::optional { const auto i = theme->settings.find(type); if (i == end(theme->settings)) { - Ui::Toast::Show(show->toastParent(), "Something went wrong :("); + show->showToast(u"Something went wrong :("_q); return std::nullopt; } const auto &fields = i->second; @@ -639,17 +637,15 @@ void ExportTestChatTheme( || !fields.paper->isPattern() || fields.paper->backgroundColors().empty() || !fields.paper->hasShareUrl()) { - Ui::Toast::Show(show->toastParent(), "Something went wrong :("); + show->showToast(u"Something went wrong :("_q); return std::nullopt; } const auto &bg = fields.paper->backgroundColors(); - const auto url = fields.paper->shareUrl(session); + const auto url = fields.paper->shareUrl(&show->session()); const auto from = url.indexOf("bg/"); const auto till = url.indexOf("?"); if (from < 0 || till <= from) { - Ui::Toast::Show( - show->toastParent(), - "Bad WallPaper link: " + url); + show->showToast(u"Bad WallPaper link: "_q + url); return std::nullopt; } @@ -731,15 +727,9 @@ void ExportTestChatTheme( const auto slug = Data::CloudTheme::Parse(session, result, true).slug; QGuiApplication::clipboard()->setText( session->createInternalLinkFull("addtheme/" + slug)); - if (show->valid()) { - Ui::Toast::Show( - show->toastParent(), - tr::lng_background_link_copied(tr::now)); - } + show->showToast(tr::lng_background_link_copied(tr::now)); }).fail([=](const MTP::Error &error) { - if (show->valid()) { - Ui::Toast::Show(show->toastParent(), "Error: " + error.type()); - } + show->showToast(u"Error: "_q + error.type()); }).send(); } diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index d202d083c5..4e311e1f1e 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -62,7 +62,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" // ClickHandlerContext #include "lang/lang_keys.h" #include "storage/file_upload.h" -#include "window/window_session_controller.h" // Window::Show +#include "window/window_session_controller.h" // SessionController::uiShow. #include "apiwrap.h" #include "styles/style_chat.h" #include "styles/style_dialogs.h" @@ -1828,7 +1828,7 @@ ClickHandlerPtr MediaDice::MakeHandler( auto config = Ui::Toast::Config{ .text = { tr::lng_about_random(tr::now, lt_emoji, emoji) }, .st = &st::historyDiceToast, - .durationMs = Ui::Toast::kDefaultDuration * 2, + .duration = Ui::Toast::kDefaultDuration * 2, .multiline = true, }; if (CanSend(history->peer, ChatRestriction::SendOther)) { @@ -1857,9 +1857,7 @@ ClickHandlerPtr MediaDice::MakeHandler( const auto my = context.other.value(); const auto weak = my.sessionWindow; if (const auto strong = weak.get()) { - ShownToast = Ui::Toast::Show( - Window::Show(strong).toastParent(), - config); + ShownToast = strong->showToast(std::move(config)); } else { ShownToast = Ui::Toast::Show(config); } diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 42c5484383..c096853c63 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -39,7 +39,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image.h" #include "ui/empty_userpic.h" #include "ui/text/text_options.h" -#include "ui/toasts/common_toasts.h" #include "ui/painter.h" #include "ui/ui_utility.h" #include "history/history.h" diff --git a/Telegram/SourceFiles/data/stickers/data_stickers.cpp b/Telegram/SourceFiles/data/stickers/data_stickers.cpp index 4b778d0b1c..c18a1c3bf3 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/stickers/data_stickers.h" #include "api/api_hash.h" +#include "chat_helpers/compose/compose_show.h" #include "data/data_document.h" #include "data/data_session.h" #include "data/data_user.h" @@ -29,7 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_app_config.h" #include "mtproto/mtproto_config.h" #include "ui/toast/toast.h" -#include "ui/toasts/common_toasts.h" #include "ui/image/image_location_factory.h" #include "window/window_controller.h" #include "window/window_session_controller.h" @@ -78,24 +78,24 @@ using SetFlag = StickersSetFlag; } void MaybeShowPremiumToast( - Window::SessionController *controller, + std::shared_ptr show, TextWithEntities text, const QString &ref) { - if (!controller) { + if (!show) { return; } - const auto session = &controller->session(); + const auto session = &show->session(); if (session->user()->isPremium()) { return; } - const auto widget = QPointer( - controller->window().widget()->bodyWidget()); const auto filter = [=](const auto ...) { - Settings::ShowPremium(controller, ref); + const auto usage = ChatHelpers::WindowUsage::PremiumPromo; + if (const auto controller = show->resolveWindow(usage)) { + Settings::ShowPremium(controller, ref); + } return false; }; - Ui::ShowMultilineToast({ - .parentOverride = widget, + show->showToast({ .text = std::move(text), .duration = kPremiumToastDuration, .filter = filter, @@ -313,7 +313,7 @@ void Stickers::incrementSticker(not_null document) { } void Stickers::addSavedGif( - Window::SessionController *controller, + std::shared_ptr show, not_null document) { const auto index = _savedGifs.indexOf(document); if (!index) { @@ -328,7 +328,7 @@ void Stickers::addSavedGif( if (_savedGifs.size() > limits.gifsCurrent()) { _savedGifs.pop_back(); MaybeShowPremiumToast( - controller, + show, SavedGifsToast(limits), LimitsPremiumRef("saved_gifs")); } @@ -518,7 +518,7 @@ bool Stickers::isFaved(not_null document) { void Stickers::checkFavedLimit( StickersSet &set, - Window::SessionController *controller) { + std::shared_ptr show) { const auto session = &_owner->session(); const auto limits = Data::PremiumLimits(session); if (set.stickers.size() <= limits.stickersFavedCurrent()) { @@ -538,21 +538,21 @@ void Stickers::checkFavedLimit( ++i; } MaybeShowPremiumToast( - controller, + std::move(show), FaveStickersToast(limits), LimitsPremiumRef("stickers_faved")); } void Stickers::pushFavedToFront( StickersSet &set, - Window::SessionController *controller, + std::shared_ptr show, not_null document, const std::vector> &emojiList) { set.stickers.push_front(document); for (auto emoji : emojiList) { set.emoji[emoji].push_front(document); } - checkFavedLimit(set, controller); + checkFavedLimit(set, std::move(show)); } void Stickers::moveFavedToFront(StickersSet &set, int index) { @@ -575,7 +575,7 @@ void Stickers::moveFavedToFront(StickersSet &set, int index) { } void Stickers::setIsFaved( - Window::SessionController *controller, + std::shared_ptr show, not_null document, std::optional>> emojiList) { auto &sets = setsRef(); @@ -600,11 +600,11 @@ void Stickers::setIsFaved( if (index > 0) { moveFavedToFront(*set, index); } else if (emojiList) { - pushFavedToFront(*set, controller, document, *emojiList); + pushFavedToFront(*set, show, document, *emojiList); } else if (auto list = getEmojiListFromSet(document)) { - pushFavedToFront(*set, controller, document, *list); + pushFavedToFront(*set, show, document, *list); } else { - requestSetToPushFaved(controller, document); + requestSetToPushFaved(show, document); return; } session().local().writeFavedStickers(); @@ -613,10 +613,8 @@ void Stickers::setIsFaved( } void Stickers::requestSetToPushFaved( - Window::SessionController *controller, + std::shared_ptr show, not_null document) { - controller = nullptr; - const auto weak = base::make_weak(controller); auto addAnyway = [=](std::vector> list) { if (list.empty()) { if (auto sticker = document->sticker()) { @@ -625,7 +623,7 @@ void Stickers::requestSetToPushFaved( } } } - setIsFaved(weak.get(), document, std::move(list)); + setIsFaved(nullptr, document, std::move(list)); }; session().api().request(MTPmessages_GetStickerSet( Data::InputStickerSet(document->sticker()->set), @@ -668,11 +666,11 @@ void Stickers::setIsNotFaved(not_null document) { } void Stickers::setFaved( - Window::SessionController *controller, + std::shared_ptr show, not_null document, bool faved) { if (faved) { - setIsFaved(controller, document); + setIsFaved(std::move(show), document); } else { setIsNotFaved(document); } diff --git a/Telegram/SourceFiles/data/stickers/data_stickers.h b/Telegram/SourceFiles/data/stickers/data_stickers.h index da202f337e..f469f173c7 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers.h +++ b/Telegram/SourceFiles/data/stickers/data_stickers.h @@ -22,6 +22,10 @@ namespace Window { class SessionController; } // namespace Window +namespace ChatHelpers { +class Show; +} // namespace ChatHelpers + namespace Data { class Session; @@ -200,7 +204,7 @@ public: void removeFromRecentSet(not_null document); void addSavedGif( - Window::SessionController *controller, + std::shared_ptr show, not_null document); void checkSavedGif(not_null item); @@ -210,7 +214,7 @@ public: void undoInstallLocally(uint64 setId); bool isFaved(not_null document); void setFaved( - Window::SessionController *controller, + std::shared_ptr show, not_null document, bool faved); @@ -260,21 +264,21 @@ private: } void checkFavedLimit( StickersSet &set, - Window::SessionController *controller = nullptr); + std::shared_ptr show); void setIsFaved( - Window::SessionController *controller, + std::shared_ptr show, not_null document, std::optional>> emojiList = std::nullopt); void setIsNotFaved(not_null document); void pushFavedToFront( StickersSet &set, - Window::SessionController *controller, + std::shared_ptr show, not_null document, const std::vector> &emojiList); void moveFavedToFront(StickersSet &set, int index); void requestSetToPushFaved( - Window::SessionController *controller, + std::shared_ptr show, not_null document); void setPackAndEmoji( StickersSet &set, diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index a33208ce61..dc8f3243e8 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -2286,7 +2286,7 @@ void Widget::showSearchFrom() { }), crl::guard(this, [=] { _filter->setFocus(); })); if (box) { - Window::Show(controller()).showBox(std::move(box)); + controller()->show(std::move(box)); } } } diff --git a/Telegram/SourceFiles/editor/controllers/stickers_panel_controller.cpp b/Telegram/SourceFiles/editor/controllers/stickers_panel_controller.cpp index 91748f82dc..66fc0f997a 100644 --- a/Telegram/SourceFiles/editor/controllers/stickers_panel_controller.cpp +++ b/Telegram/SourceFiles/editor/controllers/stickers_panel_controller.cpp @@ -24,7 +24,7 @@ StickersPanelController::StickersPanelController( controller, object_ptr( nullptr, - controller, + controller->uiShow(), Window::GifPauseReason::Layer, ChatHelpers::TabbedSelector::Mode::MediaEditor))) { _stickersPanel->setDesiredHeightValues( diff --git a/Telegram/SourceFiles/editor/photo_editor.cpp b/Telegram/SourceFiles/editor/photo_editor.cpp index ef91a1aa8c..a11fe97601 100644 --- a/Telegram/SourceFiles/editor/photo_editor.cpp +++ b/Telegram/SourceFiles/editor/photo_editor.cpp @@ -61,7 +61,7 @@ PhotoEditor::PhotoEditor( controller->sessionController()) : nullptr, std::make_unique(), - std::make_shared(controller))) + controller->uiShow())) , _content(base::make_unique_q( this, photo, diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index c2dd3e4ceb..ec8f4c593a 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -1362,7 +1362,7 @@ void InnerWidget::copySelectedText() { } void InnerWidget::showStickerPackInfo(not_null document) { - StickerSetBox::Show(_controller, document); + StickerSetBox::Show(_controller->uiShow(), document); } void InnerWidget::cancelContextDownload(not_null document) { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index b70d43d214..de4e92724f 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -1117,7 +1117,7 @@ void GenerateItems( if (const auto controller = my.sessionWindow.get()) { controller->show( Box( - controller, + controller->uiShow(), Data::FromInputSet(set), Data::StickersType::Stickers), Ui::LayerOption::CloseOther); diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index a3f2cc87d5..262af2becf 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -54,8 +54,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "support/support_helper.h" #include "ui/image/image.h" #include "ui/text/text_options.h" -#include "ui/toasts/common_toasts.h" #include "ui/text/text_utilities.h" +#include "ui/toast/toast.h" #include "payments/payments_checkout_process.h" #include "core/crash_reports.h" #include "core/application.h" @@ -1176,7 +1176,7 @@ void History::applyServiceChanges( } if (paid) { // Toast on a current active window. - Ui::ShowMultilineToast({ + Ui::Toast::Show({ .text = tr::lng_payments_success( tr::now, lt_amount, diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index c1e0d510a1..e719d9716f 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -33,7 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/menu/menu_multiline_action.h" #include "ui/widgets/popup_menu.h" #include "ui/image/image.h" -#include "ui/toasts/common_toasts.h" #include "ui/effects/path_shift_gradient.h" #include "ui/effects/message_sending_animation_controller.h" #include "ui/effects/reaction_fly_animation.h" @@ -139,7 +138,7 @@ void FillSponsoredMessagesMenu( not_null menu) { const auto &data = controller->session().data().sponsoredMessages(); const auto info = data.lookupDetails(itemId).info; - const auto toastParent = Window::Show(controller).toastParent(); + const auto show = controller->uiShow(); if (!info.empty()) { auto fillSubmenu = [&](not_null menu) { const auto allText = ranges::accumulate( @@ -150,10 +149,7 @@ void FillSponsoredMessagesMenu( }).text; const auto callback = [=] { QGuiApplication::clipboard()->setText(allText); - Ui::ShowMultilineToast({ - .parentOverride = toastParent, - .text = { tr::lng_text_copied(tr::now) }, - }); + show->showToast(tr::lng_text_copied(tr::now)); }; for (const auto &i : info) { auto item = base::make_unique_q( @@ -2478,7 +2474,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { }, &st::menuIconStickers); const auto isFaved = session->data().stickers().isFaved(document); _menu->addAction(isFaved ? tr::lng_faved_stickers_remove(tr::now) : tr::lng_faved_stickers_add(tr::now), [=] { - Api::ToggleFavedSticker(controller, document, itemId); + Api::ToggleFavedSticker(controller->uiShow(), document, itemId); }, isFaved ? &st::menuIconUnfave : &st::menuIconFave); } if (!hasCopyMediaRestriction(item)) { @@ -2681,12 +2677,9 @@ bool HistoryInner::showCopyRestriction(HistoryItem *item) { if (!hasCopyRestriction(item)) { return false; } - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(_controller).toastParent(), - .text = { _peer->isBroadcast() - ? tr::lng_error_nocopy_channel(tr::now) - : tr::lng_error_nocopy_group(tr::now) }, - }); + _controller->showToast(_peer->isBroadcast() + ? tr::lng_error_nocopy_channel(tr::now) + : tr::lng_error_nocopy_group(tr::now)); return true; } @@ -2694,12 +2687,9 @@ bool HistoryInner::showCopyMediaRestriction(not_null item) { if (!hasCopyMediaRestriction(item)) { return false; } - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(_controller).toastParent(), - .text = { _peer->isBroadcast() - ? tr::lng_error_nocopy_channel(tr::now) - : tr::lng_error_nocopy_group(tr::now) }, - }); + _controller->showToast(_peer->isBroadcast() + ? tr::lng_error_nocopy_channel(tr::now) + : tr::lng_error_nocopy_group(tr::now)); return true; } @@ -2762,7 +2752,7 @@ void HistoryInner::copyContextImage( } void HistoryInner::showStickerPackInfo(not_null document) { - StickerSetBox::Show(_controller, document); + StickerSetBox::Show(_controller->uiShow(), document); } void HistoryInner::cancelContextDownload(not_null document) { @@ -2801,7 +2791,7 @@ void HistoryInner::saveContextGif(FullMsgId itemId) { if (const auto media = item->media()) { if (const auto document = media->document()) { Api::ToggleSavedGif( - _controller, + _controller->uiShow(), document, item->fullId(), true); diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index a63048d06b..8cdf3d2c4e 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -4836,7 +4836,7 @@ void HistoryItem::setupTTLChange() { const auto my = context.other.value(); if (const auto controller = my.sessionWindow.get()) { const auto validator = TTLMenu::TTLValidator( - std::make_shared(controller), + controller->uiShow(), peer); if (validator.can()) { validator.showBox(); diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 8b65739351..0cecbe2fe4 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -135,9 +135,7 @@ ClickHandlerPtr HiddenSenderInfo::ForwardClickHandler() { const auto my = context.other.value(); const auto weak = my.sessionWindow; if (const auto strong = weak.get()) { - Ui::Toast::Show( - Window::Show(strong).toastParent(), - tr::lng_forwarded_hidden(tr::now)); + strong->showToast(tr::lng_forwarded_hidden(tr::now)); } }); return hidden; diff --git a/Telegram/SourceFiles/history/history_view_top_toast.cpp b/Telegram/SourceFiles/history/history_view_top_toast.cpp index 2315e20c61..155f139966 100644 --- a/Telegram/SourceFiles/history/history_view_top_toast.cpp +++ b/Telegram/SourceFiles/history/history_view_top_toast.cpp @@ -41,7 +41,7 @@ void InfoTooltip::show( _topToast = Ui::Toast::Show(parent, Ui::Toast::Config{ .text = text, .st = &st::historyInfoToast, - .durationMs = CountToastDuration(text), + .duration = CountToastDuration(text), .multiline = true, .dark = true, .slideSide = RectPart::Top, diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index cd07b07671..03eff7f273 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -225,7 +225,7 @@ HistoryWidget::HistoryWidget( _scroll.data(), controller->chatStyle(), static_cast(this)) -, _fieldAutocomplete(this, controller) +, _fieldAutocomplete(this, controller->uiShow()) , _supportAutocomplete(session().supportMode() ? object_ptr(this, &session()) : nullptr) @@ -248,7 +248,7 @@ HistoryWidget::HistoryWidget( , _botCommandStart(this, st::historyBotCommandStart) , _voiceRecordBar(std::make_unique( this, - controller, + controller->uiShow(), _send, st::historySendSize.height())) , _forwardPanel(std::make_unique([=] { updateField(); })) @@ -746,7 +746,7 @@ HistoryWidget::HistoryWidget( const auto account = &_peer->account(); closeCurrent(); if (const auto primary = Core::App().windowFor(account)) { - controller->showToast({ unavailable }); + controller->showToast(unavailable); } return; } @@ -879,7 +879,7 @@ HistoryWidget::HistoryWidget( }, lifetime()); } - controller->materializeLocalDraftsRequests( + Core::App().materializeLocalDraftsRequests( ) | rpl::start_with_next([=] { saveFieldToHistoryLocalDraft(); }, lifetime()); @@ -967,7 +967,7 @@ void HistoryWidget::initVoiceRecordBar() { return std::nullopt; }(); if (error) { - controller()->showToast({ *error }); + controller()->showToast(*error); return true; } else if (showSlowmodeError()) { return true; @@ -1028,7 +1028,12 @@ void HistoryWidget::initVoiceRecordBar() { _voiceRecordBar->recordingTipRequests( ) | rpl::start_with_next([=] { - controller()->showToast({ tr::lng_record_hold_tip(tr::now) }); + controller()->showToast(tr::lng_record_hold_tip(tr::now)); + }, lifetime()); + + _voiceRecordBar->recordingStateChanges( + ) | rpl::start_with_next([=](bool active) { + controller()->widget()->setInnerFocus(); }, lifetime()); _voiceRecordBar->hideFast(); @@ -1581,7 +1586,7 @@ void HistoryWidget::toggleChooseChatTheme( } else if (!show.value_or(true)) { return; } else if (_voiceRecordBar->isActive()) { - controller()->showToast({ tr::lng_chat_theme_cant_voice(tr::now) }); + controller()->showToast(tr::lng_chat_theme_cant_voice(tr::now)); return; } _chooseTheme = std::make_unique( @@ -3096,9 +3101,9 @@ void HistoryWidget::messagesFailed(const MTP::Error &error, int requestId) { auto was = _peer; closeCurrent(); if (const auto primary = Core::App().windowFor(&was->account())) { - controller()->showToast({ (was && was->isMegagroup()) + controller()->showToast((was && was->isMegagroup()) ? tr::lng_group_not_accessible(tr::now) - : tr::lng_channel_not_accessible(tr::now) }); + : tr::lng_channel_not_accessible(tr::now)); } return; } @@ -3740,9 +3745,8 @@ void HistoryWidget::saveEditMsg() { return; } else if (!left.text.isEmpty()) { const auto remove = left.text.size(); - controller()->showToast({ - tr::lng_edit_limit_reached(tr::now, lt_count, remove) - }); + controller()->showToast( + tr::lng_edit_limit_reached(tr::now, lt_count, remove)); return; } @@ -3775,14 +3779,14 @@ void HistoryWidget::saveEditMsg() { _saveEditMsgRequestId = 0; } if (ranges::contains(Api::kDefaultEditMessagesErrors, error)) { - controller()->showToast({ tr::lng_edit_error(tr::now) }); + controller()->showToast(tr::lng_edit_error(tr::now)); } else if (error == u"MESSAGE_NOT_MODIFIED"_q) { cancelEdit(); } else if (error == u"MESSAGE_EMPTY"_q) { _field->selectAll(); setInnerFocus(); } else { - controller()->showToast({ tr::lng_edit_error(tr::now) }); + controller()->showToast(tr::lng_edit_error(tr::now)); } update(); })(); @@ -3935,8 +3939,7 @@ void HistoryWidget::sendScheduled() { } const auto callback = [=](Api::SendOptions options) { send(options); }; controller()->show( - HistoryView::PrepareScheduleBox(_list, sendMenuType(), callback), - Ui::LayerOption::KeepOther); + HistoryView::PrepareScheduleBox(_list, sendMenuType(), callback)); } void HistoryWidget::sendWhenOnline() { @@ -4024,8 +4027,8 @@ void HistoryWidget::reportSelectedMessages() { clearSelected(); controller()->clearChooseReportMessages(); } - const auto toastParent = Window::Show(controller()).toastParent(); - Api::SendReport(toastParent, peer, reason, text, ids); + const auto show = controller()->uiShow(); + Api::SendReport(show, peer, reason, text, ids); box->closeBox(); }); })); @@ -4223,14 +4226,14 @@ void HistoryWidget::finishAnimating() { void HistoryWidget::chooseAttach( std::optional overrideSendImagesAsPhotos) { if (_editMsgId) { - controller()->showToast({ tr::lng_edit_caption_attach(tr::now) }); + controller()->showToast(tr::lng_edit_caption_attach(tr::now)); return; } if (!_peer || !_canSendMessages) { return; } else if (const auto error = Data::AnyFileRestrictionError(_peer)) { - controller()->showToast({ *error }); + controller()->showToast(*error); return; } else if (showSlowmodeError()) { return; @@ -5154,7 +5157,7 @@ bool HistoryWidget::showSendingFilesError( controller()->show(Box(FileSizeLimitBox, &session(), fileSize)); return true; } - controller()->showToast({ text }); + controller()->showToast(text); return true; } @@ -5178,7 +5181,7 @@ bool HistoryWidget::showSendMessageError( if (error.isEmpty()) { return false; } - controller()->showToast({ error }); + controller()->showToast(error); return true; } @@ -5212,7 +5215,7 @@ bool HistoryWidget::confirmSendingFiles( crl::guard(_list, [=] { cancelEdit(); })); return true; } - controller()->showToast({ tr::lng_edit_caption_attach(tr::now) }); + controller()->showToast(tr::lng_edit_caption_attach(tr::now)); return false; } else if (showSendingFilesError(list)) { return false; @@ -5582,7 +5585,7 @@ int HistoryWidget::countInitialScrollTop() { const auto itemTop = _list->itemTop(item); if (itemTop < 0) { setMsgId(0); - controller()->showToast({ tr::lng_message_not_found(tr::now) }); + controller()->showToast(tr::lng_message_not_found(tr::now)); return countInitialScrollTop(); } else { const auto view = item->mainView(); @@ -6136,7 +6139,7 @@ void HistoryWidget::mousePressEvent(QMouseEvent *e) { crl::guard(_list, [=] { cancelEdit(); })); } else if (_inReplyEditForward) { if (readyToForward()) { - _forwardPanel->editOptions(controller()); + _forwardPanel->editOptions(controller()->uiShow()); } else { controller()->showPeerHistory( _peer, @@ -6293,7 +6296,7 @@ bool HistoryWidget::showSlowmodeError() { if (text.isEmpty()) { return false; } - controller()->showToast({ text }); + controller()->showToast(text); return true; } @@ -6314,7 +6317,7 @@ void HistoryWidget::sendInlineResult(InlineBots::ResultSelected result) { auto errorText = result.result->getErrorOnSend(_history); if (!errorText.isEmpty()) { - controller()->showToast({ errorText }); + controller()->showToast(errorText); return; } @@ -6600,7 +6603,7 @@ void HistoryWidget::checkMessagesTTL() { } else if (!_ttlInfo || _ttlInfo->peer() != _peer) { _ttlInfo = std::make_unique( this, - std::make_shared(controller()), + controller()->uiShow(), _peer); orderWidgets(); updateControlsGeometry(); @@ -6821,7 +6824,7 @@ bool HistoryWidget::sendExistingDocument( ? Data::RestrictionError(_peer, ChatRestriction::SendStickers) : std::nullopt; if (error) { - controller()->showToast({ *error }); + controller()->showToast(*error); return false; } else if (!_peer || !_canSendMessages @@ -6856,7 +6859,7 @@ bool HistoryWidget::sendExistingPhoto( ? Data::RestrictionError(_peer, ChatRestriction::SendPhotos) : std::nullopt; if (error) { - controller()->showToast({ *error }); + controller()->showToast(*error); return false; } else if (!_peer || !_canSendMessages) { return false; @@ -6972,7 +6975,7 @@ void HistoryWidget::processReply() { return; } else if (_processingReplyItem->history() == _migrated) { if (_processingReplyItem->isService()) { - controller()->showToast({ tr::lng_reply_cant(tr::now) }); + controller()->showToast(tr::lng_reply_cant(tr::now)); } else { const auto itemId = _processingReplyItem->fullId(); controller()->show( @@ -7060,7 +7063,7 @@ void HistoryWidget::editMessage(not_null item) { if (_chooseTheme) { toggleChooseChatTheme(_peer); } else if (_voiceRecordBar->isActive()) { - controller()->showToast({ tr::lng_edit_caption_voice(tr::now) }); + controller()->showToast(tr::lng_edit_caption_voice(tr::now)); return; } else if (_composeSearch) { _composeSearch->hideAnimated(); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 1da5208247..4146e8eb88 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qt_signal_producer.h" #include "base/unixtime.h" #include "boxes/edit_caption_box.h" +#include "chat_helpers/compose/compose_show.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/message_field.h" #include "menu/menu_send.h" @@ -340,7 +341,7 @@ class FieldHeader final : public Ui::RpWidget { public: FieldHeader( QWidget *parent, - not_null controller); + std::shared_ptr show); void setHistory(const SetHistoryArgs &args); void init(); @@ -402,7 +403,7 @@ private: bool cancelled = false; }; - const not_null _controller; + const std::shared_ptr _show; History *_history = nullptr; rpl::variable _title; rpl::variable _description; @@ -436,12 +437,12 @@ private: FieldHeader::FieldHeader( QWidget *parent, - not_null controller) + std::shared_ptr show) : RpWidget(parent) -, _controller(controller) +, _show(std::move(show)) , _forwardPanel( std::make_unique([=] { customEmojiRepaint(); })) -, _data(&controller->session().data()) +, _data(&_show->session().data()) , _cancel(Ui::CreateChild(this, st::historyReplyCancel)) { resize(QSize(parent->width(), st::historyReplyHeight)); init(); @@ -466,8 +467,7 @@ void FieldHeader::init() { paintRequest( ) | rpl::start_with_next([=] { Painter p(this); - p.setInactive( - _controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any)); + p.setInactive(_show->paused(Window::GifPauseReason::Any)); p.fillRect(rect(), st::historyComposeAreaBg); const auto position = st::historyReplyIconPosition; @@ -581,7 +581,7 @@ void FieldHeader::init() { update(); } else if (isLeftButton && inPreviewRect) { if (!isEditingMessage() && readyToForward()) { - _forwardPanel->editOptions(_controller); + _forwardPanel->editOptions(_show); } else { auto id = isEditingMessage() ? _editMsgId.current() @@ -915,13 +915,37 @@ MessageToEdit FieldHeader::queryToEdit() { ComposeControls::ComposeControls( not_null parent, - not_null window, + not_null controller, Fn)> unavailableEmojiPasted, Mode mode, SendMenu::Type sendMenuType) +: ComposeControls(parent, ComposeControlsDescriptor{ + .show = controller->uiShow(), + .unavailableEmojiPasted = std::move(unavailableEmojiPasted), + .mode = mode, + .sendMenuType = sendMenuType, + .regularWindow = controller, + .stickerOrEmojiChosen = controller->stickerOrEmojiChosen(), +}) { +} + +ComposeControls::ComposeControls( + not_null parent, + ComposeControlsDescriptor descriptor) : _parent(parent) -, _window(window) -, _mode(mode) +, _show(std::move(descriptor.show)) +, _session(&_show->session()) +, _regularWindow(descriptor.regularWindow) +, _ownedSelector(_regularWindow + ? nullptr + : std::make_unique( + _parent, + _show, + Window::GifPauseReason::TabbedPanel)) +, _selector(_regularWindow + ? _regularWindow->tabbedSelector() + : not_null(_ownedSelector.get())) +, _mode(descriptor.mode) , _wrap(std::make_unique(parent)) , _writeRestricted(std::make_unique(parent)) , _send(std::make_shared(_wrap.get())) @@ -940,20 +964,23 @@ ComposeControls::ComposeControls( , _botCommandStart(Ui::CreateChild( _wrap.get(), st::historyBotCommandStart)) -, _autocomplete(std::make_unique( - parent, - window)) -, _header(std::make_unique(_wrap.get(), _window)) +, _autocomplete(std::make_unique(parent, _show)) +, _header(std::make_unique(_wrap.get(), _show)) , _voiceRecordBar(std::make_unique( _wrap.get(), parent, - window, + _show, _send, st::historySendSize.height())) -, _sendMenuType(sendMenuType) -, _unavailableEmojiPasted(unavailableEmojiPasted) +, _sendMenuType(descriptor.sendMenuType) +, _unavailableEmojiPasted(std::move(descriptor.unavailableEmojiPasted)) , _saveDraftTimer([=] { saveDraft(); }) , _saveCloudDraftTimer([=] { saveCloudDraft(); }) { + if (descriptor.stickerOrEmojiChosen) { + std::move( + descriptor.stickerOrEmojiChosen + ) | rpl::start_to_stream(_stickerOrEmojiChosen, _wrap->lifetime()); + } init(); } @@ -965,7 +992,7 @@ ComposeControls::~ComposeControls() { } Main::Session &ComposeControls::session() const { - return _window->session(); + return _show->session(); } void ComposeControls::setHistory(SetHistoryArgs &&args) { @@ -989,8 +1016,7 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) { _history = history; _header->setHistory(args); registerDraftSource(); - _window->tabbedSelector()->setCurrentPeer( - history ? history->peer.get() : nullptr); + _selector->setCurrentPeer(history ? history->peer.get() : nullptr); initWebpageProcess(); initForwardProcess(); updateBotCommandShown(); @@ -1095,6 +1121,10 @@ auto ComposeControls::replyNextRequests() const return _replyNextRequests.events(); } +rpl::producer<> ComposeControls::focusRequests() const { + return _focusRequests.events(); +} + auto ComposeControls::sendContentRequests(SendRequestType requestType) const { auto filter = rpl::filter([=] { const auto type = (_mode == Mode::Normal) @@ -1146,7 +1176,8 @@ rpl::producer> ComposeControls::attachRequests() const { _attachRequests.events() ) | rpl::filter([=] { if (isEditingMessage()) { - _window->show(Ui::MakeInformBox(tr::lng_edit_caption_attach())); + _show->showBox( + Ui::MakeInformBox(tr::lng_edit_caption_attach())); return false; } return true; @@ -1158,17 +1189,17 @@ void ComposeControls::setMimeDataHook(MimeDataHook hook) { } bool ComposeControls::confirmMediaEdit(Ui::PreparedList &list) { - if (!isEditingMessage()) { + if (!isEditingMessage() || !_regularWindow) { return false; } else if (_canReplaceMedia) { EditCaptionBox::StartMediaReplace( - _window, + _regularWindow, _editingId, std::move(list), _field->getTextWithTags(), crl::guard(_wrap.get(), [=] { cancelEditMessage(); })); } else { - _window->showToast({ tr::lng_edit_caption_attach(tr::now) }); + _show->showToast(tr::lng_edit_caption_attach(tr::now)); } return true; } @@ -1459,7 +1490,7 @@ void ComposeControls::init() { cancelEditMessage(); }, _wrap->lifetime()); - _window->materializeLocalDraftsRequests( + Core::App().materializeLocalDraftsRequests( ) | rpl::start_with_next([=] { saveFieldToHistoryLocalDraft(); }, _wrap->lifetime()); @@ -1573,7 +1604,7 @@ void ComposeControls::initField() { Ui::Connect(_field, &Ui::InputField::resized, [=] { updateHeight(); }); //Ui::Connect(_field, &Ui::InputField::focused, [=] { fieldFocused(); }); Ui::Connect(_field, &Ui::InputField::changed, [=] { fieldChanged(); }); - InitMessageField(_window, _field, [=](not_null emoji) { + InitMessageField(_show, _field, [=](not_null emoji) { if (_history && Data::AllowEmojiWithoutPremium(_history->peer)) { return true; } @@ -1589,7 +1620,7 @@ void ComposeControls::initField() { const auto suggestions = Ui::Emoji::SuggestionsController::Init( _parent, _field, - &_window->session(), + _session, { .suggestCustomEmoji = true, .allowCustomWithoutPremium = allow }); _raiseEmojiSuggestions = [=] { suggestions->raise(); }; @@ -1678,7 +1709,7 @@ void ComposeControls::initAutocomplete() { _field->rawTextEdit()->installEventFilter(_autocomplete.get()); - _window->session().data().botCommandsChanges( + _session->data().botCommandsChanges( ) | rpl::filter([=](not_null peer) { return _history && (_history->peer == peer); }) | rpl::start_with_next([=] { @@ -1687,7 +1718,7 @@ void ComposeControls::initAutocomplete() { } }, _autocomplete->lifetime()); - _window->session().data().stickers().updated( + _session->data().stickers().updated( Data::StickersType::Stickers ) | rpl::start_with_next([=] { updateStickersByEmoji(); @@ -1989,7 +2020,7 @@ rpl::producer ComposeControls::sendActionUpdates() const { } void ComposeControls::initTabbedSelector() { - if (_window->hasTabbedSelectorOwnership()) { + if (!_regularWindow || _regularWindow->hasTabbedSelectorOwnership()) { createTabbedPanel(); } else { setTabbedPanel(nullptr); @@ -2003,25 +2034,24 @@ void ComposeControls::initTabbedSelector() { } }); - const auto selector = _window->tabbedSelector(); const auto wrap = _wrap.get(); - base::install_event_filter(wrap, selector, [=](not_null e) { + base::install_event_filter(wrap, _selector, [=](not_null e) { if (_tabbedPanel && e->type() == QEvent::ParentChange) { setTabbedPanel(nullptr); } return base::EventFilterResult::Continue; }); - selector->emojiChosen( + _selector->emojiChosen( ) | rpl::start_with_next([=](ChatHelpers::EmojiChosen data) { Ui::InsertEmojiAtCursor(_field->textCursor(), data.emoji); }, wrap->lifetime()); rpl::merge( - selector->fileChosen(), - selector->customEmojiChosen(), - _window->stickerOrEmojiChosen() + _selector->fileChosen(), + _selector->customEmojiChosen(), + _stickerOrEmojiChosen.events() ) | rpl::start_with_next([=](ChatHelpers::FileChosen &&data) { if (const auto info = data.document->sticker() ; info && info->setType == Data::StickersType::Emoji) { @@ -2040,18 +2070,18 @@ void ComposeControls::initTabbedSelector() { } }, wrap->lifetime()); - selector->photoChosen( + _selector->photoChosen( ) | rpl::start_to_stream(_photoChosen, wrap->lifetime()); - selector->inlineResultChosen( + _selector->inlineResultChosen( ) | rpl::start_to_stream(_inlineResultChosen, wrap->lifetime()); - selector->contextMenuRequested( + _selector->contextMenuRequested( ) | rpl::start_with_next([=] { - selector->showMenuWithType(sendMenuType()); + _selector->showMenuWithType(sendMenuType()); }, wrap->lifetime()); - selector->choosingStickerUpdated( + _selector->choosingStickerUpdated( ) | rpl::start_with_next([=](ChatHelpers::TabbedSelector::Action action) { _sendActionUpdates.fire({ .type = Api::SendProgressType::ChooseSticker, @@ -2166,10 +2196,23 @@ void ComposeControls::initWriteRestriction() { }, _wrap->lifetime()); } +void ComposeControls::changeFocusedControl() { + _focusRequests.fire({}); + if (_regularWindow) { + _regularWindow->widget()->setInnerFocus(); + } +} + void ComposeControls::initVoiceRecordBar() { _voiceRecordBar->recordingStateChanges( ) | rpl::start_with_next([=](bool active) { + if (active) { + changeFocusedControl(); + } _field->setVisible(!active); + if (!active) { + changeFocusedControl(); + } }, _wrap->lifetime()); _voiceRecordBar->setStartRecordingFilter([=] { @@ -2185,7 +2228,7 @@ void ComposeControls::initVoiceRecordBar() { return std::nullopt; }(); if (error) { - _window->show(Ui::MakeInformBox(*error)); + _show->showBox(Ui::MakeInformBox(*error)); return true; } else if (_showSlowmodeError && _showSlowmodeError()) { return true; @@ -2396,7 +2439,7 @@ void ComposeControls::updateMessagesTTLShown() { } else if (shown && !_ttlInfo) { _ttlInfo = std::make_unique( _wrap.get(), - std::make_shared(_window), + _show, peer); orderControls(); updateControlsVisibility(); @@ -2408,7 +2451,9 @@ bool ComposeControls::updateSendAsButton() { Expects(_history != nullptr); const auto peer = _history->peer; - if (isEditingMessage() || !session().sendAsPeers().shouldChoose(peer)) { + if (!_regularWindow + || isEditingMessage() + || !session().sendAsPeers().shouldChoose(peer)) { if (!_sendAs) { return false; } @@ -2423,18 +2468,18 @@ bool ComposeControls::updateSendAsButton() { Ui::SetupSendAsButton( _sendAs.get(), rpl::single(peer.get()), - _window); + _regularWindow); return true; } void ComposeControls::updateAttachBotsMenu() { _attachBotsMenu = nullptr; - if (!_history || !_sendActionFactory) { + if (!_history || !_sendActionFactory || !_regularWindow) { return; } _attachBotsMenu = InlineBots::MakeAttachBotsMenu( _parent, - _window, + _regularWindow, _history->peer, _sendActionFactory, [=](bool compress) { _attachRequests.fire_copy(compress); }); @@ -2467,7 +2512,7 @@ void ComposeControls::escape() { bool ComposeControls::pushTabbedSelectorToThirdSection( not_null thread, const Window::SectionShow ¶ms) { - if (!_tabbedPanel) { + if (!_tabbedPanel || !_regularWindow) { return true; //} else if (!_canSendMessages) { // Core::App().settings().setTabbedReplacedWithInfo(true); @@ -2479,8 +2524,8 @@ bool ComposeControls::pushTabbedSelectorToThirdSection( &st::historyAttachEmojiActive, &st::historyRecordVoiceFgActive, &st::historyRecordVoiceRippleBgActive); - _window->resizeForThirdSection(); - _window->showSection( + _regularWindow->resizeForThirdSection(); + _regularWindow->showSection( std::make_shared(), params.withThirdColumn()); return true; @@ -2493,10 +2538,13 @@ bool ComposeControls::returnTabbedSelector() { } void ComposeControls::createTabbedPanel() { + auto descriptor = ChatHelpers::TabbedPanelDescriptor{ + .regularWindow = _regularWindow, + .nonOwnedSelector = _selector, + }; setTabbedPanel(std::make_unique( _parent, - _window, - _window->tabbedSelector())); + std::move(descriptor))); } void ComposeControls::setTabbedPanel( @@ -2514,12 +2562,12 @@ void ComposeControls::setTabbedPanel( } void ComposeControls::toggleTabbedSelectorMode() { - if (!_history) { + if (!_history || !_regularWindow) { return; } if (_tabbedPanel) { - if (_window->canShowThirdSection() - && !_window->adaptive().isOneColumn()) { + if (_regularWindow->canShowThirdSection() + && !_regularWindow->adaptive().isOneColumn()) { Core::App().settings().setTabbedSelectorSectionEnabled(true); Core::App().saveSettingsDelayed(); const auto topic = _history->peer->forumTopicFor( @@ -2531,7 +2579,7 @@ void ComposeControls::toggleTabbedSelectorMode() { _tabbedPanel->toggleAnimated(); } } else { - _window->closeThirdSection(); + _regularWindow->closeThirdSection(); } } @@ -2555,7 +2603,7 @@ void ComposeControls::editMessage(not_null item) { Expects(draftKeyCurrent() != Data::DraftKey::None()); if (_voiceRecordBar->isActive()) { - _window->show(Ui::MakeInformBox(tr::lng_edit_caption_voice())); + _show->showBox(Ui::MakeInformBox(tr::lng_edit_caption_voice())); return; } @@ -2609,7 +2657,7 @@ void ComposeControls::editMessage(not_null item) { } bool ComposeControls::updateReplaceMediaButton() { - if (!_canReplaceMedia) { + if (!_canReplaceMedia || !_regularWindow) { const auto result = (_replaceMedia != nullptr); _replaceMedia = nullptr; return result; @@ -2621,7 +2669,7 @@ bool ComposeControls::updateReplaceMediaButton() { st::historyReplaceMedia); _replaceMedia->setClickedCallback([=] { EditCaptionBox::StartMediaReplace( - _window, + _regularWindow, _editingId, _field->getTextWithTags(), crl::guard(_wrap.get(), [=] { cancelEditMessage(); })); @@ -2852,7 +2900,7 @@ bool ComposeControls::hasSilentBroadcastToggle() const { } void ComposeControls::updateInlineBotQuery() { - if (!_history) { + if (!_history || !_regularWindow) { return; } const auto query = ParseInlineBotQuery(&session(), _field); @@ -2916,6 +2964,8 @@ void ComposeControls::updateInlineBotQuery() { void ComposeControls::applyInlineBotQuery( UserData *bot, const QString &query) { + Expects(_regularWindow != nullptr); + if (_history && bot) { if (_inlineBot != bot) { _inlineBot = bot; @@ -2925,15 +2975,15 @@ void ComposeControls::applyInlineBotQuery( if (!_inlineResults) { _inlineResults = std::make_unique( _parent, - _window); + _regularWindow); _inlineResults->setResultSelectedCallback([=]( InlineBots::ResultSelected result) { if (result.open) { const auto request = result.result->openRequest(); if (const auto photo = request.photo()) { - _window->openPhoto(photo, {}, {}); + _regularWindow->openPhoto(photo, {}, {}); } else if (const auto document = request.document()) { - _window->openDocument(document, {}, {}); + _regularWindow->openDocument(document, {}, {}); } } else { _inlineResultChosen.fire_copy(result); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h index 20be24131a..c09b938d6c 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/input_fields.h" class History; +class DocumentData; class FieldAutocomplete; namespace SendMenu { @@ -29,6 +30,7 @@ class TabbedPanel; class TabbedSelector; struct FileChosen; struct PhotoChosen; +class Show; } // namespace ChatHelpers namespace Data { @@ -63,8 +65,8 @@ class Session; } // namespace Main namespace Window { -class SessionController; struct SectionShow; +class SessionController; } // namespace Window namespace Api { @@ -81,6 +83,20 @@ class TTLButton; class FieldHeader; class WebpageProcessor; +enum class ComposeControlsMode { + Normal, + Scheduled, +}; + +struct ComposeControlsDescriptor { + std::shared_ptr show; + Fn)> unavailableEmojiPasted; + ComposeControlsMode mode = ComposeControlsMode::Normal; + SendMenu::Type sendMenuType = {}; + Window::SessionController *regularWindow = nullptr; + rpl::producer stickerOrEmojiChosen; +}; + class ComposeControls final { public: using FileChosen = ChatHelpers::FileChosen; @@ -93,18 +109,17 @@ public: using SetHistoryArgs = Controls::SetHistoryArgs; using ReplyNextRequest = Controls::ReplyNextRequest; using FieldHistoryAction = Ui::InputField::HistoryAction; - - enum class Mode { - Normal, - Scheduled, - }; + using Mode = ComposeControlsMode; ComposeControls( not_null parent, - not_null window, + not_null controller, Fn)> unavailableEmojiPasted, Mode mode, SendMenu::Type sendMenuType); + ComposeControls( + not_null parent, + ComposeControlsDescriptor descriptor); ~ComposeControls(); [[nodiscard]] Main::Session &session() const; @@ -139,6 +154,7 @@ public: -> rpl::producer>; [[nodiscard]] auto replyNextRequests() const -> rpl::producer; + [[nodiscard]] rpl::producer<> focusRequests() const; using MimeDataHook = Fn data, @@ -292,9 +308,17 @@ private: void unregisterDraftSources(); void registerDraftSource(); + void changeFocusedControl(); const not_null _parent; - const not_null _window; + const std::shared_ptr _show; + const not_null _session; + + Window::SessionController * const _regularWindow = nullptr; + const std::unique_ptr _ownedSelector; + const not_null _selector; + rpl::event_stream _stickerOrEmojiChosen; + History *_history = nullptr; Fn _showSlowmodeError; Fn _sendActionFactory; @@ -340,6 +364,7 @@ private: rpl::event_stream> _editLastMessageRequests; rpl::event_stream> _attachRequests; rpl::event_stream _replyNextRequests; + rpl::event_stream<> _focusRequests; TextUpdateEvents _textUpdateEvents = TextUpdateEvents() | TextUpdateEvent::SaveDraft diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_search.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_search.cpp index b7024d55df..45ba94da29 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_search.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_search.cpp @@ -818,12 +818,12 @@ ComposeSearch::Inner::Inner( auto box = Dialogs::SearchFromBox( peer, crl::guard(_bottomBar.get(), [=](not_null from) { - Window::Show(_window).hideLayer(); + _window->hideLayer(); _topBar->setFrom(from); }), crl::guard(_bottomBar.get(), [=] { setInnerFocus(); })); - Window::Show(_window).showBox(std::move(box)); + _window->show(std::move(box)); }, _bottomBar->lifetime()); _bottomBar->showListRequests( diff --git a/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp b/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp index efb85e7bc4..30e3b26e03 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.cpp @@ -218,8 +218,7 @@ bool ForwardPanel::empty() const { return _data.items.empty(); } -void ForwardPanel::editOptions( - not_null controller) { +void ForwardPanel::editOptions(std::shared_ptr show) { using Options = Data::ForwardOptions; const auto now = _data.options; const auto count = _data.items.size(); @@ -258,7 +257,7 @@ void ForwardPanel::editOptions( } auto data = base::take(_data); _to->owningHistory()->setForwardDraft(_to->topicRootId(), {}); - Window::ShowForwardMessagesBox(controller, { + Window::ShowForwardMessagesBox(show, { .ids = _to->owner().itemsToIds(data.items), .options = data.options, }); @@ -287,7 +286,7 @@ void ForwardPanel::editOptions( _repaint(); } }); - controller->show(Box( + show->showBox(Box( Ui::ForwardOptionsBox, count, Ui::ForwardOptions{ diff --git a/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.h b/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.h index af052ec8a4..b178e27d04 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_forward_panel.h @@ -26,6 +26,10 @@ namespace Window { class SessionController; } // namespace Window +namespace ChatHelpers { +class Show; +} // namespace ChatHelpers + namespace HistoryView::Controls { class ForwardPanel final : public base::has_weak_ptr { @@ -42,7 +46,7 @@ public: [[nodiscard]] rpl::producer<> itemsUpdated() const; - void editOptions(not_null controller); + void editOptions(std::shared_ptr show); [[nodiscard]] const HistoryItemsList &items() const; [[nodiscard]] bool empty() const; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index 3b65bc18a3..b80310d3bf 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/random.h" #include "base/unixtime.h" #include "ui/boxes/confirm_box.h" +#include "chat_helpers/compose/compose_show.h" #include "core/application.h" #include "data/data_document.h" #include "data/data_document_media.h" @@ -34,7 +35,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/ripple_animation.h" #include "ui/text/format_values.h" #include "ui/painter.h" -#include "window/window_session_controller.h" namespace HistoryView::Controls { @@ -206,7 +206,7 @@ class ListenWrap final { public: ListenWrap( not_null parent, - not_null controller, + not_null session, ::Media::Capture::Result &&data, const style::font &font); @@ -231,7 +231,7 @@ private: not_null _parent; - const not_null _controller; + const not_null _session; const not_null _document; const std::unique_ptr _voiceData; const std::shared_ptr _mediaView; @@ -264,12 +264,12 @@ private: ListenWrap::ListenWrap( not_null parent, - not_null controller, + not_null session, ::Media::Capture::Result &&data, const style::font &font) : _parent(parent) -, _controller(controller) -, _document(DummyDocument(&_controller->session().data())) +, _session(session) +, _document(DummyDocument(&session->data())) , _voiceData(ProcessCaptureResult(data)) , _mediaView(_document->createMediaView()) , _data(std::make_unique<::Media::Capture::Result>(std::move(data))) @@ -456,13 +456,6 @@ void ListenWrap::initPlayButton() { ) | rpl::start_with_next([=] { *showPause = false; }, _lifetime); - - const auto weak = Ui::MakeWeak(_controller->content().get()); - _lifetime.add([=] { - if (weak && isInPlayer()) { - weak->stopAndClosePlayer(); - } - }); } void ListenWrap::initPlayProgress() { @@ -991,17 +984,15 @@ void CancelButton::requestPaintProgress(float64 progress) { VoiceRecordBar::VoiceRecordBar( not_null parent, not_null sectionWidget, - not_null controller, + std::shared_ptr show, std::shared_ptr send, int recorderHeight) : RpWidget(parent) , _sectionWidget(sectionWidget) -, _controller(controller) +, _show(std::move(show)) , _send(send) , _lock(std::make_unique(sectionWidget)) -, _level(std::make_unique( - sectionWidget, - _controller->widget()->leaveEvents())) +, _level(std::make_unique(sectionWidget)) , _cancel(std::make_unique(this, recorderHeight)) , _startTimer([=] { startRecording(); }) , _message( @@ -1016,10 +1007,10 @@ VoiceRecordBar::VoiceRecordBar( VoiceRecordBar::VoiceRecordBar( not_null parent, - not_null controller, + std::shared_ptr show, std::shared_ptr send, int recorderHeight) -: VoiceRecordBar(parent, parent, controller, send, recorderHeight) { +: VoiceRecordBar(parent, parent, std::move(show), send, recorderHeight) { } VoiceRecordBar::~VoiceRecordBar() { @@ -1325,7 +1316,6 @@ void VoiceRecordBar::startRecording() { startRedCircleAnimation(); _recording = true; - _controller->widget()->setInnerFocus(); instance()->start(); instance()->updated( ) | rpl::start_with_next_error([=](const Update &update) { @@ -1410,7 +1400,6 @@ void VoiceRecordBar::finish() { _listen = nullptr; _sendActionUpdates.fire({ Api::SendProgressType::RecordVoice, -1 }); - _controller->widget()->setInnerFocus(); } void VoiceRecordBar::hideFast() { @@ -1434,14 +1423,15 @@ void VoiceRecordBar::stopRecording(StopType type) { return; } - Window::ActivateWindow(_controller); + window()->raise(); + window()->activateWindow(); const auto duration = Duration(data.samples); if (type == StopType::Send) { _sendVoiceRequests.fire({ data.bytes, data.waveform, duration }); } else if (type == StopType::Listen) { _listen = std::make_unique( this, - _controller, + &_show->session(), std::move(data), _cancelFont); _listenChanges.fire({}); @@ -1690,7 +1680,7 @@ void VoiceRecordBar::showDiscardBox( callback(); } }; - _controller->show(Ui::MakeConfirmBox({ + _show->showBox(Ui::MakeConfirmBox({ .text = (isListenState() ? tr::lng_record_listen_cancel_sure : tr::lng_record_lock_cancel_sure)(), diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h index 6dcb19da94..ea48e887ac 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.h @@ -23,6 +23,10 @@ namespace Window { class SessionController; } // namespace Window +namespace ChatHelpers { +class Show; +} // namespace ChatHelpers + namespace HistoryView::Controls { class VoiceRecordButton; @@ -38,12 +42,12 @@ public: VoiceRecordBar( not_null parent, not_null sectionWidget, - not_null controller, + std::shared_ptr show, std::shared_ptr send, int recorderHeight); VoiceRecordBar( not_null parent, - not_null controller, + std::shared_ptr show, std::shared_ptr send, int recorderHeight); ~VoiceRecordBar(); @@ -122,7 +126,7 @@ private: void computeAndSetLockProgress(QPoint globalPos); const not_null _sectionWidget; - const not_null _controller; + const std::shared_ptr _show; const std::shared_ptr _send; const std::unique_ptr _lock; const std::unique_ptr _level; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_button.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_button.cpp index 15dd53517d..f05b3ed441 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_button.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_button.cpp @@ -47,9 +47,7 @@ auto Blobs() { } // namespace -VoiceRecordButton::VoiceRecordButton( - not_null parent, - rpl::producer<> leaveWindowEventProducer) +VoiceRecordButton::VoiceRecordButton(not_null parent) : AbstractButton(parent) , _blobs(std::make_unique( Blobs(), @@ -57,11 +55,6 @@ VoiceRecordButton::VoiceRecordButton( kMaxLevel)) , _center(_blobs->maxRadius()) { resize(_center * 2, _center * 2); - std::move( - leaveWindowEventProducer - ) | rpl::start_with_next([=] { - _inCircle = false; - }, lifetime()); init(); } diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_button.h b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_button.h index 97c3d50729..750c8abfb3 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_button.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_button.h @@ -21,9 +21,7 @@ namespace HistoryView::Controls { class VoiceRecordButton final : public Ui::AbstractButton { public: - VoiceRecordButton( - not_null parent, - rpl::producer<> leaveWindowEventProducer); + explicit VoiceRecordButton(not_null parent); ~VoiceRecordButton(); enum class Type { @@ -53,7 +51,6 @@ private: rpl::variable _showProgress = 0.; float64 _colorProgress = 0.; - rpl::variable _inCircle = false; rpl::variable _state = Type::Record; // This can animate for a very long time (like in music playing), diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index fb6687eac5..6f6e14d4a8 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -683,22 +683,17 @@ void ContactStatus::setupBlockHandler(not_null user) { void ContactStatus::setupShareHandler(not_null user) { _inner->shareClicks( ) | rpl::start_with_next([=] { - const auto show = std::make_shared(_controller); + const auto show = _controller->uiShow(); const auto share = [=](Fn &&close) { user->setSettings(0); user->session().api().request(MTPcontacts_AcceptContact( user->inputUser )).done([=](const MTPUpdates &result) { user->session().api().applyUpdates(result); - - if (show->valid()) { - Ui::Toast::Show( - show->toastParent(), - tr::lng_new_contact_share_done( - tr::now, - lt_user, - user->shortName())); - } + show->showToast(tr::lng_new_contact_share_done( + tr::now, + lt_user, + user->shortName())); }).send(); close(); }; @@ -735,8 +730,8 @@ void ContactStatus::setupReportHandler(not_null peer) { _inner->reportClicks( ) | rpl::start_with_next([=] { Expects(!peer->isUser()); - const auto show = std::make_shared(_controller); + const auto show = _controller->uiShow(); const auto callback = crl::guard(_inner, [=](Fn &&close) { close(); @@ -751,11 +746,7 @@ void ContactStatus::setupReportHandler(not_null peer) { peer->session().api().deleteConversation(peer, false); }); - if (show->valid()) { - Ui::Toast::Show( - show->toastParent(), - tr::lng_report_spam_done(tr::now)); - } + show->showToast(tr::lng_report_spam_done(tr::now)); // Destroys _bar. _controller->showBackFromStack(); diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index cc3d8586ba..14f211bac7 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -130,14 +130,14 @@ void CopyImage(not_null photo) { void ShowStickerPackInfo( not_null document, not_null list) { - StickerSetBox::Show(list->controller(), document); + StickerSetBox::Show(list->controller()->uiShow(), document); } void ToggleFavedSticker( not_null controller, not_null document, FullMsgId contextId) { - Api::ToggleFavedSticker(controller, document, contextId); + Api::ToggleFavedSticker(controller->uiShow(), document, contextId); } void AddPhotoActions( @@ -181,7 +181,7 @@ void SaveGif( if (const auto media = item->media()) { if (const auto document = media->document()) { Api::ToggleSavedGif( - controller, + controller->uiShow(), document, item->fullId(), true); @@ -564,8 +564,7 @@ bool AddRescheduleAction( &request.navigation->session(), sendMenuType, callback, - date), - Ui::LayerOption::KeepOther); + date)); owner->itemRemoved( ) | rpl::start_with_next([=](not_null item) { @@ -1126,11 +1125,9 @@ void CopyPostLink( return channel->hasUsername(); }(); - Ui::Toast::Show( - Window::Show(controller).toastParent(), - isPublicLink - ? tr::lng_channel_public_link_copied(tr::now) - : tr::lng_context_about_private_link(tr::now)); + controller->showToast(isPublicLink + ? tr::lng_channel_public_link_copied(tr::now) + : tr::lng_context_about_private_link(tr::now)); } void AddPollActions( @@ -1148,7 +1145,7 @@ void AddPollActions( } if (!Ui::SkipTranslate({ text })) { menu->addAction(tr::lng_context_translate(tr::now), [=] { - Window::Show(controller).showBox(Box( + controller->show(Box( Ui::TranslateBox, item->history()->peer, MsgId(), @@ -1211,16 +1208,13 @@ void AddSaveSoundForNotifications( } else { return; } - const auto toastParent = Window::Show(controller).toastParent(); + const auto show = controller->uiShow(); menu->addAction(tr::lng_context_save_custom_sound(tr::now), [=] { Api::ToggleSavedRingtone( document, item->fullId(), - crl::guard(toastParent, [=] { - Ui::Toast::Show( - toastParent, - tr::lng_ringtones_toast_added(tr::now)); - }), + [=] { show->showToast( + tr::lng_ringtones_toast_added(tr::now)); }, true); }, &st::menuIconSoundAdd); } @@ -1451,17 +1445,14 @@ void AddEmojiPacksAction( if (!strong) { return; } else if (packIds.size() > 1) { - strong->show(Box(strong, packIds)); + strong->show(Box(strong->uiShow(), packIds)); return; } // Single used emoji pack. - strong->show( - Box( - strong, - packIds.front(), - Data::StickersType::Emoji), - Ui::LayerOption::KeepOther); - + strong->show(Box( + strong->uiShow(), + packIds.front(), + Data::StickersType::Emoji)); }); menu->addAction(std::move(button)); } diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 8f13011cd4..d219727c1d 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -36,7 +36,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/reaction_fly_animation.h" #include "ui/chat/chat_style.h" #include "ui/toast/toast.h" -#include "ui/toasts/common_toasts.h" #include "ui/text/text_options.h" #include "ui/text/text_utilities.h" #include "ui/item_text_options.h" @@ -1012,10 +1011,7 @@ ClickHandlerPtr Element::fromLink() const { const auto my = context.other.value(); const auto weak = my.sessionWindow; if (const auto strong = weak.get()) { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(strong).toastParent(), - .text = { tr::lng_forwarded_imported(tr::now) }, - }); + strong->showToast(tr::lng_forwarded_imported(tr::now)); } }); return imported; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index d1d792ddc3..f45f4f62ba 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -44,7 +44,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/widgets/scroll_area.h" #include "ui/toast/toast.h" -#include "ui/toasts/common_toasts.h" #include "ui/inactive_press.h" #include "ui/effects/message_sending_animation_controller.h" #include "ui/effects/path_shift_gradient.h" @@ -1443,12 +1442,9 @@ bool ListWidget::showCopyRestriction(HistoryItem *item) { if (type == CopyRestrictionType::None) { return false; } - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(_controller).toastParent(), - .text = { (type == CopyRestrictionType::Channel) - ? tr::lng_error_nocopy_channel(tr::now) - : tr::lng_error_nocopy_group(tr::now) }, - }); + _controller->showToast((type == CopyRestrictionType::Channel) + ? tr::lng_error_nocopy_channel(tr::now) + : tr::lng_error_nocopy_group(tr::now)); return true; } @@ -1457,12 +1453,9 @@ bool ListWidget::showCopyMediaRestriction(not_null item) { if (type == CopyRestrictionType::None) { return false; } - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(_controller).toastParent(), - .text = { (type == CopyRestrictionType::Channel) - ? tr::lng_error_nocopy_channel(tr::now) - : tr::lng_error_nocopy_group(tr::now) }, - }); + _controller->showToast((type == CopyRestrictionType::Channel) + ? tr::lng_error_nocopy_channel(tr::now) + : tr::lng_error_nocopy_group(tr::now)); return true; } diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 01d654cd1d..5e0f36ddfa 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -25,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/reaction_fly_animation.h" #include "ui/chat/message_bubble.h" #include "ui/chat/chat_style.h" -#include "ui/toasts/common_toasts.h" #include "ui/text/text_utilities.h" #include "ui/text/text_entity.h" #include "ui/cached_round_corners.h" @@ -2061,11 +2060,8 @@ ClickHandlerPtr Message::createGoToCommentsLink() const { const auto history = item->history(); if (const auto channel = history->peer->asChannel()) { if (channel->invitePeekExpires()) { - const auto show = Window::Show(controller); - Ui::ShowMultilineToast({ - .parentOverride = show.toastParent(), - .text = { tr::lng_channel_invite_private(tr::now) }, - }); + controller->showToast( + tr::lng_channel_invite_private(tr::now)); return; } } diff --git a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp index 22ca0af7a0..0fc999bec1 100644 --- a/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_pinned_section.cpp @@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/format_values.h" #include "ui/text/text_utilities.h" #include "ui/ui_utility.h" -#include "ui/toasts/common_toasts.h" #include "base/timer_rpl.h" #include "apiwrap.h" #include "window/window_adaptive.h" diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 0056d6a298..22145b3764 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -861,7 +861,7 @@ void RepliesWidget::chooseAttach( std::optional overrideSendImagesAsPhotos) { _choosingAttach = false; if (const auto error = Data::AnyFileRestrictionError(_history->peer)) { - controller()->showToast({ *error }); + controller()->showToast(*error); return; } else if (showSlowmodeError()) { return; @@ -1054,7 +1054,7 @@ bool RepliesWidget::showSlowmodeError() { if (text.isEmpty()) { return false; } - controller()->showToast({ text }); + controller()->showToast(text); return true; } @@ -1127,7 +1127,7 @@ bool RepliesWidget::showSendingFilesError( return true; } - controller()->showToast({ text }); + controller()->showToast(text); return true; } @@ -1189,7 +1189,7 @@ void RepliesWidget::send(Api::SendOptions options) { .ignoreSlowmodeCountdown = (options.scheduled != 0), }); if (!error.isEmpty()) { - controller()->showToast({ error }); + controller()->showToast(error); return; } @@ -1238,9 +1238,8 @@ void RepliesWidget::edit( return; } else if (!left.text.isEmpty()) { const auto remove = left.text.size(); - controller()->showToast({ - tr::lng_edit_limit_reached(tr::now, lt_count, remove), - }); + controller()->showToast( + tr::lng_edit_limit_reached(tr::now, lt_count, remove)); return; } @@ -1264,13 +1263,13 @@ void RepliesWidget::edit( } if (ranges::contains(Api::kDefaultEditMessagesErrors, error)) { - controller()->showToast({ tr::lng_edit_error(tr::now) }); + controller()->showToast(tr::lng_edit_error(tr::now)); } else if (error == u"MESSAGE_NOT_MODIFIED"_q) { _composeControls->cancelEditMessage(); } else if (error == u"MESSAGE_EMPTY"_q) { doSetInnerFocus(); } else { - controller()->showToast({ tr::lng_edit_error(tr::now) }); + controller()->showToast(tr::lng_edit_error(tr::now)); } update(); return true; @@ -1351,7 +1350,7 @@ bool RepliesWidget::sendExistingDocument( _history->peer, ChatRestriction::SendStickers); if (error) { - controller()->showToast({ *error }); + controller()->showToast(*error); return false; } else if (showSlowmodeError() || ShowSendPremiumError(controller(), document)) { @@ -1386,7 +1385,7 @@ bool RepliesWidget::sendExistingPhoto( _history->peer, ChatRestriction::SendPhotos); if (error) { - controller()->showToast({ *error }); + controller()->showToast(*error); return false; } else if (showSlowmodeError()) { return false; @@ -1406,7 +1405,7 @@ void RepliesWidget::sendInlineResult( not_null bot) { const auto errorText = result->getErrorOnSend(_history); if (!errorText.isEmpty()) { - controller()->showToast({ errorText }); + controller()->showToast(errorText); return; } sendInlineResult(result, bot, {}, std::nullopt); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index ce01b68c22..85ce03471b 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -332,7 +332,7 @@ void ScheduledWidget::setupComposeControls() { void ScheduledWidget::chooseAttach() { if (const auto error = Data::AnyFileRestrictionError(_history->peer)) { - controller()->showToast({ *error }); + controller()->showToast(*error); return; } @@ -526,9 +526,7 @@ void ScheduledWidget::uploadFile( type, prepareSendAction(options)); }; - controller()->show( - PrepareScheduleBox(this, sendMenuType(), callback), - Ui::LayerOption::KeepOther); + controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); } bool ScheduledWidget::showSendingFilesError( @@ -565,7 +563,7 @@ bool ScheduledWidget::showSendingFilesError( return true; } - controller()->showToast({ text }); + controller()->showToast(text); return true; } @@ -591,13 +589,11 @@ void ScheduledWidget::send() { .ignoreSlowmodeCountdown = true, }); if (!error.isEmpty()) { - controller()->showToast({ error }); + controller()->showToast(error); return; } const auto callback = [=](Api::SendOptions options) { send(options); }; - controller()->show( - PrepareScheduleBox(this, sendMenuType(), callback), - Ui::LayerOption::KeepOther); + controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); } void ScheduledWidget::send(Api::SendOptions options) { @@ -627,9 +623,7 @@ void ScheduledWidget::sendVoice( const auto callback = [=](Api::SendOptions options) { sendVoice(bytes, waveform, duration, options); }; - controller()->show( - PrepareScheduleBox(this, sendMenuType(), callback), - Ui::LayerOption::KeepOther); + controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); } void ScheduledWidget::sendVoice( @@ -674,9 +668,8 @@ void ScheduledWidget::edit( return; } else if (!left.text.isEmpty()) { const auto remove = left.text.size(); - controller()->showToast({ - tr::lng_edit_limit_reached(tr::now, lt_count, remove) - }); + controller()->showToast( + tr::lng_edit_limit_reached(tr::now, lt_count, remove)); return; } @@ -700,13 +693,13 @@ void ScheduledWidget::edit( } if (ranges::contains(Api::kDefaultEditMessagesErrors, error)) { - controller()->showToast({ tr::lng_edit_error(tr::now) }); + controller()->showToast(tr::lng_edit_error(tr::now)); } else if (error == u"MESSAGE_NOT_MODIFIED"_q) { _composeControls->cancelEditMessage(); } else if (error == u"MESSAGE_EMPTY"_q) { _composeControls->focus(); } else { - controller()->showToast({ tr::lng_edit_error(tr::now) }); + controller()->showToast(tr::lng_edit_error(tr::now)); } update(); return true; @@ -728,9 +721,7 @@ void ScheduledWidget::sendExistingDocument( const auto callback = [=](Api::SendOptions options) { sendExistingDocument(document, options); }; - controller()->show( - PrepareScheduleBox(this, sendMenuType(), callback), - Ui::LayerOption::KeepOther); + controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); } bool ScheduledWidget::sendExistingDocument( @@ -740,7 +731,7 @@ bool ScheduledWidget::sendExistingDocument( _history->peer, ChatRestriction::SendStickers); if (error) { - controller()->showToast({ *error }); + controller()->showToast(*error); return false; } else if (ShowSendPremiumError(controller(), document)) { return false; @@ -759,9 +750,7 @@ void ScheduledWidget::sendExistingPhoto(not_null photo) { const auto callback = [=](Api::SendOptions options) { sendExistingPhoto(photo, options); }; - controller()->show( - PrepareScheduleBox(this, sendMenuType(), callback), - Ui::LayerOption::KeepOther); + controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); } bool ScheduledWidget::sendExistingPhoto( @@ -771,7 +760,7 @@ bool ScheduledWidget::sendExistingPhoto( _history->peer, ChatRestriction::SendPhotos); if (error) { - controller()->showToast({ *error }); + controller()->showToast(*error); return false; } @@ -789,15 +778,13 @@ void ScheduledWidget::sendInlineResult( not_null bot) { const auto errorText = result->getErrorOnSend(_history); if (!errorText.isEmpty()) { - controller()->showToast({ errorText }); + controller()->showToast(errorText); return; } const auto callback = [=](Api::SendOptions options) { sendInlineResult(result, bot, options); }; - controller()->show( - PrepareScheduleBox(this, sendMenuType(), callback), - Ui::LayerOption::KeepOther); + controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); } void ScheduledWidget::sendInlineResult( @@ -1264,9 +1251,7 @@ void ScheduledWidget::listSendBotCommand( message.textWithTags = { text }; session().api().sendMessage(std::move(message)); }; - controller()->show( - PrepareScheduleBox(this, sendMenuType(), callback), - Ui::LayerOption::KeepOther); + controller()->show(PrepareScheduleBox(this, sendMenuType(), callback)); } void ScheduledWidget::listHandleViaClick(not_null bot) { diff --git a/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp b/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp index 5cf22f4464..f10d8e3283 100644 --- a/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp @@ -165,7 +165,7 @@ void StickerToast::showWithTitle(const QString &title) { _weak = Ui::Toast::Show(_parent, Ui::Toast::Config{ .text = text, .st = &_st, - .durationMs = kPremiumToastDuration, + .duration = kPremiumToastDuration, .multiline = true, .dark = true, .slideSide = RectPart::Bottom, @@ -241,7 +241,7 @@ void StickerToast::showWithTitle(const QString &title) { PremiumPreview::AnimatedEmoji); } else { _controller->show(Box( - _controller, + _controller->uiShow(), _for->sticker()->set, setType)); } 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 808c26e5db..fa0d6ed7f3 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -31,7 +31,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/widgets/menu/menu_add_action_callback_factory.h" #include "ui/effects/radial_animation.h" -#include "ui/toasts/common_toasts.h" #include "ui/boxes/report_box.h" // Ui::ReportReason #include "ui/text/text.h" #include "ui/text/text_options.h" diff --git a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp index adf6b75e57..456e5cd871 100644 --- a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp @@ -524,7 +524,7 @@ void TranslateBar::showToast( const auto weak = Ui::Toast::Show(_wrap.window(), Ui::Toast::Config{ .text = std::move(text), .st = st.get(), - .durationMs = kToastDuration, + .duration = kToastDuration, .multiline = true, .dark = true, .slideSide = RectPart::Bottom, diff --git a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp index b4000725b1..b3ff9b0694 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_sticker.cpp @@ -412,7 +412,7 @@ ClickHandlerPtr Sticker::ShowSetHandler(not_null document) { return std::make_shared([=](ClickContext context) { const auto my = context.other.value(); if (const auto window = my.sessionWindow.get()) { - StickerSetBox::Show(window, document); + StickerSetBox::Show(window->uiShow(), document); } }); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp index ac730600d4..0cd31f4834 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp @@ -483,12 +483,10 @@ ClickHandlerPtr ThemeDocumentBox::createViewLink() { if (out) { controller->toggleChooseChatTheme(to); } else if (maybe) { - controller->show( - Box( - controller, - *maybe, - BackgroundPreviewArgs{ to, itemId }), - Ui::LayerOption::KeepOther); + controller->show(Box( + controller, + *maybe, + BackgroundPreviewArgs{ to, itemId })); } } }); diff --git a/Telegram/SourceFiles/history/view/media/history_view_userpic_suggestion.cpp b/Telegram/SourceFiles/history/view/media/history_view_userpic_suggestion.cpp index 1d4603a14e..7056a7780b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_userpic_suggestion.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_userpic_suggestion.cpp @@ -143,11 +143,10 @@ void ShowSetToast( st->padding.setLeft(skip + size + skip); st->palette.linkFg = st->palette.selectLinkFg = st::mediaviewTextLinkFg; - const auto parent = Window::Show(controller).toastParent(); - const auto weak = Ui::Toast::Show(parent, { + const auto weak = controller->showToast({ .text = text, .st = st.get(), - .durationMs = kToastDuration, + .duration = kToastDuration, .multiline = true, .dark = true, .slideSide = RectPart::Bottom, diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp index aed682aebf..ca6ddf2261 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp @@ -777,9 +777,8 @@ void Selector::createList(not_null controller) { } _list = _scroll->setOwnedWidget( object_ptr(_scroll, EmojiListDescriptor{ - .session = &controller->session(), + .show = controller->uiShow(), .mode = _listMode, - .controller = controller, .paused = [] { return false; }, .customRecentList = std::move(recent), .customRecentFactory = std::move(factory), diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp index fb8e5f9a07..fed48653b1 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp @@ -172,7 +172,7 @@ InnerWidget::InnerWidget( not_null controller, not_null user) : RpWidget(parent) -, _show(std::make_unique(controller->parentController())) +, _show(controller->uiShow()) , _controller(controller) , _user(user) , _listController(std::make_unique(controller, _user)) @@ -291,8 +291,8 @@ void InnerWidget::peerListHideLayer() { _show->hideLayer(); } -not_null InnerWidget::peerListToastParent() { - return _show->toastParent(); +std::shared_ptr InnerWidget::peerListUiShow() { + return _show; } } // namespace CommonGroups diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h index dc85733554..91d9067821 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h @@ -11,9 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "boxes/peer_list_box.h" -namespace Window { +namespace Ui { class Show; -} // namespace Window +} // namespace Ui namespace Info { @@ -68,13 +68,13 @@ private: object_ptr content, Ui::LayerOptions options = Ui::LayerOption::KeepOther) override; void peerListHideLayer() override; - not_null peerListToastParent() override; + std::shared_ptr peerListUiShow() override; object_ptr setupList( RpWidget *parent, not_null controller) const; - std::unique_ptr _show; + std::shared_ptr _show; not_null _controller; not_null _user; std::unique_ptr _listController; diff --git a/Telegram/SourceFiles/info/polls/info_polls_results_inner_widget.cpp b/Telegram/SourceFiles/info/polls/info_polls_results_inner_widget.cpp index 2b8248e135..c4086ff5aa 100644 --- a/Telegram/SourceFiles/info/polls/info_polls_results_inner_widget.cpp +++ b/Telegram/SourceFiles/info/polls/info_polls_results_inner_widget.cpp @@ -55,7 +55,7 @@ public: object_ptr content, Ui::LayerOptions options = Ui::LayerOption::KeepOther) override; void peerListHideLayer() override; - not_null peerListToastParent() override; + std::shared_ptr peerListUiShow() override; }; @@ -100,8 +100,8 @@ void ListDelegate::peerListShowBox( void ListDelegate::peerListHideLayer() { } -not_null ListDelegate::peerListToastParent() { - Unexpected("...ListDelegate::peerListToastParent"); +std::shared_ptr ListDelegate::peerListUiShow() { + Unexpected("...ListDelegate::peerListUiShow"); } } // namespace diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index c319afaf5b..82e0e57203 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -103,7 +103,7 @@ namespace { [[nodiscard]] Fn UsernamesLinkCallback( not_null peer, - Window::Show show, + std::shared_ptr show, const QString &addToLink) { return [=](QString link) { if (!link.startsWith(u"https://"_q)) { @@ -112,9 +112,7 @@ namespace { } if (!link.isEmpty()) { QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show( - show.toastParent(), - tr::lng_username_copied(tr::now)); + show->showToast(tr::lng_username_copied(tr::now)); } }; } @@ -424,7 +422,7 @@ object_ptr DetailsFiller::setupInfo() { st::infoProfileLabeledUsernamePadding); const auto callback = UsernamesLinkCallback( _peer, - Window::Show(controller), + controller->uiShow(), QString()); const auto hook = [=](Ui::FlatLabel::ContextMenuRequest request) { if (!request.link) { @@ -471,9 +469,7 @@ object_ptr DetailsFiller::setupInfo() { user->userName()); if (!link.isEmpty()) { QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show( - Window::Show(controller).toastParent(), - tr::lng_username_copied(tr::now)); + controller->showToast(tr::lng_username_copied(tr::now)); } return false; }); @@ -511,7 +507,7 @@ object_ptr DetailsFiller::setupInfo() { const auto controller = _controller->parentController(); const auto linkCallback = UsernamesLinkCallback( _peer, - Window::Show(controller), + controller->uiShow(), addToLink); linkLine.text->overrideLinkClickHandler(linkCallback); linkLine.subtext->overrideLinkClickHandler(linkCallback); @@ -603,7 +599,7 @@ object_ptr DetailsFiller::setupMuteToggle() { } }) | rpl::to_empty, makeThread, - std::make_shared(_controller)); + _controller->uiShow()); object_ptr( result, st::infoIconNotifications, diff --git a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp index c65c4cf408..352aa8b458 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_emoji_status_panel.cpp @@ -134,7 +134,7 @@ void EmojiStatusPanel::create( controller, object_ptr( nullptr, - controller, + controller->uiShow(), Window::GifPauseReason::Layer, ChatHelpers::TabbedSelector::Mode::EmojiStatus)); _panel->setDropDown(true); diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.cpp b/Telegram/SourceFiles/info/profile/info_profile_members.cpp index 88915b760b..605ebbad52 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members.cpp @@ -46,7 +46,7 @@ Members::Members( QWidget *parent, not_null controller) : RpWidget(parent) -, _show(std::make_unique(controller->parentController())) +, _show(controller->uiShow()) , _controller(controller) , _peer(_controller->key().peer()) , _listController(CreateMembersController(controller, _peer)) { @@ -467,8 +467,8 @@ void Members::peerListHideLayer() { _show->hideLayer(); } -not_null Members::peerListToastParent() { - return _show->toastParent(); +std::shared_ptr Members::peerListUiShow() { + return _show; } void Members::peerListSetDescription( diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.h b/Telegram/SourceFiles/info/profile/info_profile_members.h index 99a6135d34..2789756ce1 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.h +++ b/Telegram/SourceFiles/info/profile/info_profile_members.h @@ -82,7 +82,7 @@ private: object_ptr content, Ui::LayerOptions options = Ui::LayerOption::KeepOther) override; void peerListHideLayer() override; - not_null peerListToastParent() override; + std::shared_ptr peerListUiShow() override; //void peerListAppendRow( // std::unique_ptr row) override { @@ -114,7 +114,7 @@ private: void updateHeaderControlsGeometry(int newWidth); //void updateSearchEnabledByContent(); - std::unique_ptr _show; + std::shared_ptr _show; //Wrap _wrap; not_null _controller; diff --git a/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder_widget.cpp b/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder_widget.cpp index 8756628f40..6f91868822 100644 --- a/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder_widget.cpp +++ b/Telegram/SourceFiles/info/userpic/info_userpic_emoji_builder_widget.cpp @@ -153,7 +153,7 @@ void ShowGradientEditor( not_null controller, StartData data, Fn)> &&doneCallback) { - Window::Show(controller).showBox(Box([=](not_null box) { + controller->show(Box([=](not_null box) { struct State { rpl::event_stream<> saveRequests; }; @@ -180,7 +180,6 @@ void ShowGradientEditor( }); box->setWidth(content->width()); box->addRow(std::move(content), {}); - })); } @@ -242,9 +241,8 @@ EmojiSelector::Selector EmojiSelector::createEmojiList( const auto manager = &session->data().customEmojiManager(); const auto tag = Data::CustomEmojiManager::SizeTag::Large; auto args = ChatHelpers::EmojiListDescriptor{ - .session = session, + .show = _controller->uiShow(), .mode = ChatHelpers::EmojiListMode::UserpicBuilder, - .controller = _controller, .paused = [=] { return true; }, .customRecentList = _lastRecent, .customRecentFactory = [=](DocumentId id, Fn repaint) { diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 30927307ff..09de04d9ba 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_domain.h" #include "info/profile/info_profile_values.h" #include "ui/boxes/confirm_box.h" -#include "ui/toasts/common_toasts.h" #include "ui/chat/attach/attach_bot_webview.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/dropdown_menu.h" @@ -182,7 +181,7 @@ void ShowChooseBox( &controller->session(), std::move(done), std::move(filter)), - std::move(initBox)), Ui::LayerOption::KeepOther); + std::move(initBox))); } [[nodiscard]] base::flat_set> &ActiveWebViews() { @@ -1216,12 +1215,9 @@ void AttachWebView::showToast( : _addToMenuContext ? _addToMenuContext->controller.get() : nullptr; - Ui::ShowMultilineToast({ - .parentOverride = (strong - ? Window::Show(strong).toastParent().get() - : nullptr), - .text = { text }, - }); + if (strong) { + strong->showToast(text); + } } void AttachWebView::confirmAddToMenu( diff --git a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp index b0dd9d710c..0103789ecb 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp @@ -357,7 +357,7 @@ void Inner::contextMenuEvent(QContextMenuEvent *e) { }; ChatHelpers::AddGifAction( std::move(callback), - _controller, + _controller->uiShow(), previewDocument); } diff --git a/Telegram/SourceFiles/intro/intro_phone.cpp b/Telegram/SourceFiles/intro/intro_phone.cpp index 1e2560a8cf..d822d056be 100644 --- a/Telegram/SourceFiles/intro/intro_phone.cpp +++ b/Telegram/SourceFiles/intro/intro_phone.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/boxes/confirm_box.h" #include "boxes/phone_banned_box.h" #include "core/application.h" +#include "window/window_controller.h" #include "window/window_session_controller.h" #include "countries/countries_instance.h" // Countries::Groups @@ -46,7 +47,7 @@ PhoneWidget::PhoneWidget( : Step(parent, account, data) , _country( this, - std::make_shared(getData()->controller), + getData()->controller->uiShow(), st::introCountry) , _code(this, st::introCountryCode) , _phone( diff --git a/Telegram/SourceFiles/main/session/session_show.cpp b/Telegram/SourceFiles/main/session/session_show.cpp new file mode 100644 index 0000000000..bbd0b4284b --- /dev/null +++ b/Telegram/SourceFiles/main/session/session_show.cpp @@ -0,0 +1,77 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "main/session/session_show.h" + +namespace Main { +namespace { + +class SimpleSessionShow final : public SessionShow { +public: + SimpleSessionShow( + std::shared_ptr show, + not_null session); + + void showBox( + object_ptr content, + Ui::LayerOptions options + = Ui::LayerOption::KeepOther) const override; + void hideLayer() const override; + not_null toastParent() const override; + bool valid() const override; + operator bool() const override; + + Session &session() const override; + +private: + const std::shared_ptr _show; + const not_null _session; + +}; + +SimpleSessionShow::SimpleSessionShow( + std::shared_ptr show, + not_null session) +: _show(std::move(show)) +, _session(session) { +} + +void SimpleSessionShow::showBox( + object_ptr content, + Ui::LayerOptions options) const { + _show->showBox(std::move(content), options); +} + +void SimpleSessionShow::hideLayer() const { + _show->hideLayer(); +} + +not_null SimpleSessionShow::toastParent() const { + return _show->toastParent(); +} + +bool SimpleSessionShow::valid() const { + return _show->valid(); +} + +SimpleSessionShow::operator bool() const { + return _show->operator bool(); +} + +Session &SimpleSessionShow::session() const { + return *_session; +} + +} // namespace + +std::shared_ptr MakeSessionShow( + std::shared_ptr show, + not_null session) { + return std::make_shared(std::move(show), session); +} + +} // namespace Main diff --git a/Telegram/SourceFiles/main/session/session_show.h b/Telegram/SourceFiles/main/session/session_show.h new file mode 100644 index 0000000000..ae764e1254 --- /dev/null +++ b/Telegram/SourceFiles/main/session/session_show.h @@ -0,0 +1,25 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "ui/layers/show.h" + +namespace Main { + +class Session; + +class SessionShow : public Ui::Show { +public: + [[nodiscard]] virtual Main::Session &session() const = 0; +}; + +[[nodiscard]] std::shared_ptr MakeSessionShow( + std::shared_ptr show, + not_null session); + +} // namespace Main diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e438645686..4b46807d0b 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -35,7 +35,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/chat_theme.h" #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" -#include "ui/toasts/common_toasts.h" #include "ui/widgets/dropdown_menu.h" #include "ui/image/image.h" #include "ui/focus_persister.h" @@ -941,7 +940,7 @@ void MainWidget::setCurrentGroupCall(Calls::GroupCall *call) { void MainWidget::createCallTopBar() { Expects(_currentCall != nullptr || _currentGroupCall != nullptr); - const auto show = std::make_shared(controller()); + const auto show = controller()->uiShow(); _callTopBar.create( this, (_currentCall @@ -1221,10 +1220,7 @@ void MainWidget::showChooseReportMessages( peer, SectionShow::Way::Forward, ShowForChooseMessagesMsgId); - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(controller()).toastParent(), - .text = { tr::lng_report_please_select_messages(tr::now) }, - }); + controller()->showToast(tr::lng_report_please_select_messages(tr::now)); } void MainWidget::clearChooseReportMessages() { diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 65daf78ed5..3447c00b9d 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -352,8 +352,7 @@ void MainWindow::ensureLayerCreated() { } _layer = base::make_unique_q( bodyWidget(), - crl::guard(this, [=] { - return std::make_shared(&controller()); })); + crl::guard(this, [=] { return controller().uiShow(); })); _layer->hideFinishEvents( ) | rpl::filter([=] { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index a33342ea53..fb5bfb5460 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -26,7 +26,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/platform/ui_platform_utility.h" #include "ui/platform/ui_platform_window_title.h" #include "ui/toast/toast.h" -#include "ui/toasts/common_toasts.h" #include "ui/text/format_values.h" #include "ui/item_text_options.h" #include "ui/painter.h" @@ -860,12 +859,9 @@ bool OverlayWidget::showCopyMediaRestriction() { if (!hasCopyMediaRestriction()) { return false; } - Ui::ShowMultilineToast({ - .parentOverride = _widget, - .text = { _history->peer->isBroadcast() - ? tr::lng_error_nocopy_channel(tr::now) - : tr::lng_error_nocopy_group(tr::now) }, - }); + Ui::Toast::Show(_widget, _history->peer->isBroadcast() + ? tr::lng_error_nocopy_channel(tr::now) + : tr::lng_error_nocopy_group(tr::now)); return true; } diff --git a/Telegram/SourceFiles/menu/menu_antispam_validator.cpp b/Telegram/SourceFiles/menu/menu_antispam_validator.cpp index bb48448a62..b15ad58096 100644 --- a/Telegram/SourceFiles/menu/menu_antispam_validator.cpp +++ b/Telegram/SourceFiles/menu/menu_antispam_validator.cpp @@ -20,7 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "settings/settings_common.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" +#include "ui/toast/toast.h" #include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" #include "ui/wrap/slide_wrap.h" @@ -99,14 +99,11 @@ object_ptr AntiSpamValidator::createButton() const { ) | rpl::start_with_next([=, controller = _controller](bool toggled) { if (state->locked.current() && toggled) { state->toggled.fire(false); - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(controller).toastParent(), - .text = tr::lng_manage_peer_antispam_not_enough( - tr::now, - lt_count, - EnableAntiSpamMinMembers(channel), - Ui::Text::RichLangValue), - }); + controller->showToast(tr::lng_manage_peer_antispam_not_enough( + tr::now, + lt_count, + EnableAntiSpamMinMembers(channel), + Ui::Text::RichLangValue)); } else { channel->session().api().request(MTPchannels_ToggleAntiSpam( channel->inputChannel, @@ -168,8 +165,7 @@ void AntiSpamValidator::addAction( const auto showToast = [=, window = _controller, channel = _channel] { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(window).toastParent(), + window->showToast({ .text = text, .duration = ApiWrap::kJoinErrorDuration, .filter = [=]( diff --git a/Telegram/SourceFiles/menu/menu_item_download_files.cpp b/Telegram/SourceFiles/menu/menu_item_download_files.cpp index 032471a96d..3c4573e804 100644 --- a/Telegram/SourceFiles/menu/menu_item_download_files.cpp +++ b/Telegram/SourceFiles/menu/menu_item_download_files.cpp @@ -115,7 +115,7 @@ void AddAction( File::ShowInFolder(lastPath); return false; }; - const auto config = Ui::Toast::Config{ + controller->showToast({ .text = (photos.size() > 1 ? tr::lng_mediaview_saved_images_to : tr::lng_mediaview_saved_to)( @@ -127,8 +127,7 @@ void AddAction( Ui::Text::WithEntities), .st = &st::defaultToast, .filter = filter, - }; - Ui::Toast::Show(Window::Show(controller).toastParent(), config); + }); } }; const auto saveDocuments = [=](const QString &folderPath) { diff --git a/Telegram/SourceFiles/menu/menu_ttl_validator.cpp b/Telegram/SourceFiles/menu/menu_ttl_validator.cpp index 4a0edd2e75..a5ecac4278 100644 --- a/Telegram/SourceFiles/menu/menu_ttl_validator.cpp +++ b/Telegram/SourceFiles/menu/menu_ttl_validator.cpp @@ -19,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/layers/show.h" #include "ui/text/text_utilities.h" #include "ui/toast/toast.h" -#include "ui/toasts/common_toasts.h" #include "ui/text/format_values.h" #include "styles/style_chat.h" #include "styles/style_menu_icons.h" @@ -30,11 +29,11 @@ namespace { constexpr auto kToastDuration = crl::time(3500); void ShowAutoDeleteToast( - not_null parent, + std::shared_ptr show, not_null peer) { const auto period = peer->messagesTTL(); if (!period) { - Ui::Toast::Show(parent, tr::lng_ttl_about_tooltip_off(tr::now)); + show->showToast(tr::lng_ttl_about_tooltip_off(tr::now)); return; } @@ -44,11 +43,7 @@ void ShowAutoDeleteToast( const auto text = peer->isBroadcast() ? tr::lng_ttl_about_tooltip_channel(tr::now, lt_duration, duration) : tr::lng_ttl_about_tooltip(tr::now, lt_duration, duration); - Ui::ShowMultilineToast({ - .parentOverride = parent, - .text = { text }, - .duration = kToastDuration, - }); + show->showToast(text, kToastDuration); } } // namespace @@ -79,15 +74,12 @@ Args TTLValidator::createArgs() const { api.request(state->savingRequestId).cancel(); } state->savingPeriod = period; - const auto weak = Ui::MakeWeak(show->toastParent().get()); state->savingRequestId = api.request(MTPmessages_SetHistoryTTL( peer->input, MTP_int(period) )).done([=](const MTPUpdates &result) { peer->session().api().applyUpdates(result); - if (const auto strong = weak.data()) { - ShowAutoDeleteToast(strong, peer); - } + ShowAutoDeleteToast(show, peer); state->savingRequestId = 0; }).fail([=] { state->savingRequestId = 0; @@ -130,7 +122,7 @@ bool TTLValidator::can() const { } void TTLValidator::showToast() const { - ShowAutoDeleteToast(_show->toastParent(), _peer); + ShowAutoDeleteToast(_show, _peer); } const style::icon *TTLValidator::icon() const { diff --git a/Telegram/SourceFiles/payments/payments_checkout_process.cpp b/Telegram/SourceFiles/payments/payments_checkout_process.cpp index ee6ef45e22..6b289c67cc 100644 --- a/Telegram/SourceFiles/payments/payments_checkout_process.cpp +++ b/Telegram/SourceFiles/payments/payments_checkout_process.cpp @@ -342,9 +342,9 @@ void CheckoutProcess::handleFormUpdate(const FormUpdate &update) { } void CheckoutProcess::handleError(const Error &error) { - const auto showToast = [&](const TextWithEntities &text) { + const auto showToast = [&](TextWithEntities &&text) { _panel->requestActivate(); - _panel->showToast(text); + _panel->showToast(std::move(text)); }; const auto &id = error.id; switch (error.type) { diff --git a/Telegram/SourceFiles/payments/ui/payments_panel.cpp b/Telegram/SourceFiles/payments/ui/payments_panel.cpp index 2f9b1cfa49..e68fab1491 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_panel.cpp @@ -859,8 +859,8 @@ void Panel::showBox(object_ptr box) { anim::type::normal); } -void Panel::showToast(const TextWithEntities &text) { - _widget->showToast(text); +void Panel::showToast(TextWithEntities &&text) { + _widget->showToast(std::move(text)); } void Panel::showCriticalError(const TextWithEntities &text) { diff --git a/Telegram/SourceFiles/payments/ui/payments_panel.h b/Telegram/SourceFiles/payments/ui/payments_panel.h index 502eb5f073..47ec4284f9 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel.h +++ b/Telegram/SourceFiles/payments/ui/payments_panel.h @@ -90,7 +90,7 @@ public: [[nodiscard]] rpl::producer savedMethodChosen() const; void showBox(object_ptr box); - void showToast(const TextWithEntities &text); + void showToast(TextWithEntities &&text); void showCriticalError(const TextWithEntities &text); [[nodiscard]] std::shared_ptr uiShow(); diff --git a/Telegram/SourceFiles/settings/settings_calls.cpp b/Telegram/SourceFiles/settings/settings_calls.cpp index b1bb38c264..55916a97bb 100644 --- a/Telegram/SourceFiles/settings/settings_calls.cpp +++ b/Telegram/SourceFiles/settings/settings_calls.cpp @@ -223,10 +223,7 @@ void Calls::setupContent() { if (!GetVideoInputList().empty()) { AddSkip(content); AddSubsectionTitle(content, tr::lng_settings_call_camera()); - AddCameraSubsection( - std::make_shared(_controller), - content, - true); + AddCameraSubsection(_controller->uiShow(), content, true); AddSkip(content); AddDivider(content); } diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 1156bdb509..188d701408 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -807,8 +807,9 @@ void SetupStickersEmoji( st::settingsButton, { &st::settingsIconStickers, kIconLightOrange } )->addClickHandler([=] { - controller->show( - Box(controller, StickersBox::Section::Installed)); + controller->show(Box( + controller->uiShow(), + StickersBox::Section::Installed)); }); AddButton( @@ -991,8 +992,8 @@ void SetupMessages( Core::App().saveSettingsDelayed(); }); - buttonRight->setClickedCallback([=, show = Window::Show(controller)] { - show.showBox(Box(ReactionsSettingsBox, controller)); + buttonRight->setClickedCallback([=, show = controller->uiShow()] { + show->showBox(Box(ReactionsSettingsBox, controller)); }); AddSkip(inner, st::settingsSendTypeSkip); diff --git a/Telegram/SourceFiles/settings/settings_global_ttl.cpp b/Telegram/SourceFiles/settings/settings_global_ttl.cpp index 435bc00f3d..cba6a2c00d 100644 --- a/Telegram/SourceFiles/settings/settings_global_ttl.cpp +++ b/Telegram/SourceFiles/settings/settings_global_ttl.cpp @@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/painter.h" #include "ui/text/format_values.h" #include "ui/text/text_utilities.h" -#include "ui/toasts/common_toasts.h" #include "ui/widgets/buttons.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/labels.h" @@ -119,10 +118,8 @@ void TTLChatsBoxController::prepareViewHook() { void TTLChatsBoxController::rowClicked(not_null row) { if (!TTLMenu::TTLValidator(nullptr, row->peer()).can()) { - Ui::ShowMultilineToast({ - .parentOverride = delegate()->peerListToastParent(), - .text = { tr::lng_settings_ttl_select_chats_sorry(tr::now) }, - }); + delegate()->peerListUiShow()->showToast( + { tr::lng_settings_ttl_select_chats_sorry(tr::now) }); return; } delegate()->peerListSetRowChecked(row, !row->checked()); @@ -208,7 +205,7 @@ private: const not_null _controller; const std::shared_ptr _group; - const std::shared_ptr _show; + const std::shared_ptr _show; not_null _buttons; @@ -223,7 +220,7 @@ GlobalTTL::GlobalTTL( : Section(parent) , _controller(controller) , _group(std::make_shared(0)) -, _show(std::make_shared(controller)) +, _show(controller->uiShow()) , _buttons(Ui::CreateChild(this)) { setupContent(); } @@ -244,14 +241,11 @@ void GlobalTTL::showSure(TimeId ttl, bool rebuild) const { } _group->setChangedCallback([=](int value) { _group->setChangedCallback(nullptr); - Ui::ShowMultilineToast({ - .parentOverride = _show->toastParent(), - .text = tr::lng_settings_ttl_after_toast( - tr::now, - lt_after_duration, - { .text = ttlText }, - Ui::Text::WithEntities) - }); + _show->showToast(tr::lng_settings_ttl_after_toast( + tr::now, + lt_after_duration, + { .text = ttlText }, + Ui::Text::WithEntities)); _show->hideLayer(); // Don't use close(). }); request(ttl); @@ -348,7 +342,7 @@ void GlobalTTL::setupContent() { ) | rpl::start_with_next(rebuild, content->lifetime()); } - const auto show = std::make_shared(_controller); + const auto show = _controller->uiShow(); AddButton( content, tr::lng_settings_ttl_after_custom(), @@ -398,29 +392,25 @@ void GlobalTTL::setupContent() { peer->session().api().applyUpdates(result); }).send(); } - Ui::ShowMultilineToast({ - .parentOverride = Ui::BoxShow(box).toastParent(), - .text = ttl - ? tr::lng_settings_ttl_select_chats_toast( - tr::now, - lt_count, - peers.size(), - lt_duration, - { .text = Ui::FormatTTL(ttl) }, - Ui::Text::WithEntities) - : tr::lng_settings_ttl_select_chats_disabled_toast( - tr::now, - lt_count, - peers.size(), - Ui::Text::WithEntities), - }); + box->showToast(ttl + ? tr::lng_settings_ttl_select_chats_toast( + tr::now, + lt_count, + peers.size(), + lt_duration, + { .text = Ui::FormatTTL(ttl) }, + Ui::Text::WithEntities) + : tr::lng_settings_ttl_select_chats_disabled_toast( + tr::now, + lt_count, + peers.size(), + Ui::Text::WithEntities)); box->closeBox(); })); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; _controller->show( - Box(std::move(controller), std::move(initBox)), - Ui::LayerOption::KeepOther); + Box(std::move(controller), std::move(initBox))); })); content->add(object_ptr( content, diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index 7b46bb1118..488676af23 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -213,9 +213,7 @@ void Cover::initViewers() { } else { QGuiApplication::clipboard()->setText( _user->session().createInternalLinkFull(username)); - Ui::Toast::Show( - Window::Show(_controller).toastParent(), - tr::lng_username_copied(tr::now)); + _controller->showToast(tr::lng_username_copied(tr::now)); } }); } diff --git a/Telegram/SourceFiles/settings/settings_power_saving.cpp b/Telegram/SourceFiles/settings/settings_power_saving.cpp index 21974c9a09..15b83b18da 100644 --- a/Telegram/SourceFiles/settings/settings_power_saving.cpp +++ b/Telegram/SourceFiles/settings/settings_power_saving.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "settings/settings_common.h" #include "ui/layers/generic_box.h" -#include "ui/toasts/common_toasts.h" #include "ui/widgets/buttons.h" #include "ui/power_saving.h" #include "styles/style_menu_icons.h" @@ -84,13 +83,13 @@ void PowerSavingBox(not_null box) { : rpl::single(QString()); }) | rpl::flatten_latest(); - const auto disabler = Ui::CreateChild(container.get()); + const auto show = box->uiShow(); + const auto disabler = Ui::CreateChild( + container.get()); disabler->setClickedCallback([=] { - Ui::ShowMultilineToast({ - .parentOverride = container, - .text = { tr::lng_settings_power_turn_off(tr::now) }, - .duration = kForceDisableTooltipDuration, - }); + show->showToast( + tr::lng_settings_power_turn_off(tr::now), + kForceDisableTooltipDuration); }); disabler->paintRequest() | rpl::start_with_next([=](QRect clip) { auto color = st::boxBg->c; diff --git a/Telegram/SourceFiles/settings/settings_premium.cpp b/Telegram/SourceFiles/settings/settings_premium.cpp index 78c324fe63..2c3f2eecf5 100644 --- a/Telegram/SourceFiles/settings/settings_premium.cpp +++ b/Telegram/SourceFiles/settings/settings_premium.cpp @@ -860,12 +860,10 @@ void TopBarUser::updateTitle( auto link = std::make_shared([=, stickerSetIdentifier = stickerInfo->set] { setPaused(true); - const auto box = controller->show( - Box( - controller, - stickerSetIdentifier, - Data::StickersType::Emoji), - Ui::LayerOption::KeepOther); + const auto box = controller->show(Box( + controller->uiShow(), + stickerSetIdentifier, + Data::StickersType::Emoji)); box->boxClosing( ) | rpl::start_with_next(crl::guard(this, [=] { diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index f28b44e96e..665c44ed44 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -418,8 +418,7 @@ void BlockedBoxController::BlockNewPeer( box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); }; window->show( - Box(std::move(controller), std::move(initBox)), - Ui::LayerOption::KeepOther); + Box(std::move(controller), std::move(initBox))); } bool BlockedBoxController::appendRow(not_null peer) { diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index 42b2980fff..d9fff12323 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -193,14 +193,14 @@ void AddPremiumPrivacyButton( tr::lng_settings_privacy_premium_link(tr::now)); link.entities.push_back( EntityInText(EntityType::Semibold, 0, link.text.size())); - const auto config = Ui::Toast::Config{ + (*toast) = controller->showToast({ .text = tr::lng_settings_privacy_premium( tr::now, lt_link, link, Ui::Text::WithEntities), .st = &st::defaultMultilineToast, - .durationMs = Ui::Toast::kDefaultDuration * 2, + .duration = Ui::Toast::kDefaultDuration * 2, .multiline = true, .filter = crl::guard(&controller->session(), [=]( const ClickHandlerPtr &, @@ -215,10 +215,7 @@ void AddPremiumPrivacyButton( } return false; }), - }; - (*toast) = Ui::Toast::Show( - Window::Show(controller).toastParent(), - config); + }); }; button->addClickHandler([=] { if (!session->premium()) { @@ -232,9 +229,10 @@ void AddPremiumPrivacyButton( ) | rpl::take( 1 ) | rpl::start_with_next([=](const Privacy::Rule &value) { - controller->show( - Box(controller, controllerFactory(), value), - Ui::LayerOption::KeepOther); + controller->show(Box( + controller, + controllerFactory(), + value)); }); }); } @@ -833,9 +831,10 @@ void AddPrivacyButton( ) | rpl::take( 1 ) | rpl::start_with_next([=](const Privacy::Rule &value) { - controller->show( - Box(controller, controllerFactory(), value), - Ui::LayerOption::KeepOther); + controller->show(Box( + controller, + controllerFactory(), + value)); }); }); } diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index 274b543edd..642f138c2e 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -88,10 +88,7 @@ EditInfoBox::EditInfoBox( Core::App().settings().replaceEmojiValue()); _field->setMarkdownReplacesEnabled(rpl::single(true)); _field->setEditLinkCallback( - DefaultEditLinkCallback( - std::make_shared(controller), - &controller->session(), - _field)); + DefaultEditLinkCallback(controller->uiShow(), _field)); } void EditInfoBox::prepare() { @@ -495,9 +492,7 @@ void Helper::showEditInfoBox( TextUtilities::ConvertTextTagsToEntities(result.tags) }, done); }; - controller->show( - Box(controller, editData, save), - Ui::LayerOption::KeepOther); + controller->show(Box(controller, editData, save)); } void Helper::saveInfo( diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index d77b84f3ec..c00a2b2780 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -1045,8 +1045,8 @@ void Panel::showBox(object_ptr box) { anim::type::normal); } -void Panel::showToast(const TextWithEntities &text) { - _widget->showToast(text); +void Panel::showToast(TextWithEntities &&text) { + _widget->showToast(std::move(text)); } void Panel::showCriticalError(const TextWithEntities &text) { diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h index a3f48b2d2d..c2898afc20 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h @@ -66,7 +66,7 @@ public: rpl::producer bottomText); void showBox(object_ptr box); - void showToast(const TextWithEntities &text); + void showToast(TextWithEntities &&text); void showCriticalError(const TextWithEntities &text); void showWebviewError( const QString &text, diff --git a/Telegram/SourceFiles/ui/chat/choose_send_as.cpp b/Telegram/SourceFiles/ui/chat/choose_send_as.cpp index c3be83c2f1..fc24f1aab8 100644 --- a/Telegram/SourceFiles/ui/chat/choose_send_as.cpp +++ b/Telegram/SourceFiles/ui/chat/choose_send_as.cpp @@ -176,14 +176,14 @@ void ShowPremiumPromoToast(not_null controller) { tr::lng_send_as_premium_required_link(tr::now)); link.entities.push_back( EntityInText(EntityType::Semibold, 0, link.text.size())); - const auto config = Ui::Toast::Config{ + (*toast) = controller->showToast({ .text = tr::lng_send_as_premium_required( tr::now, lt_link, link, Ui::Text::WithEntities), .st = &st::defaultMultilineToast, - .durationMs = Ui::Toast::kDefaultDuration * 2, + .duration = Ui::Toast::kDefaultDuration * 2, .multiline = true, .filter = crl::guard(&controller->session(), [=]( const ClickHandlerPtr &, @@ -198,10 +198,7 @@ void ShowPremiumPromoToast(not_null controller) { } return false; }), - }; - (*toast) = Ui::Toast::Show( - Window::Show(controller).toastParent(), - config); + }); } } // namespace diff --git a/Telegram/SourceFiles/ui/controls/userpic_button.cpp b/Telegram/SourceFiles/ui/controls/userpic_button.cpp index c4439d25e4..df5f98e04d 100644 --- a/Telegram/SourceFiles/ui/controls/userpic_button.cpp +++ b/Telegram/SourceFiles/ui/controls/userpic_button.cpp @@ -63,7 +63,7 @@ void CameraBox( using namespace Webrtc; const auto track = Settings::Calls::AddCameraSubsection( - std::make_shared(box), + box->uiShow(), box->verticalLayout(), false); if (!track) { diff --git a/Telegram/SourceFiles/ui/countryinput.cpp b/Telegram/SourceFiles/ui/countryinput.cpp index c140f79475..0021591009 100644 --- a/Telegram/SourceFiles/ui/countryinput.cpp +++ b/Telegram/SourceFiles/ui/countryinput.cpp @@ -22,7 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL CountryInput::CountryInput( QWidget *parent, - std::shared_ptr show, + std::shared_ptr show, const style::InputField &st) : RpWidget(parent) , _show(show) diff --git a/Telegram/SourceFiles/ui/countryinput.h b/Telegram/SourceFiles/ui/countryinput.h index 986b741a54..7bf3f97966 100644 --- a/Telegram/SourceFiles/ui/countryinput.h +++ b/Telegram/SourceFiles/ui/countryinput.h @@ -17,16 +17,15 @@ namespace Countries { struct Info; } // namespace Countries -namespace Window { +namespace Ui { class Show; -} // namespace Window +} // namespace Ui class CountryInput : public Ui::RpWidget { - public: CountryInput( QWidget *parent, - std::shared_ptr show, + std::shared_ptr show, const style::InputField &st); [[nodiscard]] QString iso() const { @@ -49,7 +48,7 @@ private: void chooseCountry(not_null info, int codeIndex); void setText(const QString &newText); - const std::shared_ptr _show; + const std::shared_ptr _show; const style::InputField &_st; bool _active = false; QString _text; diff --git a/Telegram/SourceFiles/window/section_widget.cpp b/Telegram/SourceFiles/window/section_widget.cpp index 1ad731fc4b..bdc5fc849a 100644 --- a/Telegram/SourceFiles/window/section_widget.cpp +++ b/Telegram/SourceFiles/window/section_widget.cpp @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "ui/ui_utility.h" #include "ui/chat/chat_theme.h" -#include "ui/toasts/common_toasts.h" #include "ui/painter.h" #include "boxes/premium_preview_box.h" #include "data/data_peer.h" diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index d1c648fc0d..b045fb2deb 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -892,12 +892,11 @@ void SaveThemeBox( } else if (error == u"THEME_SLUG_INVALID"_q) { type = SaveErrorType::Link; } else if (error == u"THEME_SLUG_OCCUPIED"_q) { - Ui::Toast::Show( - Ui::BoxShow(box).toastParent(), + box->showToast( tr::lng_create_channel_link_occupied(tr::now)); type = SaveErrorType::Link; } else if (!error.isEmpty()) { - Ui::Toast::Show(Ui::BoxShow(box).toastParent(), error); + box->showToast(error); } if (type == SaveErrorType::Name) { name->showError(); diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index 25e62283fe..ca6f48b3df 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -39,6 +39,61 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include namespace Window { +namespace { + +class Show final : public Ui::Show { +public: + explicit Show(not_null window); + + void showBox( + object_ptr content, + Ui::LayerOptions options + = Ui::LayerOption::KeepOther) const override; + void hideLayer() const override; + [[nodiscard]] not_null toastParent() const override; + [[nodiscard]] bool valid() const override; + operator bool() const override; + +private: + const base::weak_ptr _window; + +}; + +Show::Show(not_null window) +: _window(base::make_weak(window)) { +} + +void Show::showBox( + object_ptr content, + Ui::LayerOptions options) const { + if (const auto window = _window.get()) { + window->show(std::move(content), options); + } +} + +void Show::hideLayer() const { + if (const auto window = _window.get()) { + window->show( + object_ptr{ nullptr }, + Ui::LayerOption::CloseOther); + } +} + +not_null Show::toastParent() const { + const auto window = _window.get(); + Assert(window != nullptr); + return window->widget()->bodyWidget(); +} + +bool Show::valid() const { + return !_window.empty(); +} + +Show::operator bool() const { + return valid(); +} + +} // namespace Controller::Controller() : Controller(CreateArgs{}) { } @@ -220,13 +275,11 @@ void Controller::checkLockByTerms() { } void Controller::showTermsDecline() { - const auto box = show( - Box( - TextWithEntities{ tr::lng_terms_update_sorry(tr::now) }, - tr::lng_terms_decline_and_delete(), - tr::lng_terms_back(), - true), - Ui::LayerOption::KeepOther); + const auto box = show(Box( + TextWithEntities{ tr::lng_terms_update_sorry(tr::now) }, + tr::lng_terms_decline_and_delete(), + tr::lng_terms_back(), + true)); box->agreeClicks( ) | rpl::start_with_next([=] { @@ -252,14 +305,12 @@ void Controller::showTermsDelete() { hideLayer(); } }; - show( - Ui::MakeConfirmBox({ - .text = tr::lng_terms_delete_warning(), - .confirmed = deleteByTerms, - .confirmText = tr::lng_terms_delete_now(), - .confirmStyle = &st::attentionBoxButton, - }), - Ui::LayerOption::KeepOther); + show(Ui::MakeConfirmBox({ + .text = tr::lng_terms_delete_warning(), + .confirmed = deleteByTerms, + .confirmText = tr::lng_terms_delete_now(), + .confirmStyle = &st::attentionBoxButton, + })); } void Controller::finishFirstShow() { @@ -341,8 +392,16 @@ int Controller::verticalShadowTop() const { : 0; } -void Controller::showToast(const QString &text) { - Ui::Toast::Show(_widget.bodyWidget(), text); +void Controller::showToast(Ui::Toast::Config &&config) { + Show(this).showToast(std::move(config)); +} + +void Controller::showToast(TextWithEntities &&text, crl::time duration) { + Show(this).showToast(std::move(text), duration); +} + +void Controller::showToast(const QString &text, crl::time duration) { + Show(this).showToast(text, duration); } void Controller::showLayer( @@ -515,6 +574,10 @@ auto Controller::floatPlayerDelegateValue() const return _floatPlayerDelegate.value(); } +std::shared_ptr Controller::uiShow() { + return std::make_shared(this); +} + rpl::lifetime &Controller::lifetime() { return _lifetime; } diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index b106a4d51f..62abd54bb3 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -16,6 +16,14 @@ class Account; class Session; } // namespace Main +namespace Ui { +class Show; +} // namespace Ui + +namespace Ui::Toast { +struct Config; +} // namespace Ui::Toast + namespace Media::View { struct OpenRequest; } // namespace Media::View @@ -87,7 +95,11 @@ public: showBox(std::move(content), options, animated); return result; } - void showToast(const QString &text); + + void showToast(Ui::Toast::Config &&config); + void showToast(TextWithEntities &&text, crl::time duration = 0); + void showToast(const QString &text, crl::time duration = 0); + void showLayer( std::unique_ptr &&layer, Ui::LayerOptions options, @@ -131,6 +143,8 @@ public: [[nodiscard]] auto floatPlayerDelegateValue() const -> rpl::producer; + [[nodiscard]] std::shared_ptr uiShow(); + [[nodiscard]] rpl::lifetime &lifetime(); private: diff --git a/Telegram/SourceFiles/window/window_lock_widgets.cpp b/Telegram/SourceFiles/window/window_lock_widgets.cpp index a68a25025a..c0b02c9c39 100644 --- a/Telegram/SourceFiles/window/window_lock_widgets.cpp +++ b/Telegram/SourceFiles/window/window_lock_widgets.cpp @@ -243,7 +243,7 @@ void TermsBox::prepare() { st::termsPadding), 0, age ? age->height() : 0); - const auto toastParent = Ui::BoxShow(this).toastParent(); + const auto show = uiShow(); content->entity()->setClickHandlerFilter([=]( const ClickHandlerPtr &handler, Qt::MouseButton button) { @@ -252,8 +252,7 @@ void TermsBox::prepare() { : QString(); if (TextUtilities::RegExpMention().match(link).hasMatch()) { _lastClickedMention = link; - Ui::Toast::Show( - toastParent, + show->showToast( tr::lng_terms_agree_to_proceed(tr::now, lt_bot, link)); return false; } diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 2feff047b9..305b883299 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -157,7 +157,7 @@ void ShowCallsBox(not_null window) { Window::SectionShow(anim::type::instant)); }; const auto clearAll = crl::guard(box, [=] { - Ui::BoxShow(box).showBox(Box(Calls::ClearCallsBox, window)); + box->uiShow()->showBox(Box(Calls::ClearCallsBox, window)); }); state->menu->addAction( tr::lng_settings_section_call_settings(tr::now), diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 6b3f84e81d..77055b6bf9 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "menu/menu_check_item.h" #include "boxes/share_box.h" +#include "chat_helpers/compose/compose_show.h" #include "chat_helpers/message_field.h" #include "ui/wrap/slide_wrap.h" #include "ui/widgets/input_fields.h" @@ -40,7 +41,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/widgets/menu/menu_add_action_callback_factory.h" #include "ui/layers/generic_box.h" -#include "ui/toasts/common_toasts.h" #include "ui/delayed_activation.h" #include "main/main_session.h" #include "main/main_session_settings.h" @@ -197,7 +197,7 @@ void PeerMenuAddMuteSubmenuAction( notifySettings->update(thread, { .unmute = true }); }), &st::menuIconUnmute); } else { - const auto show = std::make_shared(controller); + const auto show = controller->uiShow(); addAction(PeerMenuCallback::Args{ .text = tr::lng_context_mute(tr::now), .handler = nullptr, @@ -212,23 +212,19 @@ void PeerMenuAddMuteSubmenuAction( } void ForwardToSelf( - not_null navigation, + std::shared_ptr show, const Data::ForwardDraft &draft) { - const auto content = navigation->parentController()->content(); - const auto session = &navigation->session(); + const auto session = &show->session(); const auto history = session->data().history(session->user()); auto resolved = history->resolveForwardDraft(draft); if (!resolved.items.empty()) { auto action = Api::SendAction(history); action.clearDraft = false; action.generateLocal = false; - const auto weakContent = Ui::MakeWeak(content); session->api().forwardMessages( std::move(resolved), action, - crl::guard(weakContent, [w = weakContent] { - Ui::Toast::Show(w, tr::lng_share_done(tr::now)); - })); + [=] { show->showToast(tr::lng_share_done(tr::now)); }); } } @@ -414,9 +410,7 @@ void TogglePinnedThread( (&owner->session())->data().chatsFilters().list(), filterId, &Data::ChatFilter::id)) { - Ui::Toast::Show( - Window::Show(controller).toastParent(), - tr::lng_cant_do_this(tr::now)); + controller->showToast(tr::lng_cant_do_this(tr::now)); return; } @@ -777,9 +771,7 @@ void Filler::addViewDiscussion() { const auto navigation = _controller; _addAction(tr::lng_profile_view_discussion(tr::now), [=] { if (channel->invitePeekExpires()) { - Ui::Toast::Show( - Window::Show(navigation).toastParent(), - tr::lng_channel_invite_private(tr::now)); + navigation->showToast(tr::lng_channel_invite_private(tr::now)); return; } navigation->showPeerHistory( @@ -955,11 +947,9 @@ void Filler::addTopicLink() { const auto query = base + '/' + QString::number(id.bare); const auto link = channel->session().createInternalLinkFull(query); QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show( - Window::Show(controller).toastParent(), - (channel->hasUsername() - ? tr::lng_channel_public_link_copied(tr::now) - : tr::lng_context_about_private_link(tr::now))); + controller->showToast(channel->hasUsername() + ? tr::lng_channel_public_link_copied(tr::now) + : tr::lng_context_about_private_link(tr::now)); }, &st::menuIconCopy); } @@ -1048,7 +1038,7 @@ void Filler::addTTLSubmenu(bool addSeparator) { return; // #TODO later forum } const auto validator = TTLMenu::TTLValidator( - std::make_shared(_controller), + _controller->uiShow(), _peer); if (!validator.can()) { return; @@ -1170,7 +1160,6 @@ void Filler::addVideoChat() { FillVideoChatMenu(_controller, _request, _addAction); return; } - const auto show = std::make_shared(_controller); _addAction(PeerMenuCallback::Args{ .text = tr::lng_menu_start_group_call_options(tr::now), .handler = nullptr, @@ -1276,14 +1265,11 @@ void Filler::fillArchiveActions() { }, hidden ? &st::menuIconExpand : &st::menuIconCollapse); _addAction(tr::lng_context_archive_to_menu(tr::now), [=] { - Ui::Toast::Show( - Window::Show(controller).toastParent(), - Ui::Toast::Config{ - .text = { tr::lng_context_archive_to_menu_info(tr::now) }, - .st = &st::windowArchiveToast, - .durationMs = kArchivedToastDuration, - .multiline = true, - }); + controller->showToast({ + .text = { tr::lng_context_archive_to_menu_info(tr::now) }, + .st = &st::windowArchiveToast, + .duration = kArchivedToastDuration, + }); controller->session().settings().setArchiveInMainMenu( !controller->session().settings().archiveInMainMenu()); @@ -1378,16 +1364,13 @@ void PeerMenuShareContactBox( const auto peer = thread->peer(); if (!Data::CanSend(thread, ChatRestriction::SendOther)) { navigation->parentController()->show( - Ui::MakeInformBox(tr::lng_forward_share_cant()), - Ui::LayerOption::KeepOther); + Ui::MakeInformBox(tr::lng_forward_share_cant())); return; } else if (peer->isSelf()) { auto action = Api::SendAction(thread); action.clearDraft = false; user->session().api().shareContact(user, action); - Ui::Toast::Show( - Window::Show(navigation).toastParent(), - tr::lng_share_done(tr::now)); + navigation->showToast(tr::lng_share_done(tr::now)); if (auto strong = *weak) { strong->closeBox(); } @@ -1419,8 +1402,7 @@ void PeerMenuShareContactBox( close(); }, .confirmText = tr::lng_forward_send(), - }), - Ui::LayerOption::KeepOther); + })); }; *weak = navigation->parentController()->show( Box( @@ -1431,8 +1413,7 @@ void PeerMenuShareContactBox( box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); - }), - Ui::LayerOption::CloseOther); + })); } void PeerMenuCreatePoll( @@ -1585,8 +1566,7 @@ void PeerMenuBlockUserBox( } } - Ui::Toast::Show( - Window::Show(window).toastParent(), + window->showToast( tr::lng_new_contact_block_done(tr::now, lt_user, name)); }, st::attentionBoxButton); @@ -1650,15 +1630,16 @@ QPointer ShowChooseRecipientBox( std::make_unique( &navigation->session(), std::move(callback)), - std::move(initBox)), Ui::LayerOption::KeepOther); + std::move(initBox))); return weak->data(); } QPointer ShowForwardMessagesBox( - not_null navigation, + std::shared_ptr show, Data::ForwardDraft &&draft, Fn &&successCallback) { - const auto owner = &navigation->session().data(); + const auto session = &show->session(); + const auto owner = &session->data(); const auto msgIds = owner->itemsToIds(owner->idsToItems(draft.ids)); if (msgIds.empty()) { return nullptr; @@ -1753,7 +1734,6 @@ QPointer ShowForwardMessagesBox( }; - const auto session = &navigation->session(); struct State { not_null box; not_null controller; @@ -1764,24 +1744,37 @@ QPointer ShowForwardMessagesBox( const auto controllerRaw = controller.get(); auto box = Box(std::move(controller), nullptr); const auto boxRaw = box.data(); - navigation->parentController()->show( - std::move(box), - Ui::LayerOption::KeepOther); + show->showBox(std::move(box)); auto state = State{ boxRaw, controllerRaw }; return boxRaw->lifetime().make_state(std::move(state)); }(); { // Chosen a single. - auto chosen = [navigation, draft = std::move(draft)]( + auto chosen = [show, draft = std::move(draft)]( not_null thread) mutable { - const auto content = navigation->parentController()->content(); const auto peer = thread->peer(); if (peer->isSelf() && !draft.ids.empty() && draft.ids.front().peer != peer->id) { - ForwardToSelf(navigation, draft); + ForwardToSelf(show, draft); return true; } + auto controller = Core::App().windowFor(peer); + if (!controller) { + return false; + } + if (controller->maybeSession() != &peer->session()) { + controller = peer->isForum() + ? Core::App().ensureSeparateWindowForAccount( + &peer->account()) + : Core::App().ensureSeparateWindowForPeer( + peer, + ShowAtUnreadMsgId); + if (controller->maybeSession() != &peer->session()) { + return false; + } + } + const auto content = controller->sessionController()->content(); return content->setForwardDraft(thread, std::move(draft)); }; auto callback = [=, chosen = std::move(chosen)]( @@ -1810,7 +1803,7 @@ QPointer ShowForwardMessagesBox( st::shareCommentPadding); const auto send = ShareBox::DefaultForwardCallback( - std::make_shared(navigation), + show, session->data().message(msgIds.front())->history(), msgIds); @@ -1913,10 +1906,11 @@ QPointer ShowForwardMessagesBox( QObject::connect(field, &Ui::InputField::submitted, [=] { submit({}); }); - const auto show = std::make_shared(state->box); - if (show->valid()) { - InitMessageFieldHandlers(session, show, field, nullptr); - } + InitMessageFieldHandlers( + session, + show, + field, + [=] { return show->paused(GifPauseReason::Layer); }); field->setSubmitSettings(Core::App().settings().sendSubmitWay()); Ui::SendPendingMoveResizeEvents(comment); @@ -1951,6 +1945,16 @@ QPointer ShowForwardMessagesBox( return QPointer(state->box); } +QPointer ShowForwardMessagesBox( + not_null navigation, + Data::ForwardDraft &&draft, + Fn &&successCallback) { + return ShowForwardMessagesBox( + navigation->uiShow(), + std::move(draft), + std::move(successCallback)); +} + QPointer ShowForwardMessagesBox( not_null navigation, MessageIdsList &&items, @@ -1994,8 +1998,7 @@ QPointer ShowShareGameBox( Ui::MakeConfirmBox({ .text = confirmText, .confirmed = std::move(send), - }), - Ui::LayerOption::KeepOther); + })); }; auto filter = [](not_null thread) { return !thread->peer()->isSelf() @@ -2012,7 +2015,7 @@ QPointer ShowShareGameBox( &navigation->session(), std::move(chosen), std::move(filter)), - std::move(initBox)), Ui::LayerOption::KeepOther); + std::move(initBox))); return weak->data(); } @@ -2071,10 +2074,7 @@ QPointer ShowSendNowMessagesBox( history->peer, { .forward = &list }); if (!error.isEmpty()) { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(navigation).toastParent(), - .text = { error }, - }); + navigation->showToast(error); return { nullptr }; } auto done = [ @@ -2102,13 +2102,11 @@ QPointer ShowSendNowMessagesBox( callback(); } }; - return navigation->parentController()->show( - Ui::MakeConfirmBox({ - .text = text, - .confirmed = std::move(done), - .confirmText = tr::lng_send_button(), - }), - Ui::LayerOption::KeepOther).data(); + return navigation->parentController()->show(Ui::MakeConfirmBox({ + .text = text, + .confirmed = std::move(done), + .confirmText = tr::lng_send_button(), + })).data(); } void PeerMenuAddChannelMembers( @@ -2117,9 +2115,7 @@ void PeerMenuAddChannelMembers( if (!channel->isMegagroup() && (channel->membersCount() >= channel->session().serverConfig().chatSizeMax)) { - navigation->parentController()->show( - Box(channel), - Ui::LayerOption::KeepOther); + navigation->parentController()->show(Box(channel)); return; } const auto api = &channel->session().api(); @@ -2325,7 +2321,7 @@ void ToggleHistoryArchived(not_null history, bool archived) { ? tr::lng_archived_added(tr::now) : tr::lng_archived_removed(tr::now)) }, .st = &st::windowArchiveToast, - .durationMs = (archived + .duration = (archived ? kArchivedToastDuration : Ui::Toast::kDefaultDuration), .multiline = true, @@ -2341,9 +2337,7 @@ Fn ClearHistoryHandler( not_null controller, not_null peer) { return [=] { - controller->show( - Box(peer, true), - Ui::LayerOption::KeepOther); + controller->show(Box(peer, true)); }; } @@ -2351,9 +2345,7 @@ Fn DeleteAndLeaveHandler( not_null controller, not_null peer) { return [=] { - controller->show( - Box(peer, false), - Ui::LayerOption::KeepOther); + controller->show(Box(peer, false)); }; } @@ -2377,9 +2369,7 @@ bool FillVideoChatMenu( controller->startOrJoinGroupCall(peer, std::move(args)); }; const auto rtmpCallback = [=] { - Core::App().calls().showStartWithRtmp( - std::make_shared(controller), - peer); + Core::App().calls().showStartWithRtmp(controller->uiShow(), peer); }; const auto livestream = !peer->isMegagroup() && peer->isChannel(); const auto has = (peer->groupCall() != nullptr); diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index d224197d1e..44e3bd90f6 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -34,6 +34,10 @@ class MainList; struct EntryState; } // namespace Dialogs +namespace ChatHelpers { +class Show; +} // namespace ChatHelpers + namespace Window { class Controller; @@ -119,6 +123,10 @@ QPointer ShowChooseRecipientBox( FnMut)> &&chosen, rpl::producer titleOverride = nullptr, FnMut &&successCallback = nullptr); +QPointer ShowForwardMessagesBox( + std::shared_ptr show, + Data::ForwardDraft &&draft, + Fn &&successCallback = nullptr); QPointer ShowForwardMessagesBox( not_null navigation, Data::ForwardDraft &&draft, diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index add465f590..d40800ef74 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document_resolver.h" #include "data/data_media_types.h" #include "data/data_session.h" +#include "data/data_file_origin.h" #include "data/data_folder.h" #include "data/data_channel.h" #include "data/data_chat.h" @@ -64,7 +65,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/message_sending_animation_controller.h" #include "ui/style/style_palette_colorizer.h" #include "ui/toast/toast.h" -#include "ui/toasts/common_toasts.h" #include "calls/calls_instance.h" // Core::App().calls().inCall(). #include "calls/group/calls_group_call.h" #include "ui/boxes/calendar_box.h" @@ -109,6 +109,137 @@ constexpr auto kMaxChatEntryHistorySize = 50; }; } +class MainWindowShow final : public ChatHelpers::Show { +public: + explicit MainWindowShow(not_null navigation); + + void showBox( + object_ptr content, + Ui::LayerOptions options + = Ui::LayerOption::KeepOther) const override; + void hideLayer() const override; + not_null toastParent() const override; + bool valid() const override; + operator bool() const override; + + Main::Session &session() const override; + bool paused(ChatHelpers::PauseReason reason) const override; + rpl::producer<> pauseChanged() const override; + + rpl::producer adjustShadowLeft() const override; + SendMenu::Type sendMenuType() const override; + + bool showMediaPreview( + Data::FileOrigin origin, + not_null document) const override; + bool showMediaPreview( + Data::FileOrigin origin, + not_null photo) const override; + + void processChosenSticker( + ChatHelpers::FileChosen chosen) const override; + +private: + const base::weak_ptr _window; + +}; + +MainWindowShow::MainWindowShow( + not_null navigation) +: _window(base::make_weak(navigation->parentController())) { +} + +void MainWindowShow::showBox( + object_ptr content, + Ui::LayerOptions options) const { + if (const auto window = _window.get()) { + window->show(std::move(content), options); + } +} + +void MainWindowShow::hideLayer() const { + if (const auto window = _window.get()) { + window->show( + object_ptr{ nullptr }, + Ui::LayerOption::CloseOther); + } +} + +not_null MainWindowShow::toastParent() const { + const auto window = _window.get(); + Assert(window != nullptr); + return window->widget()->bodyWidget(); +} + +bool MainWindowShow::valid() const { + return !_window.empty(); +} + +MainWindowShow::operator bool() const { + return valid(); +} + +Main::Session &MainWindowShow::session() const { + const auto window = _window.get(); + Assert(window != nullptr); + return window->session(); +} + +bool MainWindowShow::paused(ChatHelpers::PauseReason reason) const { + const auto window = _window.get(); + return window && window->isGifPausedAtLeastFor(reason); +} + +rpl::producer<> MainWindowShow::pauseChanged() const { + const auto window = _window.get(); + if (!window) { + return rpl::never<>(); + } + return window->gifPauseLevelChanged(); +} + +rpl::producer MainWindowShow::adjustShadowLeft() const { + const auto window = _window.get(); + if (!window) { + return rpl::single(false); + } + return window->adaptive().value( + ) | rpl::map([=] { + return !window->adaptive().isOneColumn(); + }); +} + +SendMenu::Type MainWindowShow::sendMenuType() const { + const auto window = _window.get(); + if (!window) { + return SendMenu::Type::Disabled; + } + return window->content()->sendMenuType(); +} + +bool MainWindowShow::showMediaPreview( + Data::FileOrigin origin, + not_null document) const { + const auto window = _window.get(); + return window && window->widget()->showMediaPreview(origin, document); +} + +bool MainWindowShow::showMediaPreview( + Data::FileOrigin origin, + not_null photo) const { + const auto window = _window.get(); + return window && window->widget()->showMediaPreview(origin, photo); +} + +void MainWindowShow::processChosenSticker( + ChatHelpers::FileChosen chosen) const { + if (const auto window = _window.get()) { + Ui::PostponeCall(window, [=, chosen = std::move(chosen)]() mutable { + window->stickerOrEmojiChosen(std::move(chosen)); + }); + } +} + } // namespace void ActivateWindow(not_null controller) { @@ -160,8 +291,8 @@ void DateClickHandler::onClick(ClickContext context) const { } SessionNavigation::SessionNavigation(not_null session) - : _session(session) - , _api(&_session->mtp()) { +: _session(session) +, _api(&_session->mtp()) { } SessionNavigation::~SessionNavigation() = default; @@ -263,12 +394,10 @@ void SessionNavigation::resolveChannelById( done(channel); return; } - const auto fail = [=] { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(this).toastParent(), - .text = { tr::lng_error_post_link_invalid(tr::now) } - }); - }; + const auto fail = crl::guard(this, [=] { + MainWindowShow(this).showToast( + tr::lng_error_post_link_invalid(tr::now)); + }); _api.request(base::take(_resolveRequestId)).cancel(); _resolveRequestId = _api.request(MTPchannels_GetChannels( MTP_vector( @@ -464,12 +593,10 @@ void SessionNavigation::joinVoiceChatFromLink( const PeerByLinkInfo &info) { Expects(info.voicechatHash.has_value()); - const auto bad = [=] { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(this).toastParent(), - .text = { tr::lng_group_invite_bad_link(tr::now) } - }); - }; + const auto bad = crl::guard(this, [=] { + MainWindowShow(this).showToast( + tr::lng_group_invite_bad_link(tr::now)); + }); const auto hash = *info.voicechatHash; _api.request(base::take(_resolveRequestId)).cancel(); _resolveRequestId = _api.request( @@ -603,9 +730,7 @@ void SessionNavigation::showRepliesForMessage( _showingRepliesRequestId = 0; if (error.type() == u"CHANNEL_PRIVATE"_q || error.type() == u"USER_BANNED_IN_CHANNEL"_q) { - Ui::Toast::Show( - Show(this).toastParent(), - tr::lng_group_not_accessible(tr::now)); + showToast(tr::lng_group_not_accessible(tr::now)); } }).send(); } @@ -697,6 +822,27 @@ void SessionNavigation::showPollResults( showSection(std::make_shared(poll, contextId), params); } +auto SessionNavigation::showToast(Ui::Toast::Config &&config) +-> base::weak_ptr { + return MainWindowShow(this).showToast(std::move(config)); +} + +auto SessionNavigation::showToast(const QString &text, crl::time duration) +-> base::weak_ptr { + return MainWindowShow(this).showToast(text); +} + +auto SessionNavigation::showToast( + TextWithEntities &&text, + crl::time duration) +-> base::weak_ptr { + return MainWindowShow(this).showToast(std::move(text)); +} + +std::shared_ptr SessionNavigation::uiShow() { + return std::make_shared(this); +} + struct SessionController::CachedThemeKey { Ui::ChatThemeKey theme; QString paper; @@ -731,7 +877,7 @@ SessionController::SessionController( , _tabbedSelector( std::make_unique( _window->widget(), - this, + uiShow(), GifPauseReason::TabbedPanel)) , _invitePeekTimer([=] { checkInvitePeek(); }) , _activeChatsFilter(session->data().chatsFilters().defaultId()) @@ -1065,12 +1211,8 @@ void SessionController::setupPremiumToast() { session().mtp().requestConfig(); return premium; }) | rpl::start_with_next([=] { - Ui::Toast::Show( - Window::Show(this).toastParent(), - { - .text = { tr::lng_premium_success(tr::now) }, - .st = &st::defaultToast, - }); + MainWindowShow(this).showToast( + { tr::lng_premium_success(tr::now) }); }, _lifetime); } @@ -1327,14 +1469,6 @@ void SessionController::floatPlayerAreaUpdated() { } } -void SessionController::materializeLocalDrafts() { - _materializeLocalDraftsRequests.fire({}); -} - -rpl::producer<> SessionController::materializeLocalDraftsRequests() const { - return _materializeLocalDraftsRequests.events(); -} - int SessionController::dialogsSmallColumnWidth() const { return st::defaultDialogRow.padding.left() + st::defaultDialogRow.photoSize @@ -1558,14 +1692,9 @@ void SessionController::showPeer(not_null peer, MsgId msgId) { && (!currentPeer->isChannel() || currentPeer->asChannel()->linkedChat() != clickedChannel)) { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(this).toastParent(), - .text = { - .text = peer->isMegagroup() - ? tr::lng_group_not_accessible(tr::now) - : tr::lng_channel_not_accessible(tr::now) - }, - }); + MainWindowShow(this).showToast(peer->isMegagroup() + ? tr::lng_group_not_accessible(tr::now) + : tr::lng_channel_not_accessible(tr::now)); } else { showPeerHistory(peer->id, SectionShow(), msgId); } @@ -1581,10 +1710,7 @@ void SessionController::startOrJoinGroupCall(not_null peer) { void SessionController::startOrJoinGroupCall( not_null peer, Calls::StartGroupCallArgs args) { - Core::App().calls().startOrJoinGroupCall( - std::make_shared(this), - peer, - args); + Core::App().calls().startOrJoinGroupCall(uiShow(), peer, args); } void SessionController::showCalendar(Dialogs::Key chat, QDate requestedDate) { @@ -1963,21 +2089,15 @@ void SessionController::setActiveChatsFilter( } void SessionController::showAddContact() { - _window->show( - Box(&session()), - Ui::LayerOption::KeepOther); + _window->show(Box(&session())); } void SessionController::showNewGroup() { - _window->show( - Box(this, GroupInfoBox::Type::Group), - Ui::LayerOption::KeepOther); + _window->show(Box(this, GroupInfoBox::Type::Group)); } void SessionController::showNewChannel() { - _window->show( - Box(this, GroupInfoBox::Type::Channel), - Ui::LayerOption::KeepOther); + _window->show(Box(this, GroupInfoBox::Type::Channel)); } Window::Adaptive &SessionController::adaptive() const { @@ -2012,13 +2132,6 @@ void SessionController::hideLayer(anim::type animated) { _window->hideLayer(animated); } -void SessionController::showToast(TextWithEntities &&text) { - Ui::ShowMultilineToast({ - .parentOverride = Window::Show(this).toastParent(), - .text = std::move(text), - }); -} - void SessionController::openPhoto( not_null photo, FullMsgId contextId, @@ -2376,44 +2489,4 @@ SessionController::~SessionController() { resetFakeUnreadWhileOpened(); } -Show::Show(not_null navigation) -: Show(&navigation->parentController()->window()) { -} - -Show::Show(Controller *window) -: _window(base::make_weak(window)) { -} - -Show::~Show() = default; - -void Show::showBox( - object_ptr content, - Ui::LayerOptions options) const { - if (const auto window = _window.get()) { - window->show(std::move(content), options); - } -} - -void Show::hideLayer() const { - if (const auto window = _window.get()) { - window->show( - object_ptr{ nullptr }, - Ui::LayerOption::CloseOther); - } -} - -not_null Show::toastParent() const { - const auto window = _window.get(); - Assert(window != nullptr); - return window->widget()->bodyWidget(); -} - -bool Show::valid() const { - return !_window.empty(); -} - -Show::operator bool() const { - return valid(); -} - } // namespace Window diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index b06dd32c70..70b3c77165 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/weak_ptr.h" #include "base/timer.h" #include "boxes/gift_premium_box.h" // GiftPremiumValidator. +#include "chat_helpers/compose/compose_show.h" #include "data/data_chat_participant_status.h" #include "dialogs/dialogs_key.h" #include "ui/layers/layer_widget.h" @@ -80,22 +81,14 @@ class CachedIconFactory; namespace Window { +using GifPauseReason = ChatHelpers::PauseReason; +using GifPauseReasons = ChatHelpers::PauseReasons; + class MainWindow; class SectionMemento; class Controller; class FiltersMenu; -enum class GifPauseReason { - Any = 0, - InlineResults = (1 << 0), - TabbedPanel = (1 << 1), - Layer = (1 << 2), - RoundPlaying = (1 << 3), - MediaPreview = (1 << 4), -}; -using GifPauseReasons = base::flags; -inline constexpr bool is_flag_type(GifPauseReason) { return true; }; - enum class ResolveType { Default, BotApp, @@ -186,7 +179,7 @@ public: explicit SessionNavigation(not_null session); virtual ~SessionNavigation(); - Main::Session &session() const; + [[nodiscard]] Main::Session &session() const; virtual void showSection( std::shared_ptr memento, @@ -276,6 +269,17 @@ public: FullMsgId contextId, const SectionShow ¶ms = SectionShow()); + base::weak_ptr showToast( + Ui::Toast::Config &&config); + base::weak_ptr showToast( + TextWithEntities &&text, + crl::time duration = 0); + base::weak_ptr showToast( + const QString &text, + crl::time duration = 0); + + [[nodiscard]] std::shared_ptr uiShow(); + private: void resolvePhone( const QString &phone, @@ -345,8 +349,6 @@ public: anim::type animated = anim::type::normal); void hideLayer(anim::type animated = anim::type::normal); - void showToast(TextWithEntities &&text); - [[nodiscard]] auto sendingAnimation() const -> Ui::MessageSendingAnimationController &; [[nodiscard]] auto tabbedSelector() const @@ -406,9 +408,6 @@ public: bool isGifPausedAtLeastFor(GifPauseReason reason) const; void floatPlayerAreaUpdated(); - void materializeLocalDrafts(); - [[nodiscard]] rpl::producer<> materializeLocalDraftsRequests() const; - struct ColumnLayout { int bodyWidth = 0; int dialogsWidth = 0; @@ -696,8 +695,6 @@ private: QString _premiumRef; - rpl::event_stream<> _materializeLocalDraftsRequests; - rpl::lifetime _lifetime; }; @@ -711,22 +708,4 @@ void ActivateWindow(not_null controller); not_null controller, GifPauseReason level); -class Show : public Ui::Show { -public: - explicit Show(not_null navigation); - explicit Show(Controller *window); - ~Show(); - void showBox( - object_ptr content, - Ui::LayerOptions options = Ui::LayerOption::KeepOther) const override; - void hideLayer() const override; - [[nodiscard]] not_null toastParent() const override; - [[nodiscard]] bool valid() const override; - operator bool() const override; - -private: - const base::weak_ptr _window; - -}; - } // namespace Window diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 7c9aa94533..b850852221 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 7c9aa94533276d693942ed0ffb39d3d66a49e124 +Subproject commit b850852221fd27e8c70b01238638a29b50774369