mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Show nice gift burned error everywhere.
This commit is contained in:
@@ -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<Ui::Show> 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<Main::Session*> session,
|
||||
CreditsAmount ton) {
|
||||
|
||||
@@ -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<PeerData*> to,
|
||||
const Data::UniqueGift &gift);
|
||||
|
||||
[[nodiscard]] bool ShowGiftErrorToast(
|
||||
std::shared_ptr<Ui::Show> show,
|
||||
const MTP::Error &error);
|
||||
|
||||
[[nodiscard]] CreditsAmount StarsFromTon(
|
||||
not_null<Main::Session*> session,
|
||||
CreditsAmount ton);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -570,8 +570,10 @@ ClickHandlerPtr OpenStarGiftLink(not_null<HistoryItem*> 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();
|
||||
};
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user