diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 9ab04c9ad..085cbd39b 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2418,6 +2418,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_credits_small_balance_title#other" = "{count} Stars Needed"; "lng_credits_small_balance_about" = "Buy **Stars** and use them on **{bot}** and other miniapps."; "lng_credits_small_balance_reaction" = "Buy **Stars** and send them to {channel} to support their posts."; +"lng_credits_small_balance_subscribe" = "Buy **Stars** and subscribe to **{channel}** and other channels."; "lng_credits_purchase_blocked" = "Sorry, you can't purchase this item with Telegram Stars."; "lng_credits_gift_title" = "Gift Telegram Stars"; diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index 36c58d67f..5f64a21c9 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "boxes/premium_limits_box.h" #include "core/application.h" +#include "data/components/credits.h" #include "data/data_channel.h" #include "data/data_file_origin.h" #include "data/data_forum.h" @@ -21,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_badge.h" #include "lang/lang_keys.h" #include "main/main_session.h" +#include "settings/settings_credits_graphics.h" #include "ui/boxes/confirm_box.h" #include "ui/controls/userpic_button.h" #include "ui/effects/premium_graphics.h" @@ -35,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "styles/style_boxes.h" #include "styles/style_chat_helpers.h" +#include "styles/style_credits.h" #include "styles/style_info.h" #include "styles/style_layers.h" #include "styles/style_premium.h" @@ -247,15 +250,26 @@ void ConfirmSubscriptionBox( Ui::Text::RichLangValue), st::inviteLinkSubscribeBoxTerms))); - auto confirmText = tr::lng_channel_invite_subscription_button(); - const auto weak = Ui::MakeWeak(box); - state->saveButton = box->addButton(std::move(confirmText), [=] { - if (state->api) { - return; - } - state->api.emplace(&session->mtp()); - state->loading.force_assign(true); + { + const auto balance = Settings::AddBalanceWidget( + content, + session->credits().balanceValue(), + true); + session->credits().load(true); + rpl::combine( + balance->sizeValue(), + content->sizeValue() + ) | rpl::start_with_next([=](const QSize &, const QSize &) { + balance->moveToRight( + st::creditsHistoryRightSkip * 2, + st::creditsHistoryRightSkip); + balance->update(); + }, balance->lifetime()); + } + + const auto sendCredits = [=, weak = Ui::MakeWeak(box)] { + const auto show = box->uiShow(); const auto buttonWidth = state->saveButton ? state->saveButton->width() : 0; @@ -264,22 +278,52 @@ void ConfirmSubscriptionBox( MTP_flags(0), MTP_long(formId), MTP_inputInvoiceChatInviteSubscription(MTP_string(hash))) - ).done([=](auto result) { + ).done([=](const MTPpayments_PaymentResult &result) { + state->api = std::nullopt; + state->loading.force_assign(false); + result.match([&](const MTPDpayments_paymentResult &data) { + session->api().applyUpdates(data.vupdates()); + }, [](const MTPDpayments_paymentVerificationNeeded &data) { + }); if (weak) { - state->api = std::nullopt; box->closeBox(); } - }).fail([=, show = box->uiShow()](const MTP::Error &error) { + }).fail([=](const MTP::Error &error) { const auto id = error.type(); if (weak) { state->api = std::nullopt; } show->showToast(id); + state->loading.force_assign(false); }).send(); if (state->saveButton) { state->saveButton->resizeToWidth(buttonWidth); } + }; + + auto confirmText = tr::lng_channel_invite_subscription_button(); + state->saveButton = box->addButton(std::move(confirmText), [=] { + if (state->api) { + return; + } + state->api.emplace(&session->mtp()); + state->loading.force_assign(true); + + const auto done = [=](Settings::SmallBalanceResult result) { + if (result == Settings::SmallBalanceResult::Success) { + sendCredits(); + } else { + state->api = std::nullopt; + state->loading.force_assign(false); + } + }; + Settings::MaybeRequestBalanceIncrease( + Main::MakeSessionShow(box->uiShow(), session), + amount, + Settings::SmallBalanceSubscription{ .name = name }, + done); }); + if (const auto saveButton = state->saveButton) { using namespace Info::Statistics; const auto loadingAnimation = InfiniteRadialAnimationWidget( diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index 88d5bb89c..d76ee64db 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -877,10 +877,12 @@ void SmallBalanceBox( }; const auto owner = &show->session().data(); - const auto peer = v::match(source, [&](SmallBalanceBot value) { - return owner->peer(peerFromUser(value.botId)); + const auto name = v::match(source, [&](SmallBalanceBot value) { + return owner->peer(peerFromUser(value.botId))->name(); }, [&](SmallBalanceReaction value) { - return owner->peer(peerFromChannel(value.channelId)); + return owner->peer(peerFromChannel(value.channelId))->name(); + }, [](SmallBalanceSubscription value) { + return value.name; }); auto needed = show->session().credits().balanceValue( @@ -897,14 +899,19 @@ void SmallBalanceBox( rpl::duplicate( needed ) | rpl::filter(rpl::mappers::_1 > 0) | tr::to_count()), - .about = (peer->isBroadcast() + .about = (v::is(source) + ? tr::lng_credits_small_balance_subscribe( + lt_channel, + rpl::single(Ui::Text::Bold(name)), + Ui::Text::RichLangValue) + : v::is(source) ? tr::lng_credits_small_balance_reaction( lt_channel, - rpl::single(Ui::Text::Bold(peer->name())), + rpl::single(Ui::Text::Bold(name)), Ui::Text::RichLangValue) : tr::lng_credits_small_balance_about( lt_bot, - rpl::single(TextWithEntities{ peer->name() }), + rpl::single(TextWithEntities{ name }), Ui::Text::RichLangValue)), .light = true, .gradientStops = Ui::Premium::CreditsIconGradientStops(), diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.h b/Telegram/SourceFiles/settings/settings_credits_graphics.h index 9a8f05e3e..a22debf2c 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.h +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.h @@ -93,9 +93,13 @@ struct SmallBalanceBot { struct SmallBalanceReaction { ChannelId channelId = 0; }; +struct SmallBalanceSubscription { + QString name; +}; struct SmallBalanceSource : std::variant< SmallBalanceBot, - SmallBalanceReaction> { + SmallBalanceReaction, + SmallBalanceSubscription> { using variant::variant; };