Skip to content

Commit 2aae67c

Browse files
committed
Show nice gift burned error everywhere.
1 parent efc31d6 commit 2aae67c

File tree

8 files changed

+68
-19
lines changed

8 files changed

+68
-19
lines changed

‎Telegram/SourceFiles/boxes/star_gift_box.cpp‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,9 @@ void SendStarsFormRequest(
13321332
done(Payments::CheckoutResult::Failed, nullptr);
13331333
});
13341334
}).fail([=](const MTP::Error &error) {
1335-
show->showToast(error.type());
1335+
if (!ShowGiftErrorToast(show, error)) {
1336+
show->showToast(error.type());
1337+
}
13361338
done(Payments::CheckoutResult::Failed, nullptr);
13371339
}).send();
13381340
} else if (result == BalanceResult::Cancelled) {
@@ -1379,7 +1381,9 @@ void UpgradeGift(
13791381
formDone(Payments::CheckoutResult::Paid, &result);
13801382
}).fail([=](const MTP::Error &error) {
13811383
if (const auto strong = weak.get()) {
1382-
strong->showToast(error.type());
1384+
if (!ShowGiftErrorToast(strong->uiShow(), error)) {
1385+
strong->showToast(error.type());
1386+
}
13831387
}
13841388
formDone(Payments::CheckoutResult::Failed, nullptr);
13851389
}).send();
@@ -2860,7 +2864,7 @@ void UpdateGiftSellPrice(
28602864
const auto newAvailableAt = base::unixtime::now() + seconds;
28612865
unique->canResellAt = newAvailableAt;
28622866
ShowResaleGiftLater(show, unique);
2863-
} else {
2867+
} else if (!ShowGiftErrorToast(show, error)) {
28642868
show->showToast(type);
28652869
}
28662870
}).send();
@@ -3061,9 +3065,10 @@ void SendOfferBuyGift(
30613065
show->session().api().applyUpdates(result);
30623066
done(true);
30633067
}).fail([=](const MTP::Error &error) {
3064-
if (error.type() == u""_q) {
3065-
} else {
3066-
show->showToast(error.type());
3068+
const auto type = error.type();
3069+
if (type == u""_q) {
3070+
} else if (!ShowGiftErrorToast(show, error)) {
3071+
show->showToast(type);
30673072
}
30683073
done(false);
30693074
}).send();
@@ -4297,7 +4302,9 @@ void RequestOurForm(
42974302
show->showToast(tr::lng_edit_privacy_gifts_restricted(tr::now));
42984303
fail(Payments::CheckoutResult::Cancelled);
42994304
} else {
4300-
show->showToast(type);
4305+
if (!ShowGiftErrorToast(show, error)) {
4306+
show->showToast(type);
4307+
}
43014308
fail(Payments::CheckoutResult::Failed);
43024309
}
43034310
}).send();
@@ -4338,6 +4345,16 @@ void ShowGiftTransferredToast(
43384345
});
43394346
}
43404347

4348+
bool ShowGiftErrorToast(
4349+
std::shared_ptr<Ui::Show> show,
4350+
const MTP::Error &error) {
4351+
if (error.type() == u"STARGIFT_ALREADY_BURNED"_q) {
4352+
show->showToast(tr::lng_gift_burned_message(tr::now));
4353+
return true;
4354+
}
4355+
return false;
4356+
}
4357+
43414358
CreditsAmount StarsFromTon(
43424359
not_null<Main::Session*> session,
43434360
CreditsAmount ton) {

‎Telegram/SourceFiles/boxes/star_gift_box.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ namespace Payments {
3939
enum class CheckoutResult;
4040
} // namespace Payments
4141

42+
namespace MTP {
43+
class Error;
44+
} // namespace MTP
45+
4246
namespace Settings {
4347
struct GiftWearBoxStyleOverride;
4448
struct CreditsEntryBoxStyleOverrides;
@@ -57,6 +61,7 @@ namespace Ui {
5761
class RpWidget;
5862
class PopupMenu;
5963
class GenericBox;
64+
class Show;
6065
class VerticalLayout;
6166

6267
void ChooseStarGiftRecipient(
@@ -146,6 +151,10 @@ void ShowGiftTransferredToast(
146151
not_null<PeerData*> to,
147152
const Data::UniqueGift &gift);
148153

154+
[[nodiscard]] bool ShowGiftErrorToast(
155+
std::shared_ptr<Ui::Show> show,
156+
const MTP::Error &error);
157+
149158
[[nodiscard]] CreditsAmount StarsFromTon(
150159
not_null<Main::Session*> session,
151160
CreditsAmount ton);

‎Telegram/SourceFiles/boxes/transfer_gift_box.cpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,9 @@ void TransferGift(
484484
ShowTransferGiftLater(strong->uiShow(), gift);
485485
}
486486
} else if (const auto strong = weak.get()) {
487-
strong->showToast(error.type());
487+
if (!Ui::ShowGiftErrorToast(strong->uiShow(), error)) {
488+
strong->showToast(type);
489+
}
488490
}
489491
}).send();
490492
} else {
@@ -512,7 +514,9 @@ void ResolveGiftSaleOffer(
512514
session->api().applyUpdates(result);
513515
done(true);
514516
}).fail([=](const MTP::Error &error) {
515-
show->showToast(error.type());
517+
if (!Ui::ShowGiftErrorToast(show, error)) {
518+
show->showToast(error.type());
519+
}
516520
done(false);
517521
}).send();
518522
}

