From e9a8acdc54776d8e83978e5bea642a77ed5cfa9b Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 1 Nov 2023 16:05:20 +0300 Subject: [PATCH] Added initial click handler to boosts list in boosts info. --- .../info/boosts/info_boosts_inner_widget.cpp | 20 +++++++++++++++++-- .../info_statistics_list_controllers.cpp | 19 +++++++++--------- .../info_statistics_list_controllers.h | 3 ++- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp index 66445a109a..8c9b8ab7fb 100644 --- a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp +++ b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp @@ -9,7 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_premium.h" #include "api/api_statistics.h" +#include "boxes/gift_premium_box.h" #include "boxes/peers/edit_peer_invite_link.h" +#include "data/data_peer.h" +#include "data/data_session.h" +#include "data/data_user.h" #include "info/boosts/create_giveaway_box.h" #include "info/boosts/info_boosts_widget.h" #include "info/info_controller.h" @@ -268,8 +272,20 @@ void InnerWidget::fill() { ::Settings::AddSkip(inner); if (status.firstSlice.total > 0) { + auto boostClicked = [=](const Data::Boost &boost) { + if (!boost.giftCodeLink.slug.isEmpty()) { + ResolveGiftCode(_controller, boost.giftCodeLink.slug); + } else if (boost.userId) { + const auto user = _peer->owner().user(boost.userId); + crl::on_main(this, [=] { + _controller->showPeerInfo(user); + }); + } else if (!boost.isUnclaimed) { + _show->showToast(tr::lng_boosts_list_pending_about(tr::now)); + } + }; + ::Settings::AddSkip(inner); - using PeerPtr = not_null; const auto header = inner->add( object_ptr(inner), st::statisticsLayerMargins @@ -283,7 +299,7 @@ void InnerWidget::fill() { Statistics::AddBoostsList( status.firstSlice, inner, - [=](PeerPtr p) { _controller->showPeerInfo(p); }, + std::move(boostClicked), _peer, tr::lng_boosts_title()); ::Settings::AddSkip(inner); diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp index cd71cd420e..085ee5bff9 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.cpp @@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Info::Statistics { namespace { +using BoostCallback = Fn; constexpr auto kColorIndexUnclaimed = int(3); constexpr auto kColorIndexPending = int(4); @@ -104,7 +105,7 @@ struct MembersDescriptor final { struct BoostsDescriptor final { Data::BoostsListSlice firstSlice; - Fn)> showPeerInfo; + BoostCallback boostClickedCallback; not_null peer; }; @@ -501,7 +502,7 @@ private: void applySlice(const Data::BoostsListSlice &slice); const not_null _session; - Fn)> _showPeerInfo; + BoostCallback _boostClickedCallback; Api::Boosts _api; Data::BoostsListSlice _firstSlice; @@ -516,7 +517,7 @@ private: BoostsController::BoostsController(BoostsDescriptor d) : _session(&d.peer->session()) -, _showPeerInfo(std::move(d.showPeerInfo)) +, _boostClickedCallback(std::move(d.boostClickedCallback)) , _api(d.peer) , _firstSlice(std::move(d.firstSlice)) { PeerListController::setStyleOverrides(&st::boostsListBox); @@ -566,11 +567,9 @@ void BoostsController::applySlice(const Data::BoostsListSlice &slice) { } void BoostsController::rowClicked(not_null row) { - if (!row->special()) { - crl::on_main([=, peer = row->peer()] { - _showPeerInfo(peer); - }); - return; + if (_boostClickedCallback) { + _boostClickedCallback( + static_cast(row.get())->boost()); } } @@ -677,7 +676,7 @@ void AddMembersList( void AddBoostsList( const Data::BoostsListSlice &firstSlice, not_null container, - Fn)> showPeerInfo, + BoostCallback boostClickedCallback, not_null peer, rpl::producer title) { const auto max = firstSlice.total; @@ -688,7 +687,7 @@ void AddBoostsList( BoostsController controller; int limit = Api::Boosts::kFirstSlice; }; - auto d = BoostsDescriptor{ firstSlice, std::move(showPeerInfo), peer }; + auto d = BoostsDescriptor{ firstSlice, boostClickedCallback, peer }; const auto state = container->lifetime().make_state(std::move(d)); state->delegate.setContent(container->add( diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.h b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.h index dc619362d1..de4bc5f2f1 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.h +++ b/Telegram/SourceFiles/info/statistics/info_statistics_list_controllers.h @@ -14,6 +14,7 @@ class VerticalLayout; } // namespace Ui namespace Data { +struct Boost; struct BoostsListSlice; struct PublicForwardsSlice; struct SupergroupStatistics; @@ -38,7 +39,7 @@ void AddMembersList( void AddBoostsList( const Data::BoostsListSlice &firstSlice, not_null container, - Fn)> showPeerInfo, + Fn boostClickedCallback, not_null peer, rpl::producer title);