Suggest to reset gifts filter.

This commit is contained in:
John Preston 2025-05-18 17:20:53 +04:00
parent b20caee548
commit a7296f15ac
2 changed files with 44 additions and 0 deletions

View file

@ -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";

View file

@ -75,6 +75,9 @@ public:
[[nodiscard]] rpl::producer<bool> 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<bool> _notifyEnabled;
std::vector<View> _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<Ui::FlatLabel>(
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());