From 2aae67cb8184f052dee573778c7d7cb7448d0bee Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 24 Feb 2026 14:14:22 +0400 Subject: [PATCH] Show nice gift burned error everywhere. --- Telegram/SourceFiles/boxes/star_gift_box.cpp | 31 ++++++++++++++----- Telegram/SourceFiles/boxes/star_gift_box.h | 9 ++++++ .../SourceFiles/boxes/transfer_gift_box.cpp | 8 +++-- .../SourceFiles/core/local_url_handlers.cpp | 4 ++- .../components/recent_shared_media_gifts.cpp | 5 ++- .../view/media/history_view_premium_gift.cpp | 6 ++-- .../peer_gifts/info_peer_gifts_widget.cpp | 16 +++++++--- .../settings/settings_credits_graphics.cpp | 8 +++-- 8 files changed, 68 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/boxes/star_gift_box.cpp b/Telegram/SourceFiles/boxes/star_gift_box.cpp index 1708b25725..c44f0e6074 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_box.cpp @@ -1332,7 +1332,9 @@ void SendStarsFormRequest( done(Payments::CheckoutResult::Failed, nullptr); }); }).fail([=](const MTP::Error &error) { - show->showToast(error.type()); + if (!ShowGiftErrorToast(show, error)) { + show->showToast(error.type()); + } done(Payments::CheckoutResult::Failed, nullptr); }).send(); } else if (result == BalanceResult::Cancelled) { @@ -1379,7 +1381,9 @@ void UpgradeGift( formDone(Payments::CheckoutResult::Paid, &result); }).fail([=](const MTP::Error &error) { if (const auto strong = weak.get()) { - strong->showToast(error.type()); + if (!ShowGiftErrorToast(strong->uiShow(), error)) { + strong->showToast(error.type()); + } } formDone(Payments::CheckoutResult::Failed, nullptr); }).send(); @@ -2860,7 +2864,7 @@ void UpdateGiftSellPrice( const auto newAvailableAt = base::unixtime::now() + seconds; unique->canResellAt = newAvailableAt; ShowResaleGiftLater(show, unique); - } else { + } else if (!ShowGiftErrorToast(show, error)) { show->showToast(type); } }).send(); @@ -3061,9 +3065,10 @@ void SendOfferBuyGift( show->session().api().applyUpdates(result); done(true); }).fail([=](const MTP::Error &error) { - if (error.type() == u""_q) { - } else { - show->showToast(error.type()); + const auto type = error.type(); + if (type == u""_q) { + } else if (!ShowGiftErrorToast(show, error)) { + show->showToast(type); } done(false); }).send(); @@ -4297,7 +4302,9 @@ void RequestOurForm( show->showToast(tr::lng_edit_privacy_gifts_restricted(tr::now)); fail(Payments::CheckoutResult::Cancelled); } else { - show->showToast(type); + if (!ShowGiftErrorToast(show, error)) { + show->showToast(type); + } fail(Payments::CheckoutResult::Failed); } }).send(); @@ -4338,6 +4345,16 @@ void ShowGiftTransferredToast( }); } +bool ShowGiftErrorToast( + std::shared_ptr show, + const MTP::Error &error) { + if (error.type() == u"STARGIFT_ALREADY_BURNED"_q) { + show->showToast(tr::lng_gift_burned_message(tr::now)); + return true; + } + return false; +} + CreditsAmount StarsFromTon( not_null session, CreditsAmount ton) { diff --git a/Telegram/SourceFiles/boxes/star_gift_box.h b/Telegram/SourceFiles/boxes/star_gift_box.h index 2ca942135b..0adfb1a309 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.h +++ b/Telegram/SourceFiles/boxes/star_gift_box.h @@ -39,6 +39,10 @@ namespace Payments { enum class CheckoutResult; } // namespace Payments +namespace MTP { +class Error; +} // namespace MTP + namespace Settings { struct GiftWearBoxStyleOverride; struct CreditsEntryBoxStyleOverrides; @@ -57,6 +61,7 @@ namespace Ui { class RpWidget; class PopupMenu; class GenericBox; +class Show; class VerticalLayout; void ChooseStarGiftRecipient( @@ -146,6 +151,10 @@ void ShowGiftTransferredToast( not_null to, const Data::UniqueGift &gift); +[[nodiscard]] bool ShowGiftErrorToast( + std::shared_ptr show, + const MTP::Error &error); + [[nodiscard]] CreditsAmount StarsFromTon( not_null session, CreditsAmount ton); diff --git a/Telegram/SourceFiles/boxes/transfer_gift_box.cpp b/Telegram/SourceFiles/boxes/transfer_gift_box.cpp index 032d8a1dfb..7a093169f9 100644 --- a/Telegram/SourceFiles/boxes/transfer_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/transfer_gift_box.cpp @@ -484,7 +484,9 @@ void TransferGift( ShowTransferGiftLater(strong->uiShow(), gift); } } else if (const auto strong = weak.get()) { - strong->showToast(error.type()); + if (!Ui::ShowGiftErrorToast(strong->uiShow(), error)) { + strong->showToast(type); + } } }).send(); } else { @@ -512,7 +514,9 @@ void ResolveGiftSaleOffer( session->api().applyUpdates(result); done(true); }).fail([=](const MTP::Error &error) { - show->showToast(error.type()); + if (!Ui::ShowGiftErrorToast(show, error)) { + show->showToast(error.type()); + } done(false); }).send(); } diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 599560abda..d6b1e7db5e 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -2031,7 +2031,9 @@ void ResolveAndShowUniqueGift( } }).fail([=](const MTP::Error &error) { clear(); - show->showToast(u"Error: "_q + error.type()); + if (!Ui::ShowGiftErrorToast(show, error)) { + show->showToast(u"Error: "_q + error.type()); + } }).send(); } diff --git a/Telegram/SourceFiles/data/components/recent_shared_media_gifts.cpp b/Telegram/SourceFiles/data/components/recent_shared_media_gifts.cpp index 7b321edb38..2cafa5dace 100644 --- a/Telegram/SourceFiles/data/components/recent_shared_media_gifts.cpp +++ b/Telegram/SourceFiles/data/components/recent_shared_media_gifts.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_credits.h" // InputSavedStarGiftId #include "api/api_premium.h" #include "apiwrap.h" +#include "boxes/star_gift_box.h" #include "chat_helpers/compose/compose_show.h" #include "data/data_document.h" #include "data/data_peer.h" @@ -145,7 +146,9 @@ void RecentSharedMediaGifts::updatePinnedOrder( done(); } }).fail([=](const MTP::Error &error) { - show->showToast(error.type()); + if (!Ui::ShowGiftErrorToast(show, error)) { + show->showToast(error.type()); + } }).send(); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp b/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp index 63c98b5aac..548d3e90b7 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp @@ -570,8 +570,10 @@ ClickHandlerPtr OpenStarGiftLink(not_null item) { }).fail([=](const MTP::Error &error) { *requesting = false; if (const auto window = weak.get()) { - window->showToast(error.type()); - quick(window); + if (!Ui::ShowGiftErrorToast(window->uiShow(), error)) { + window->showToast(error.type()); + quick(window); + } } }).send(); }; diff --git a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp index 8e1d863418..f27c2b02dc 100644 --- a/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp +++ b/Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp @@ -1143,7 +1143,9 @@ void InnerWidget::addGiftToCollection( refreshCollectionsTabs(); } }).fail([=, show = _window->uiShow()](const MTP::Error &error) { - show->showToast(error.type()); + if (!Ui::ShowGiftErrorToast(show, error)) { + show->showToast(error.type()); + } }).send(); } @@ -1460,7 +1462,9 @@ void InnerWidget::editCollectionGifts(int id) { }).fail([=](const MTP::Error &error) { if (const auto strong = weakBox.get()) { state->saving = false; - strong->uiShow()->showToast(error.type()); + if (!Ui::ShowGiftErrorToast(strong->uiShow(), error)) { + strong->uiShow()->showToast(error.type()); + } } }).send(); }); @@ -1650,7 +1654,9 @@ void InnerWidget::removeGiftFromCollection( refreshCollectionsTabs(); } }).fail([=, show = _window->uiShow()](const MTP::Error &error) { - show->showToast(error.type()); + if (!Ui::ShowGiftErrorToast(show, error)) { + show->showToast(error.type()); + } }).send(); } @@ -2301,7 +2307,9 @@ void InnerWidget::requestReorder(int fromIndex, int toIndex) { refreshCollectionsTabs(); } }).fail([show = _window->uiShow()](const MTP::Error &error) { - show->showToast(error.type()); + if (!Ui::ShowGiftErrorToast(show, error)) { + show->showToast(error.type()); + } }).send(); } else { _window->session().recentSharedGifts().reorderPinned( diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index 3d0d17b451..42f4109203 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -215,7 +215,9 @@ void ToggleStarGiftSaved( if (const auto onstack = done) { onstack(false); } - show->showToast(error.type()); + if (!Ui::ShowGiftErrorToast(show, error)) { + show->showToast(error.type()); + } }).send(); } @@ -271,7 +273,9 @@ void ConvertStarGift( tr::rich)); done(true); }).fail([=](const MTP::Error &error) { - show->showToast(error.type()); + if (!Ui::ShowGiftErrorToast(show, error)) { + show->showToast(error.type()); + } done(false); }).send(); }