From a7296f15ace8e8c901d3b2ee06b848104479374a Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 18 May 2025 17:20:53 +0400 Subject: [PATCH] Suggest to reset gifts filter. --- Telegram/Resources/langs/lang.strings | 2 + .../peer_gifts/info_peer_gifts_widget.cpp | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 40c9c2e782..89211b5e01 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2256,6 +2256,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_peer_gifts_title" = "Gifts"; "lng_peer_gifts_about" = "These gifts were sent to {user} by other users."; "lng_peer_gifts_about_mine" = "These gifts were sent to you by other users. Click on a gift to convert it to Stars or change its privacy settings."; +"lng_peer_gifts_empty_search" = "No matching gifts"; +"lng_peer_gifts_view_all" = "View All Gifts"; "lng_peer_gifts_notify" = "Notify About New Gifts"; "lng_peer_gifts_notify_enabled" = "You will receive a message from Telegram when your channel receives a gift."; "lng_peer_gifts_filter_by_value" = "Sort by Value"; diff --git a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp index f591c74bac..b3454d1e17 100644 --- a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp +++ b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp @@ -75,6 +75,9 @@ public: [[nodiscard]] rpl::producer notifyEnabled() const { return _notifyEnabled.events(); } + [[nodiscard]] rpl::producer<> resetFilterRequests() const { + return _resetFilterRequests.events(); + } [[nodiscard]] rpl::producer<> scrollToTop() const { return _scrollToTop.events(); } @@ -130,7 +133,9 @@ private: QString _offset; bool _allLoaded = false; bool _reloading = false; + bool _aboutFiltered = false; + rpl::event_stream<> _resetFilterRequests; rpl::event_stream _notifyEnabled; std::vector _views; int _viewsForWidth = 0; @@ -575,6 +580,39 @@ void InnerWidget::showGift(int index) { } void InnerWidget::refreshAbout() { + const auto filter = _filter.current(); + const auto filteredEmpty = _allLoaded + && _entries.empty() + && (filter.skipLimited + || filter.skipUnlimited + || filter.skipSaved + || filter.skipUnsaved + || filter.skipUnique); + + if (filteredEmpty) { + auto text = tr::lng_peer_gifts_empty_search( + tr::now, + Ui::Text::RichLangValue); + if (_totalCount > 0) { + text.append("\n\n").append(Ui::Text::Link( + tr::lng_peer_gifts_view_all(tr::now))); + } + _about = std::make_unique( + this, + rpl::single(text), + st::giftListAbout); + _about->setClickHandlerFilter([=](const auto &...) { + _resetFilterRequests.fire({}); + return false; + }); + _about->show(); + _aboutFiltered = true; + resizeToWidth(width()); + } else if (_aboutFiltered) { + _about = nullptr; + _aboutFiltered = false; + } + if (!_peer->isSelf() && _peer->canManageGifts() && !_entries.empty()) { if (_about) { _about = nullptr; @@ -679,6 +717,10 @@ Widget::Widget( ) | rpl::take(1) | rpl::start_with_next([=](bool enabled) { setupNotifyCheckbox(enabled); }, _inner->lifetime()); + _inner->resetFilterRequests( + ) | rpl::start_with_next([=] { + _filter = Filter(); + }, _inner->lifetime()); _inner->scrollToTop() | rpl::start_with_next([=] { scrollTo({ 0, 0 }); }, _inner->lifetime());