Slightly simplified constructor of Info::BotEarn::InnerWidget.

This commit is contained in:
23rd 2024-10-27 07:34:51 +03:00
parent 32b8d83c04
commit 24aaed44b9
3 changed files with 11 additions and 23 deletions

View file

@ -60,13 +60,9 @@ void AddHeader(
} // namespace } // namespace
InnerWidget::InnerWidget( InnerWidget::InnerWidget(QWidget *parent, not_null<Controller*> controller)
QWidget *parent,
not_null<Controller*> controller,
not_null<PeerData*> peer)
: VerticalLayout(parent) : VerticalLayout(parent)
, _controller(controller) , _controller(controller)
, _peer(peer)
, _show(controller->uiShow()) { , _show(controller->uiShow()) {
} }
@ -75,7 +71,7 @@ void InnerWidget::load() {
const auto request = [=](Fn<void(Data::CreditsEarnStatistics)> done) { const auto request = [=](Fn<void(Data::CreditsEarnStatistics)> done) {
const auto api = apiLifetime->make_state<Api::CreditsEarnStatistics>( const auto api = apiLifetime->make_state<Api::CreditsEarnStatistics>(
_peer->asUser()); peer()->asUser());
api->request( api->request(
) | rpl::start_with_error_done([show = _show](const QString &error) { ) | rpl::start_with_error_done([show = _show](const QString &error) {
show->showToast(error); show->showToast(error);
@ -92,18 +88,18 @@ void InnerWidget::load() {
_showFinished.events()); _showFinished.events());
_showFinished.events( _showFinished.events(
) | rpl::take(1) | rpl::start_with_next([=] { ) | rpl::take(1) | rpl::start_with_next([=, this, peer = peer()] {
request([=](Data::CreditsEarnStatistics state) { request([=](Data::CreditsEarnStatistics state) {
_state = state; _state = state;
_loaded.fire(true); _loaded.fire(true);
fill(); fill();
_peer->session().account().mtpUpdates( peer->session().account().mtpUpdates(
) | rpl::start_with_next([=](const MTPUpdates &updates) { ) | rpl::start_with_next([=](const MTPUpdates &updates) {
using TL = MTPDupdateStarsRevenueStatus; using TL = MTPDupdateStarsRevenueStatus;
Api::PerformForUpdate<TL>(updates, [&](const TL &d) { Api::PerformForUpdate<TL>(updates, [&](const TL &d) {
const auto peerId = peerFromMTP(d.vpeer()); const auto peerId = peerFromMTP(d.vpeer());
if (peerId == _peer->id) { if (peerId == peer->id) {
request([=](Data::CreditsEarnStatistics state) { request([=](Data::CreditsEarnStatistics state) {
_state = state; _state = state;
_stateUpdated.fire({}); _stateUpdated.fire({});
@ -233,7 +229,7 @@ void InnerWidget::fill() {
::Settings::AddWithdrawalWidget( ::Settings::AddWithdrawalWidget(
container, container,
_controller->parentController(), _controller->parentController(),
_peer, peer(),
rpl::single( rpl::single(
data.buyAdsUrl data.buyAdsUrl
) | rpl::then( ) | rpl::then(
@ -262,7 +258,7 @@ void InnerWidget::fillHistory() {
const auto sectionIndex = history->lifetime().make_state<int>(0); const auto sectionIndex = history->lifetime().make_state<int>(0);
const auto fill = [=, peer = _peer]( const auto fill = [=, peer = peer()](
not_null<PeerData*> premiumBot, not_null<PeerData*> premiumBot,
const Data::CreditsStatusSlice &fullSlice, const Data::CreditsStatusSlice &fullSlice,
const Data::CreditsStatusSlice &inSlice, const Data::CreditsStatusSlice &inSlice,
@ -395,7 +391,7 @@ void InnerWidget::fillHistory() {
const auto apiLifetime = history->lifetime().make_state<rpl::lifetime>(); const auto apiLifetime = history->lifetime().make_state<rpl::lifetime>();
rpl::single(rpl::empty) | rpl::then( rpl::single(rpl::empty) | rpl::then(
_stateUpdated.events() _stateUpdated.events()
) | rpl::start_with_next([=, peer = _peer] { ) | rpl::start_with_next([=, peer = peer()] {
using Api = Api::CreditsHistory; using Api = Api::CreditsHistory;
const auto apiFull = apiLifetime->make_state<Api>(peer, true, true); const auto apiFull = apiLifetime->make_state<Api>(peer, true, true);
const auto apiIn = apiLifetime->make_state<Api>(peer, true, false); const auto apiIn = apiLifetime->make_state<Api>(peer, true, false);
@ -450,7 +446,7 @@ void InnerWidget::setInnerFocus() {
} }
not_null<PeerData*> InnerWidget::peer() const { not_null<PeerData*> InnerWidget::peer() const {
return _peer; return _controller->statisticsTag().peer;
} }
} // namespace Info::BotEarn } // namespace Info::BotEarn

View file

@ -32,10 +32,7 @@ public:
struct ShowRequest final { struct ShowRequest final {
}; };
InnerWidget( InnerWidget(QWidget *parent, not_null<Controller*> controller);
QWidget *parent,
not_null<Controller*> controller,
not_null<PeerData*> peer);
[[nodiscard]] not_null<PeerData*> peer() const; [[nodiscard]] not_null<PeerData*> peer() const;
@ -54,7 +51,6 @@ private:
void fillHistory(); void fillHistory();
not_null<Controller*> _controller; not_null<Controller*> _controller;
not_null<PeerData*> _peer;
std::shared_ptr<Ui::Show> _show; std::shared_ptr<Ui::Show> _show;
Data::CreditsEarnStatistics _state; Data::CreditsEarnStatistics _state;

View file

@ -50,11 +50,7 @@ Widget::Widget(
QWidget *parent, QWidget *parent,
not_null<Controller*> controller) not_null<Controller*> controller)
: ContentWidget(parent, controller) : ContentWidget(parent, controller)
, _inner(setInnerWidget( , _inner(setInnerWidget(object_ptr<InnerWidget>(this, controller))) {
object_ptr<InnerWidget>(
this,
controller,
controller->statisticsTag().peer))) {
_inner->showRequests( _inner->showRequests(
) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) {
}, _inner->lifetime()); }, _inner->lifetime());