diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 03fea8b0b..44b17cc6e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1661,6 +1661,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_star_ref_warning_end" = "End Anyway"; "lng_star_ref_created_title" = "Affiliate program started"; "lng_star_ref_created_text" = "Any Telegram user, channel owner or mini app developer can now join your program."; +"lng_star_ref_updated_title" = "Affiliate program updated"; +"lng_star_ref_updated_text" = "Any Telegram user, channel owner or mini app developer can join your program."; "lng_star_ref_ended_title" = "Affiliate program ended"; "lng_star_ref_ended_text" = "Participating affiliates have been notified. All referral links will be disabled in **24** hours."; "lng_star_ref_list_title" = "Affiliate Programs"; diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp index b680f72e7..d13a584ee 100644 --- a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp @@ -423,8 +423,8 @@ object_ptr ConfirmEndBox(Fn finish) { padded->paintRequest() | rpl::start_with_next([=] { auto p = QPainter(padded); auto hq = PainterHighQualityEnabler(p); - const auto size = st::boxTextFont->spacew; - const auto top = (st::boxTextFont->height - size) / 2; + const auto size = st::starrefEndBulletSize; + const auto top = st::starrefEndBulletTop; p.setBrush(st::windowFg); p.setPen(Qt::NoPen); p.drawEllipse(0, top, size, size); @@ -519,15 +519,19 @@ std::unique_ptr MakePeerBubbleButton( return result; } -void FinishProgram( +void UpdateProgram( std::shared_ptr show, not_null bot, + const StarRefProgram &program, Fn finished) { + using Flag = MTPbots_UpdateStarRefProgram::Flag; bot->session().api().request(MTPbots_UpdateStarRefProgram( - MTP_flags(0), + MTP_flags((program.commission > 0 && program.durationMonths > 0) + ? Flag::f_duration_months + : Flag()), bot->inputUser, - MTP_int(0), - MTP_int(0) + MTP_int(program.commission), + MTP_int(program.durationMonths) )).done([=](const MTPStarRefProgram &result) { bot->setStarRefProgram(Data::ParseStarRefProgram(&result)); finished(); @@ -536,6 +540,13 @@ void FinishProgram( }).send(); } +void FinishProgram( + std::shared_ptr show, + not_null bot, + Fn finished) { + UpdateProgram(std::move(show), bot, {}, std::move(finished)); +} + ConnectedBots Parse( not_null session, const MTPpayments_ConnectedStarRefBots &bots) { diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.h b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.h index f051b1042..921e3c360 100644 --- a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.h +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.h @@ -73,6 +73,11 @@ std::unique_ptr MakePeerBubbleButton( not_null peer, Ui::RpWidget *right = nullptr); +void UpdateProgram( + std::shared_ptr show, + not_null bot, + const StarRefProgram &program, + Fn finished); void FinishProgram( std::shared_ptr show, not_null bot, diff --git a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.cpp b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.cpp index d2b3e6a6a..2232b462a 100644 --- a/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.cpp +++ b/Telegram/SourceFiles/info/bot/starref/info_bot_starref_setup_widget.cpp @@ -749,6 +749,7 @@ void InnerWidget::setupEnd() { .text = tr::lng_star_ref_ended_text( tr::now, Ui::Text::RichLangValue), + .duration = Ui::Toast::kDefaultDuration * 3, }); } }); @@ -1003,30 +1004,28 @@ std::unique_ptr Widget::setupBottom() { st::boxDividerLabel), QMargins(margins.left(), 0, margins.right(), 0)); save->setClickedCallback([=] { - using Flag = MTPbots_UpdateStarRefProgram::Flag; - const auto weak = Ui::MakeWeak(this); const auto user = _state->user; - auto program = StarRefProgram{ + const auto program = StarRefProgram{ .commission = _state->program.commission, .durationMonths = _state->program.durationMonths, }; - user->session().api().request(MTPbots_UpdateStarRefProgram( - MTP_flags((program.commission > 0 && program.durationMonths > 0) - ? Flag::f_duration_months - : Flag()), - user->inputUser, - MTP_int(program.commission), - MTP_int(program.durationMonths) - )).done([=] { - user->botInfo->starRefProgram.commission = program.commission; - user->botInfo->starRefProgram.durationMonths - = program.durationMonths; - if (weak) { - controller()->showBackFromStack(); - } - }).fail(crl::guard(weak, [=] { - controller()->showToast("Failed!"); - })).send(); + + const auto show = controller()->uiShow(); + const auto exists = _state->exists; + UpdateProgram(show, user, program, crl::guard(this, [=] { + controller()->showBackFromStack(); + show->showToast({ + .title = (exists + ? tr::lng_star_ref_updated_title + : tr::lng_star_ref_created_title)(tr::now), + .text = (exists + ? tr::lng_star_ref_updated_text + : tr::lng_star_ref_created_text)( + tr::now, + Ui::Text::RichLangValue), + .duration = Ui::Toast::kDefaultDuration * 3, + }); + })); }); widthValue() | rpl::start_with_next([=](int width) { diff --git a/Telegram/SourceFiles/ui/effects/premium.style b/Telegram/SourceFiles/ui/effects/premium.style index 360a3e6f4..b27cc61a3 100644 --- a/Telegram/SourceFiles/ui/effects/premium.style +++ b/Telegram/SourceFiles/ui/effects/premium.style @@ -461,3 +461,5 @@ starrefBottomButtonSublabel: FlatLabel(starrefBottomButtonLabel) { } starrefBottomButtonLabelTop: 5px; starrefBottomButtonSublabelTop: 23px; +starrefEndBulletSize: 6px; +starrefEndBulletTop: 8px;