From 629574685e2353a716a7495d8501a81f95fa253a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 14 Jun 2022 12:48:25 +0300 Subject: [PATCH] Fixed display of most of simple toasts in corresponding window. --- .../SourceFiles/boxes/add_contact_box.cpp | 4 ++- .../boxes/background_preview_box.cpp | 4 ++- Telegram/SourceFiles/boxes/connection_box.cpp | 5 +++- Telegram/SourceFiles/boxes/connection_box.h | 1 + .../SourceFiles/boxes/create_poll_box.cpp | 16 +++++++---- .../SourceFiles/boxes/edit_caption_box.cpp | 9 ++++-- Telegram/SourceFiles/boxes/max_invite_box.cpp | 4 ++- Telegram/SourceFiles/boxes/send_files_box.cpp | 21 +++++++++----- .../SourceFiles/boxes/sticker_set_box.cpp | 24 ++++++++++------ Telegram/SourceFiles/boxes/username_box.cpp | 4 ++- .../SourceFiles/core/click_handler_types.cpp | 11 +++++--- .../SourceFiles/core/local_url_handlers.cpp | 28 +++++++++++++------ .../SourceFiles/data/data_media_types.cpp | 15 ++++++++-- .../data/stickers/data_stickers.cpp | 1 + .../history/history_item_components.cpp | 19 ++++++++++--- .../history/history_item_components.h | 2 ++ .../view/history_view_contact_status.cpp | 24 +++++++++++----- .../history/view/history_view_element.cpp | 5 +--- .../history/view/history_view_message.cpp | 1 + .../info/profile/info_profile_actions.cpp | 7 +++-- .../SourceFiles/settings/settings_main.cpp | 4 ++- .../window/themes/window_theme_editor.cpp | 6 ++-- .../window/themes/window_theme_editor_box.cpp | 3 +- .../themes/window_themes_cloud_list.cpp | 3 +- .../window/window_lock_widgets.cpp | 5 +++- .../SourceFiles/window/window_peer_menu.cpp | 28 +++++++++++-------- .../window/window_session_controller.cpp | 4 ++- 27 files changed, 179 insertions(+), 79 deletions(-) diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 24b35d13e..b2d39c374 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -1056,7 +1056,9 @@ void SetupChannelBox::mousePressEvent(QMouseEvent *e) { return; } else if (!_channel->inviteLink().isEmpty()) { QGuiApplication::clipboard()->setText(_channel->inviteLink()); - Ui::Toast::Show(tr::lng_create_channel_link_copied(tr::now)); + Ui::Toast::Show( + Ui::BoxShow(this).toastParent(), + 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/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 1ca6faf39..d942e60d7 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -258,7 +258,9 @@ void BackgroundPreviewBox::apply() { void BackgroundPreviewBox::share() { QGuiApplication::clipboard()->setText( _paper.shareUrl(&_controller->session())); - Ui::Toast::Show(tr::lng_background_link_copied(tr::now)); + Ui::Toast::Show( + Ui::BoxShow(this).toastParent(), + tr::lng_background_link_copied(tr::now)); } void BackgroundPreviewBox::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 8dd8db93b..ab8dd8ee4 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -1264,6 +1264,7 @@ object_ptr ProxiesBoxController::CreateOwningBox( object_ptr ProxiesBoxController::create() { auto result = Box(this, _settings); + _toastParent = Ui::BoxShow(result.data()).toastParent(); for (const auto &item : _list) { updateView(item); } @@ -1549,7 +1550,9 @@ void ProxiesBoxController::share(const ProxyData &proxy) { + ((proxy.type == Type::Mtproto && !proxy.password.isEmpty()) ? "&secret=" + proxy.password : ""); QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show(tr::lng_username_copied(tr::now)); + if (_toastParent) { + Ui::Toast::Show(_toastParent, tr::lng_username_copied(tr::now)); + } } ProxiesBoxController::~ProxiesBoxController() { diff --git a/Telegram/SourceFiles/boxes/connection_box.h b/Telegram/SourceFiles/boxes/connection_box.h index 26244fe50..566a43421 100644 --- a/Telegram/SourceFiles/boxes/connection_box.h +++ b/Telegram/SourceFiles/boxes/connection_box.h @@ -117,6 +117,7 @@ private: rpl::event_stream _views; base::Timer _saveTimer; rpl::event_stream _proxySettingsChanges; + QPointer _toastParent; ProxyData _lastSelectedProxy; bool _lastSelectedProxyUsed = false; diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index d46f73a96..8c4cd47a5 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -18,7 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/labels.h" #include "ui/widgets/buttons.h" #include "ui/widgets/checkbox.h" -#include "ui/toast/toast.h" #include "ui/text/text_utilities.h" #include "main/main_session.h" #include "core/application.h" @@ -776,7 +775,7 @@ void CreatePollBox::setInnerFocus() { } void CreatePollBox::submitFailed(const QString &error) { - Ui::Toast::Show(error); + Ui::Toast::Show(Ui::BoxShow(this).toastParent(), error); } not_null CreatePollBox::setupQuestion( @@ -990,8 +989,11 @@ object_ptr CreatePollBox::setupContent() { multiple->events( ) | rpl::filter([=](not_null e) { return (e->type() == QEvent::MouseButtonPress) && quiz->checked(); - }) | rpl::start_with_next([=] { - Ui::Toast::Show(tr::lng_polls_create_one_answer(tr::now)); + }) | rpl::start_with_next([ + toastParent = Ui::BoxShow(this).toastParent()] { + Ui::Toast::Show( + toastParent, + tr::lng_polls_create_one_answer(tr::now)); }, multiple->lifetime()); } @@ -1068,8 +1070,10 @@ object_ptr CreatePollBox::setupContent() { *error &= ~Error::Solution; } }; - const auto showError = [](tr::phrase<> text) { - Ui::Toast::Show(text(tr::now)); + const auto showError = [ + toastParent = Ui::BoxShow(this).toastParent()]( + tr::phrase<> text) { + Ui::Toast::Show(toastParent, text(tr::now)); }; const auto send = [=](Api::SendOptions sendOptions) { collectError(); diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index df0fa7ab0..e59cd311c 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -324,9 +324,10 @@ void EditCaptionBox::setupControls() { } void EditCaptionBox::setupEditEventHandler() { + const auto toastParent = Ui::BoxShow(this).toastParent(); const auto callback = [=](FileDialog::OpenResult &&result) { - auto showError = [](tr::phrase<> t) { - Ui::Toast::Show(t(tr::now)); + auto showError = [toastParent](tr::phrase<> t) { + Ui::Toast::Show(toastParent, t(tr::now)); }; const auto checkResult = [=](const Ui::PreparedList &list) { @@ -547,7 +548,9 @@ bool EditCaptionBox::setPreparedList(Ui::PreparedList &&list) { } } if (invalidForAlbum) { - Ui::Toast::Show(tr::lng_edit_media_album_error(tr::now)); + Ui::Toast::Show( + Ui::BoxShow(this).toastParent(), + tr::lng_edit_media_album_error(tr::now)); return false; } _preparedList = std::move(list); diff --git a/Telegram/SourceFiles/boxes/max_invite_box.cpp b/Telegram/SourceFiles/boxes/max_invite_box.cpp index 88be91f04..c9408aaec 100644 --- a/Telegram/SourceFiles/boxes/max_invite_box.cpp +++ b/Telegram/SourceFiles/boxes/max_invite_box.cpp @@ -90,7 +90,9 @@ void MaxInviteBox::mousePressEvent(QMouseEvent *e) { if (_linkOver) { if (!_channel->inviteLink().isEmpty()) { QGuiApplication::clipboard()->setText(_channel->inviteLink()); - Ui::Toast::Show(tr::lng_create_channel_link_copied(tr::now)); + Ui::Toast::Show( + Ui::BoxShow(this).toastParent(), + 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/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 22d901734..7ff717921 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -74,9 +74,10 @@ void FileDialogCallback( FileDialog::OpenResult &&result, Fn checkResult, Fn callback, - bool premium) { - auto showError = [](tr::phrase<> text) { - Ui::Toast::Show(text(tr::now)); + bool premium, + not_null toastParent) { + auto showError = [=](tr::phrase<> text) { + Ui::Toast::Show(toastParent, text(tr::now)); }; auto list = Storage::PreparedFileFromFilesDialog( @@ -394,11 +395,12 @@ void SendFilesBox::refreshAllAfterChanges(int fromItem) { } void SendFilesBox::openDialogToAddFileToAlbum() { + const auto toastParent = Ui::BoxShow(this).toastParent(); const auto checkResult = [=](const Ui::PreparedList &list) { if (_sendLimit != SendLimit::One) { return true; } else if (!_list.canBeSentInSlowmodeWith(list)) { - Ui::Toast::Show(tr::lng_slowmode_no_many(tr::now)); + Ui::Toast::Show(toastParent, tr::lng_slowmode_no_many(tr::now)); return false; } return true; @@ -409,7 +411,8 @@ void SendFilesBox::openDialogToAddFileToAlbum() { std::move(result), checkResult, [=](Ui::PreparedList list) { addFiles(std::move(list)); }, - premium); + premium, + toastParent); }; FileDialog::GetOpenPaths( @@ -549,6 +552,7 @@ void SendFilesBox::pushBlock(int from, int till) { }); }, widget->lifetime()); + const auto toastParent = Ui::BoxShow(this).toastParent(); block.itemReplaceRequest( ) | rpl::start_with_next([=](int index) { const auto replace = [=](Ui::PreparedList list) { @@ -569,7 +573,9 @@ 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(tr::lng_slowmode_no_many(tr::now)); + Ui::Toast::Show( + toastParent, + tr::lng_slowmode_no_many(tr::now)); return false; } return true; @@ -580,7 +586,8 @@ void SendFilesBox::pushBlock(int from, int till) { std::move(result), checkResult, replace, - premium); + premium, + toastParent); }; FileDialog::GetOpenPath( diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index a67c1bf9d..27393a533 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -272,7 +272,9 @@ void StickerSetBox::prepare() { _inner->setInstalled( ) | rpl::start_with_next([=](uint64 setId) { if (_inner->isMasksSet()) { - Ui::Toast::Show(tr::lng_masks_installed(tr::now)); + Ui::Toast::Show( + Ui::BoxShow(this).toastParent(), + tr::lng_masks_installed(tr::now)); } else { auto &stickers = _controller->session().data().stickers(); stickers.notifyStickerSetInstalled(setId); @@ -289,9 +291,11 @@ void StickerSetBox::prepare() { ) | rpl::start_with_next([=](uint64 setId) { const auto isMasks = _inner->isMasksSet(); - Ui::Toast::Show(isMasks - ? tr::lng_masks_has_been_archived(tr::now) - : tr::lng_stickers_has_been_archived(tr::now)); + Ui::Toast::Show( + Ui::BoxShow(this).toastParent(), + isMasks + ? tr::lng_masks_has_been_archived(tr::now) + : tr::lng_stickers_has_been_archived(tr::now)); auto &order = isMasks ? _controller->session().data().stickers().maskSetsOrderRef() @@ -360,7 +364,9 @@ void StickerSetBox::updateButtons() { const auto top = addTopButton(st::infoTopBarMenu); const auto share = [=] { copyStickersLink(); - Ui::Toast::Show(tr::lng_stickers_copied(tr::now)); + Ui::Toast::Show( + Ui::BoxShow(this).toastParent(), + tr::lng_stickers_copied(tr::now)); closeBox(); }; const auto menu = @@ -384,7 +390,9 @@ void StickerSetBox::updateButtons() { } else { auto share = [=] { copyStickersLink(); - Ui::Toast::Show(tr::lng_stickers_copied(tr::now)); + Ui::Toast::Show( + Ui::BoxShow(this).toastParent(), + tr::lng_stickers_copied(tr::now)); }; auto shareText = isMasks ? tr::lng_stickers_share_masks() @@ -1123,8 +1131,8 @@ void StickerSetBox::Inner::archiveStickers() { if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) { _setArchived.fire_copy(_setId); } - }).fail([] { - Ui::Toast::Show(Lang::Hard::ServerError()); + }).fail([toastParent = Window::Show(_controller).toastParent()] { + Ui::Toast::Show(toastParent, Lang::Hard::ServerError()); }).send(); } diff --git a/Telegram/SourceFiles/boxes/username_box.cpp b/Telegram/SourceFiles/boxes/username_box.cpp index d3b3bf140..756216728 100644 --- a/Telegram/SourceFiles/boxes/username_box.cpp +++ b/Telegram/SourceFiles/boxes/username_box.cpp @@ -254,7 +254,9 @@ void UsernameBox::changed() { void UsernameBox::linkClick() { QGuiApplication::clipboard()->setText( _session->createInternalLinkFull(getName())); - Ui::Toast::Show(tr::lng_username_copied(tr::now)); + Ui::Toast::Show( + Ui::BoxShow(this).toastParent(), + tr::lng_username_copied(tr::now)); } void UsernameBox::updateFail(const QString &error) { diff --git a/Telegram/SourceFiles/core/click_handler_types.cpp b/Telegram/SourceFiles/core/click_handler_types.cpp index 38bd8bb5d..caffdce7c 100644 --- a/Telegram/SourceFiles/core/click_handler_types.cpp +++ b/Telegram/SourceFiles/core/click_handler_types.cpp @@ -308,14 +308,17 @@ 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(item->history()->peer->isBroadcast() - ? tr::lng_error_nocopy_channel(tr::now) - : tr::lng_error_nocopy_group(tr::now)); + Ui::Toast::Show( + toastParent, + 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)); } - Ui::Toast::Show(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 f4efc6d0b..65191822f 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -565,7 +565,9 @@ bool ShowInviteLink( return false; } QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show(tr::lng_group_invite_copied(tr::now)); + Ui::Toast::Show( + Window::Show(controller).toastParent(), + tr::lng_group_invite_copied(tr::now)); return true; } @@ -579,13 +581,15 @@ bool OpenExternalLink( } void ExportTestChatTheme( - not_null session, + not_null controller, not_null theme) { + const auto session = &controller->session(); + const auto show = std::make_shared(controller); const auto inputSettings = [&](Data::CloudThemeType type) -> std::optional { const auto i = theme->settings.find(type); if (i == end(theme->settings)) { - Ui::Toast::Show("Something went wrong :("); + Ui::Toast::Show(show->toastParent(), "Something went wrong :("); return std::nullopt; } const auto &fields = i->second; @@ -593,7 +597,7 @@ void ExportTestChatTheme( || !fields.paper->isPattern() || fields.paper->backgroundColors().empty() || !fields.paper->hasShareUrl()) { - Ui::Toast::Show("Something went wrong :("); + Ui::Toast::Show(show->toastParent(), "Something went wrong :("); return std::nullopt; } const auto &bg = fields.paper->backgroundColors(); @@ -601,7 +605,9 @@ void ExportTestChatTheme( const auto from = url.indexOf("bg/"); const auto till = url.indexOf("?"); if (from < 0 || till <= from) { - Ui::Toast::Show("Bad WallPaper link: " + url); + Ui::Toast::Show( + show->toastParent(), + "Bad WallPaper link: " + url); return std::nullopt; } @@ -683,9 +689,15 @@ void ExportTestChatTheme( const auto slug = Data::CloudTheme::Parse(session, result, true).slug; QGuiApplication::clipboard()->setText( session->createInternalLinkFull("addtheme/" + slug)); - Ui::Toast::Show(tr::lng_background_link_copied(tr::now)); + if (show->valid()) { + Ui::Toast::Show( + show->toastParent(), + tr::lng_background_link_copied(tr::now)); + } }).fail([=](const MTP::Error &error) { - Ui::Toast::Show("Error: " + error.type()); + if (show->valid()) { + Ui::Toast::Show(show->toastParent(), "Error: " + error.type()); + } }).send(); } @@ -706,7 +718,7 @@ bool ResolveTestChatTheme( params); if (theme) { if (!params["export"].isEmpty()) { - ExportTestChatTheme(&controller->session(), &*theme); + ExportTestChatTheme(controller, &*theme); } const auto recache = [&](Data::CloudThemeType type) { [[maybe_unused]] auto value = theme->settings.contains(type) diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 10503a2f5..e7dc84a2b 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -52,8 +52,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "main/main_session_settings.h" #include "core/application.h" +#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 "styles/style_chat.h" #include "styles/style_dialogs.h" @@ -1646,6 +1648,7 @@ ClickHandlerPtr MediaDice::makeHandler() const { ClickHandlerPtr MediaDice::MakeHandler( not_null history, const QString &emoji) { + // TODO support multi-windows. static auto ShownToast = base::weak_ptr(); static const auto HideExisting = [] { if (const auto toast = ShownToast.get()) { @@ -1653,7 +1656,7 @@ ClickHandlerPtr MediaDice::MakeHandler( ShownToast = nullptr; } }; - return std::make_shared([=] { + return std::make_shared([=](ClickContext context) { auto config = Ui::Toast::Config{ .text = { tr::lng_about_random(tr::now, lt_emoji, emoji) }, .st = &st::historyDiceToast, @@ -1683,7 +1686,15 @@ ClickHandlerPtr MediaDice::MakeHandler( } HideExisting(); - ShownToast = Ui::Toast::Show(config); + 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); + } else { + ShownToast = Ui::Toast::Show(config); + } }); } diff --git a/Telegram/SourceFiles/data/stickers/data_stickers.cpp b/Telegram/SourceFiles/data/stickers/data_stickers.cpp index e586416ec..aa7055c3b 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers.cpp @@ -405,6 +405,7 @@ void Stickers::applyArchivedResult( session().local().writeArchivedMasks(); } + // TODO async toast. Ui::Toast::Show(Ui::Toast::Config{ .text = { tr::lng_stickers_packs_archived(tr::now) }, .st = &st::stickersToast, diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index c6cb0c854..379fd7ffc 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -113,6 +113,20 @@ HiddenSenderInfo::HiddenSenderInfo(const QString &name, bool external) } } +ClickHandlerPtr HiddenSenderInfo::ForwardClickHandler() { + static const auto hidden = std::make_shared([]( + ClickContext context) { + 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)); + } + }); + return hidden; +} + bool HiddenSenderInfo::paintCustomUserpic( Painter &p, int x, @@ -202,15 +216,12 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { } } text.setMarkedText(st::fwdTextStyle, phrase); - static const auto hidden = std::make_shared([] { - Ui::Toast::Show(tr::lng_forwarded_hidden(tr::now)); - }); text.setLink(1, fromChannel ? goToMessageClickHandler(originalSender, originalId) : originalSender ? originalSender->openLink() - : hidden); + : HiddenSenderInfo::ForwardClickHandler()); if (via) { text.setLink(2, via->link); } diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 7beae9944..c52ea92bb 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -81,6 +81,8 @@ struct HiddenSenderInfo { Ui::EmptyUserpic emptyUserpic; mutable Data::CloudImage customUserpic; + [[nodiscard]] static ClickHandlerPtr ForwardClickHandler(); + [[nodiscard]] bool paintCustomUserpic( Painter &p, int x, diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index 4440db7c4..47e03e760 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -441,6 +441,7 @@ void ContactStatus::setupBlockHandler(not_null user) { void ContactStatus::setupShareHandler(not_null user) { _bar.entity()->shareClicks( ) | rpl::start_with_next([=] { + const auto show = std::make_shared(_controller); const auto share = [=](Fn &&close) { user->setSettings(0); user->session().api().request(MTPcontacts_AcceptContact( @@ -448,14 +449,18 @@ void ContactStatus::setupShareHandler(not_null user) { )).done([=](const MTPUpdates &result) { user->session().api().applyUpdates(result); - Ui::Toast::Show(tr::lng_new_contact_share_done( - tr::now, - lt_user, - user->shortName())); + if (show->valid()) { + Ui::Toast::Show( + show->toastParent(), + tr::lng_new_contact_share_done( + tr::now, + lt_user, + user->shortName())); + } }).send(); close(); }; - _controller->window().show(Ui::MakeConfirmBox({ + show->showBox(Ui::MakeConfirmBox({ .text = tr::lng_new_contact_share_sure( tr::now, lt_phone, @@ -488,6 +493,7 @@ void ContactStatus::setupReportHandler(not_null peer) { _bar.entity()->reportClicks( ) | rpl::start_with_next([=] { Expects(!peer->isUser()); + const auto show = std::make_shared(_controller); const auto callback = crl::guard(&_bar, [=](Fn &&close) { close(); @@ -503,7 +509,11 @@ void ContactStatus::setupReportHandler(not_null peer) { peer->session().api().deleteConversation(peer, false); }); - Ui::Toast::Show(tr::lng_report_spam_done(tr::now)); + if (show->valid()) { + Ui::Toast::Show( + show->toastParent(), + tr::lng_report_spam_done(tr::now)); + } // Destroys _bar. _controller->showBackFromStack(); @@ -514,7 +524,7 @@ void ContactStatus::setupReportHandler(not_null peer) { auto text = ((peer->isChat() || peer->isMegagroup()) ? tr::lng_report_spam_sure_group : tr::lng_report_spam_sure_channel)(); - _controller->window().show(Ui::MakeConfirmBox({ + show->showBox(Ui::MakeConfirmBox({ .text= std::move(text), .confirmed = callback, .confirmText = tr::lng_report_spam_ok(), diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index a18760ca0..23643a1c1 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -682,10 +682,7 @@ ClickHandlerPtr Element::fromLink() const { return imported; } } - static const auto hidden = std::make_shared([] { - Ui::Toast::Show(tr::lng_forwarded_hidden(tr::now)); - }); - _fromLink = hidden; + _fromLink = HiddenSenderInfo::ForwardClickHandler(); return _fromLink; } diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 7c877c80e..e3cc1d5fa 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1651,6 +1651,7 @@ ClickHandlerPtr Message::createGoToCommentsLink() const { if (const auto channel = history->peer->asChannel()) { if (channel->invitePeekExpires()) { Ui::Toast::Show( + Window::Show(controller).toastParent(), tr::lng_channel_invite_private(tr::now)); return; } diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 7c09d1c63..931b3da0e 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -353,12 +353,15 @@ object_ptr DetailsFiller::setupInfo() { tr::lng_info_link_label(), std::move(linkText), QString()); - link->setClickHandlerFilter([peer = _peer](auto&&...) { + const auto controller = _controller->parentController(); + link->setClickHandlerFilter([=, peer = _peer](auto&&...) { const auto link = peer->session().createInternalLinkFull( peer->userName()); if (!link.isEmpty()) { QGuiApplication::clipboard()->setText(link); - Ui::Toast::Show(tr::lng_username_copied(tr::now)); + Ui::Toast::Show( + Window::Show(controller).toastParent(), + tr::lng_username_copied(tr::now)); } return false; }); diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index fa373011b..506127de2 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -199,7 +199,9 @@ void Cover::initViewers() { } else { QGuiApplication::clipboard()->setText( _user->session().createInternalLinkFull(username)); - Ui::Toast::Show(tr::lng_username_copied(tr::now)); + Ui::Toast::Show( + Window::Show(_controller).toastParent(), + tr::lng_username_copied(tr::now)); } return false; }); diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index e73c8bd3d..3b7ac8017 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -760,7 +760,7 @@ void Editor::exportTheme() { _window->show(Ui::MakeInformBox(tr::lng_theme_editor_error())); return; } - Ui::Toast::Show(tr::lng_theme_editor_done(tr::now)); + _window->showToast(tr::lng_theme_editor_done(tr::now)); })); } @@ -817,10 +817,10 @@ QByteArray Editor::ColorizeInContent( void Editor::save() { if (Core::App().passcodeLocked()) { - Ui::Toast::Show(tr::lng_theme_editor_need_unlock(tr::now)); + _window->showToast(tr::lng_theme_editor_need_unlock(tr::now)); return; } else if (!_window->account().sessionExists()) { - Ui::Toast::Show(tr::lng_theme_editor_need_auth(tr::now)); + _window->showToast(tr::lng_theme_editor_need_auth(tr::now)); return; } else if (_saving) { return; diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index b568106e1..4843eb235 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -893,10 +893,11 @@ void SaveThemeBox( type = SaveErrorType::Link; } else if (error == qstr("THEME_SLUG_OCCUPIED")) { Ui::Toast::Show( + Ui::BoxShow(box).toastParent(), tr::lng_create_channel_link_occupied(tr::now)); type = SaveErrorType::Link; } else if (!error.isEmpty()) { - Ui::Toast::Show(error); + Ui::Toast::Show(Ui::BoxShow(box).toastParent(), error); } if (type == SaveErrorType::Name) { name->showError(); diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp index 5ad865efc..e9998538d 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp @@ -592,7 +592,8 @@ void CloudList::showMenu(Element &element) { _contextMenu->addAction(tr::lng_theme_share(tr::now), [=] { QGuiApplication::clipboard()->setText( _window->session().createInternalLinkFull("addtheme/" + slug)); - Ui::Toast::Show(tr::lng_background_link_copied(tr::now)); + _window->window().showToast( + tr::lng_background_link_copied(tr::now)); }, &st::menuIconShare); } if (cloud.documentId diff --git a/Telegram/SourceFiles/window/window_lock_widgets.cpp b/Telegram/SourceFiles/window/window_lock_widgets.cpp index 510caf4d0..b44831d6b 100644 --- a/Telegram/SourceFiles/window/window_lock_widgets.cpp +++ b/Telegram/SourceFiles/window/window_lock_widgets.cpp @@ -263,6 +263,7 @@ void TermsBox::prepare() { st::termsPadding), 0, age ? age->height() : 0); + const auto toastParent = Ui::BoxShow(this).toastParent(); content->entity()->setClickHandlerFilter([=]( const ClickHandlerPtr &handler, Qt::MouseButton button) { @@ -271,7 +272,9 @@ void TermsBox::prepare() { : QString(); if (TextUtilities::RegExpMention().match(link).hasMatch()) { _lastClickedMention = link; - Ui::Toast::Show(tr::lng_terms_agree_to_proceed(tr::now, lt_bot, link)); + Ui::Toast::Show( + toastParent, + tr::lng_terms_agree_to_proceed(tr::now, lt_bot, link)); return false; } return true; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index bf984a69d..12452159c 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -297,10 +297,12 @@ void TogglePinnedDialog( // This can happen when you remove this filter from another client. if (!ranges::contains( - (&owner->session())->data().chatsFilters().list(), - filterId, - &Data::ChatFilter::id)) { - Ui::Toast::Show(tr::lng_cant_do_this(tr::now)); + (&owner->session())->data().chatsFilters().list(), + filterId, + &Data::ChatFilter::id)) { + Ui::Toast::Show( + Window::Show(controller).toastParent(), + tr::lng_cant_do_this(tr::now)); return; } @@ -601,6 +603,7 @@ void Filler::addViewDiscussion() { _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)); return; } @@ -895,12 +898,14 @@ void Filler::fillArchiveActions() { }, hidden ? &st::menuIconExpand : &st::menuIconCollapse); _addAction(tr::lng_context_archive_to_menu(tr::now), [=] { - Ui::Toast::Show(Ui::Toast::Config{ - .text = { tr::lng_context_archive_to_menu_info(tr::now) }, - .st = &st::windowArchiveToast, - .durationMs = kArchivedToastDuration, - .multiline = true, - }); + 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->session().settings().setArchiveInMainMenu( !controller->session().settings().archiveInMainMenu()); @@ -959,7 +964,7 @@ void PeerMenuShareContactBox( action.clearDraft = false; user->session().api().shareContact(user, action); Ui::Toast::Show( - navigation->parentController()->widget()->bodyWidget(), + Window::Show(navigation).toastParent(), tr::lng_share_done(tr::now)); if (auto strong = *weak) { strong->closeBox(); @@ -1152,6 +1157,7 @@ void PeerMenuBlockUserBox( } Ui::Toast::Show( + Window::Show(window).toastParent(), tr::lng_new_contact_block_done(tr::now, lt_user, name)); }, st::attentionBoxButton); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 1bf10a7d7..e223bc66d 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -525,7 +525,9 @@ void SessionNavigation::showRepliesForMessage( _showingRepliesRequestId = 0; if (error.type() == u"CHANNEL_PRIVATE"_q || error.type() == u"USER_BANNED_IN_CHANNEL"_q) { - Ui::Toast::Show(tr::lng_group_not_accessible(tr::now)); + Ui::Toast::Show( + Show(this).toastParent(), + tr::lng_group_not_accessible(tr::now)); } }).send(); }