From 8a804fcfad8511f8dc1cca2d9f2e484892ce4d7a Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 6 Nov 2023 14:41:42 +0400 Subject: [PATCH] Add toasts about giveaway/gift start. --- Telegram/Resources/langs/lang.strings | 6 +++ .../info/boosts/create_giveaway_box.cpp | 48 +++++++++++++++++-- Telegram/lib_ui | 2 +- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 6ecca9459..001925cbe 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2119,6 +2119,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_giveaway_channels_confirm_title" = "Channel is Private"; "lng_giveaway_channels_confirm_about" = "Are you sure you want to add a private channel? Users won't be able to join it without an invite link."; +"lng_giveaway_created_title" = "Giveaway created"; +"lng_giveaway_created_body" = "Check your channels' {link} to see how this giveaway boosted your channel."; +"lng_giveaway_awarded_title" = "Premium subscriptions gifted"; +"lng_giveaway_awarded_body" = "Check your channels' {link} to see how gifts boosted your channel."; +"lng_giveaway_created_link" = "Statistics"; + "lng_prize_title" = "Congratulations!"; "lng_prize_about" = "You won a prize in a giveaway organized by {channel}."; "lng_prize_duration" = "Your prize is a **Telegram Premium** subscription {duration}."; diff --git a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp index a1f72950b..c1781ea03 100644 --- a/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp +++ b/Telegram/SourceFiles/info/boosts/create_giveaway_box.cpp @@ -15,7 +15,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/boosts/giveaway/giveaway_list_controllers.h" #include "info/boosts/giveaway/giveaway_type_row.h" #include "info/boosts/giveaway/select_countries_box.h" +#include "info/boosts/info_boosts_widget.h" #include "info/info_controller.h" +#include "info/info_memento.h" #include "lang/lang_keys.h" #include "payments/payments_checkout_process.h" // Payments::CheckoutProcess #include "payments/payments_form.h" // Payments::InvoicePremiumGiftCode @@ -40,6 +42,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { +constexpr auto kDoneTooltipDuration = 5 * crl::time(1000); + [[nodiscard]] QDateTime ThreeDaysAfterToday() { auto dateNow = QDateTime::currentDateTime(); dateNow = dateNow.addDays(3); @@ -71,6 +75,8 @@ void CreateGiveawayBox( not_null peer) { box->setWidth(st::boxWideWidth); + const auto weakWindow = base::make_weak(controller->parentController()); + const auto bar = box->verticalLayout()->add( object_ptr( box, @@ -624,12 +630,44 @@ void CreateGiveawayBox( }; } state->confirmButtonBusy = true; - Payments::CheckoutProcess::Start( - std::move(invoice), - crl::guard(box, [=](auto) { + const auto show = box->uiShow(); + const auto weak = Ui::MakeWeak(box.get()); + const auto done = [=](Payments::CheckoutResult result) { + if (const auto strong = weak.data()) { state->confirmButtonBusy = false; - box->window()->setFocus(); - })); + strong->window()->setFocus(); + strong->closeBox(); + } + if (result == Payments::CheckoutResult::Paid) { + const auto filter = [=](const auto &...) { + if (const auto window = weakWindow.get()) { + window->showSection(Info::Boosts::Make(peer)); + } + return false; + }; + const auto title = isSpecific + ? tr::lng_giveaway_awarded_title + : tr::lng_giveaway_created_title; + const auto body = isSpecific + ? tr::lng_giveaway_awarded_body + : tr::lng_giveaway_created_body; + show->showToast({ + .text = Ui::Text::Bold( + title(tr::now)).append('\n').append( + body( + tr::now, + lt_link, + Ui::Text::Link( + tr::lng_giveaway_created_link( + tr::now)), + Ui::Text::WithEntities)), + .duration = kDoneTooltipDuration, + .adaptive = true, + .filter = filter, + }); + } + }; + Payments::CheckoutProcess::Start(std::move(invoice), done); }); box->addButton(std::move(button)); } diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 762a611f2..b8998700c 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 762a611f2009e623d6291ae5564bcd5fa4602e3d +Subproject commit b8998700c4a34890cf20b7cad0a9225877101d69