From 4bdac53be2bdc7158fdb259048349564905a47a9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 4 Aug 2022 16:35:50 +0300 Subject: [PATCH] Fix toast hiding on jump to Saved Messages. --- .../SourceFiles/history/history_widget.cpp | 1 + .../view/history_view_sticker_toast.cpp | 21 +++++++++++++++++++ .../history/view/history_view_sticker_toast.h | 2 ++ 3 files changed, 24 insertions(+) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 6ac3b0a6c..53d32e13e 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -3977,6 +3977,7 @@ void HistoryWidget::showAnimated( } _topShadow->setVisible(params.withTopBarShadow ? false : true); _preserveScrollTop = false; + _stickerToast = nullptr; _cacheOver = controller()->content()->grabForShowAnimation(params); diff --git a/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp b/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp index 4039030bd..580c99c0e 100644 --- a/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp +++ b/Telegram/SourceFiles/history/view/history_view_sticker_toast.cpp @@ -42,6 +42,12 @@ StickerToast::StickerToast( StickerToast::~StickerToast() { cancelRequest(); + _hiding.push_back(_weak); + for (const auto &weak : base::take(_hiding)) { + if (const auto strong = weak.get()) { + delete strong->widget(); + } + } } void StickerToast::showFor(not_null document) { @@ -143,6 +149,12 @@ void StickerToast::showWithTitle(const QString &title) { _st.padding.setLeft(skip + size + skip); _st.padding.setRight(st::historyPremiumViewSet.font->width(view) - st::historyPremiumViewSet.width); + + clearHiddenHiding(); + if (_weak.get()) { + _hiding.push_back(_weak); + } + _weak = Ui::Toast::Show(_parent, Ui::Toast::Config{ .text = text, .st = &_st, @@ -226,6 +238,15 @@ void StickerToast::showWithTitle(const QString &title) { }); } +void StickerToast::clearHiddenHiding() { + _hiding.erase( + ranges::remove( + _hiding, + nullptr, + &base::weak_ptr::get), + end(_hiding)); +} + void StickerToast::setupEmojiPreview( not_null widget, int size) { diff --git a/Telegram/SourceFiles/history/view/history_view_sticker_toast.h b/Telegram/SourceFiles/history/view/history_view_sticker_toast.h index 21d8d8997..d91c8c7c8 100644 --- a/Telegram/SourceFiles/history/view/history_view_sticker_toast.h +++ b/Telegram/SourceFiles/history/view/history_view_sticker_toast.h @@ -42,11 +42,13 @@ private: void setupEmojiPreview(not_null widget, int size); void setupLottiePreview(not_null widget, int size); + void clearHiddenHiding(); const not_null _controller; const not_null _parent; style::Toast _st; base::weak_ptr _weak; + std::vector> _hiding; DocumentData *_for = nullptr; Fn _destroy;