diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index da93d015b5..f54562516e 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -1371,8 +1371,8 @@ void ApplyChannelUpdate( creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) { if (const auto strong = weak.get()) { strong->credits().apply(id, slice.balance); - creditsLoadLifetime->destroy(); } + creditsLoadLifetime->destroy(); }); base::timer_once(kTimeout) | rpl::start_with_next([=] { creditsLoadLifetime->destroy(); @@ -1380,17 +1380,16 @@ void ApplyChannelUpdate( const auto currencyLoadLifetime = std::make_shared(); const auto currencyLoad = currencyLoadLifetime->make_state(channel); - currencyLoad->request( - ) | rpl::start_with_error_done([=](const QString &error) { - currencyLoadLifetime->destroy(); - }, [=] { + const auto apply = [=](Data::EarnInt balance) { if (const auto strong = weak.get()) { - strong->credits().applyCurrency( - id, - currencyLoad->data().currentBalance); - currencyLoadLifetime->destroy(); + strong->credits().applyCurrency(id, balance); } - }, *currencyLoadLifetime); + currencyLoadLifetime->destroy(); + }; + currencyLoad->request() | rpl::start_with_error_done( + [=](const QString &error) { apply(0); }, + [=] { apply(currencyLoad->data().currentBalance); }, + *currencyLoadLifetime); base::timer_once(kTimeout) | rpl::start_with_next([=] { currencyLoadLifetime->destroy(); }, *currencyLoadLifetime); diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index 1b0642ef92..f7abd8d9f0 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -778,8 +778,8 @@ void ApplyUserUpdate(not_null user, const MTPDuserFull &update) { creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) { if (const auto strong = weak.get()) { strong->credits().apply(id, slice.balance); - creditsLoadLifetime->destroy(); } + creditsLoadLifetime->destroy(); }); base::timer_once(kTimeout) | rpl::start_with_next([=] { creditsLoadLifetime->destroy(); @@ -788,17 +788,16 @@ void ApplyUserUpdate(not_null user, const MTPDuserFull &update) { = std::make_shared(); const auto currencyLoad = currencyLoadLifetime->make_state(user); - currencyLoad->request( - ) | rpl::start_with_error_done([=](const QString &error) { - currencyLoadLifetime->destroy(); - }, [=] { + const auto apply = [=](Data::EarnInt balance) { if (const auto strong = weak.get()) { - strong->credits().applyCurrency( - id, - currencyLoad->data().currentBalance); - currencyLoadLifetime->destroy(); + strong->credits().applyCurrency(id, balance); } - }, *currencyLoadLifetime); + currencyLoadLifetime->destroy(); + }; + currencyLoad->request() | rpl::start_with_error_done( + [=](const QString &error) { apply(0); }, + [=] { apply(currencyLoad->data().currentBalance); }, + *currencyLoadLifetime); base::timer_once(kTimeout) | rpl::start_with_next([=] { currencyLoadLifetime->destroy(); }, *currencyLoadLifetime); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 61998c8787..e38d772d83 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -887,15 +887,16 @@ rpl::producer AddCurrencyAction( = std::make_shared(); const auto currencyLoad = currencyLoadLifetime->make_state(user); - currencyLoad->request( - ) | rpl::start_with_error_done([=](const QString &error) { - currencyLoadLifetime->destroy(); - }, [=] { + const auto done = [=](Data::EarnInt balance) { if ([[maybe_unused]] const auto strong = weak.data()) { - state->balance = currencyLoad->data().currentBalance; + state->balance = balance; currencyLoadLifetime->destroy(); } - }, *currencyLoadLifetime); + }; + currencyLoad->request() | rpl::start_with_error_done( + [=](const QString &error) { done(0); }, + [=] { done(currencyLoad->data().currentBalance); }, + *currencyLoadLifetime); } const auto &st = st::infoSharedMediaButton; const auto button = wrapButton->entity(); @@ -915,7 +916,7 @@ rpl::producer AddCurrencyAction( ) | rpl::start_with_next([=, &st]( int width, const QString &button, - uint64 balance) { + Data::EarnInt balance) { const auto available = width - rect::m::sum::h(st.padding) - st.style.font->width(button)