‎Telegram/SourceFiles/core/local_url_handlers.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2031,7 +2031,9 @@ void ResolveAndShowUniqueGift(
20312031
}
20322032
}).fail([=](const MTP::Error &error) {
20332033
clear();
2034-
show->showToast(u"Error: "_q + error.type());
2034+
if (!Ui::ShowGiftErrorToast(show, error)) {
2035+
show->showToast(u"Error: "_q + error.type());
2036+
}
20352037
}).send();
20362038
}
20372039

‎Telegram/SourceFiles/data/components/recent_shared_media_gifts.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ For license and copyright information please follow this link:
1010
#include "api/api_credits.h" // InputSavedStarGiftId
1111
#include "api/api_premium.h"
1212
#include "apiwrap.h"
13+
#include "boxes/star_gift_box.h"
1314
#include "chat_helpers/compose/compose_show.h"
1415
#include "data/data_document.h"
1516
#include "data/data_peer.h"
@@ -145,7 +146,9 @@ void RecentSharedMediaGifts::updatePinnedOrder(
145146
done();
146147
}
147148
}).fail([=](const MTP::Error &error) {
148-
show->showToast(error.type());
149+
if (!Ui::ShowGiftErrorToast(show, error)) {
150+
show->showToast(error.type());
151+
}
149152
}).send();
150153
}
151154

‎Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,10 @@ ClickHandlerPtr OpenStarGiftLink(not_null<HistoryItem*> item) {
570570
}).fail([=](const MTP::Error &error) {
571571
*requesting = false;
572572
if (const auto window = weak.get()) {
573-
window->showToast(error.type());
574-
quick(window);
573+
if (!Ui::ShowGiftErrorToast(window->uiShow(), error)) {
574+
window->showToast(error.type());
575+
quick(window);
576+
}
575577
}
576578
}).send();
577579
};

‎Telegram/SourceFiles/info/peer_gifts/info_peer_gifts_widget.cpp‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,9 @@ void InnerWidget::addGiftToCollection(
11431143
refreshCollectionsTabs();
11441144
}
11451145
}).fail([=, show = _window->uiShow()](const MTP::Error &error) {
1146-
show->showToast(error.type());
1146+
if (!Ui::ShowGiftErrorToast(show, error)) {
1147+
show->showToast(error.type());
1148+
}
11471149
}).send();
11481150
}
11491151

@@ -1460,7 +1462,9 @@ void InnerWidget::editCollectionGifts(int id) {
14601462
}).fail([=](const MTP::Error &error) {
14611463
if (const auto strong = weakBox.get()) {
14621464
state->saving = false;
1463-
strong->uiShow()->showToast(error.type());
1465+
if (!Ui::ShowGiftErrorToast(strong->uiShow(), error)) {
1466+
strong->uiShow()->showToast(error.type());
1467+
}
14641468
}
14651469
}).send();
14661470
});
@@ -1650,7 +1654,9 @@ void InnerWidget::removeGiftFromCollection(
16501654
refreshCollectionsTabs();
16511655
}
16521656
}).fail([=, show = _window->uiShow()](const MTP::Error &error) {
1653-
show->showToast(error.type());
1657+
if (!Ui::ShowGiftErrorToast(show, error)) {
1658+
show->showToast(error.type());
1659+
}
16541660
}).send();
16551661
}
16561662

@@ -2301,7 +2307,9 @@ void InnerWidget::requestReorder(int fromIndex, int toIndex) {
23012307
refreshCollectionsTabs();
23022308
}
23032309
}).fail([show = _window->uiShow()](const MTP::Error &error) {
2304-
show->showToast(error.type());
2310+
if (!Ui::ShowGiftErrorToast(show, error)) {
2311+
show->showToast(error.type());
2312+
}
23052313
}).send();
23062314
} else {
23072315
_window->session().recentSharedGifts().reorderPinned(

‎Telegram/SourceFiles/settings/settings_credits_graphics.cpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ void ToggleStarGiftSaved(
215215
if (const auto onstack = done) {
216216
onstack(false);
217217
}
218-
show->showToast(error.type());
218+
if (!Ui::ShowGiftErrorToast(show, error)) {
219+
show->showToast(error.type());
220+
}
219221
}).send();
220222
}
221223

@@ -271,7 +273,9 @@ void ConvertStarGift(
271273
tr::rich));
272274
done(true);
273275
}).fail([=](const MTP::Error &error) {
274-
show->showToast(error.type());
276+
if (!Ui::ShowGiftErrorToast(show, error)) {
277+
show->showToast(error.type());
278+
}
275279
done(false);
276280
}).send();
277281
}

0 commit comments

Comments
 (0)