mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
Improve upgrade/transfer toasts.
This commit is contained in:
parent
083400d1c2
commit
4f702e12b7
4 changed files with 67 additions and 21 deletions
|
@ -3311,6 +3311,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_gift_upgrade_add_comment" = "Add sender's name and comment";
|
||||
"lng_gift_upgraded_title" = "Gift Upgraded";
|
||||
"lng_gift_upgraded_about" = "Your gift {name} now has unique attributes and can be transferred to others";
|
||||
"lng_gift_transferred_title" = "Gift Transferred";
|
||||
"lng_gift_transferred_about" = "{name} was successfully transferred to {recipient}.";
|
||||
"lng_gift_transfer_title" = "Transfer {name}";
|
||||
"lng_gift_transfer_via_blockchain" = "Send via Blockchain";
|
||||
"lng_gift_transfer_unlocks_days#one" = "unlocks in {count} day";
|
||||
|
|
|
@ -1114,7 +1114,7 @@ void SendGift(
|
|||
void ShowGiftUpgradedToast(
|
||||
base::weak_ptr<Window::SessionController> weak,
|
||||
not_null<Main::Session*> session,
|
||||
const MTPUpdates & result) {
|
||||
const MTPUpdates &result) {
|
||||
const auto gift = FindUniqueGift(session, result);
|
||||
if (const auto strong = gift ? weak.get() : nullptr) {
|
||||
strong->showToast({
|
||||
|
@ -1134,7 +1134,7 @@ void SendStarsFormRequest(
|
|||
Settings::SmallBalanceResult result,
|
||||
uint64 formId,
|
||||
MTPInputInvoice invoice,
|
||||
Fn<void(Payments::CheckoutResult)> done) {
|
||||
Fn<void(Payments::CheckoutResult, const MTPUpdates *)> done) {
|
||||
using BalanceResult = Settings::SmallBalanceResult;
|
||||
const auto session = &controller->session();
|
||||
if (result == BalanceResult::Success
|
||||
|
@ -1146,20 +1146,20 @@ void SendStarsFormRequest(
|
|||
)).done([=](const MTPpayments_PaymentResult &result) {
|
||||
result.match([&](const MTPDpayments_paymentResult &data) {
|
||||
session->api().applyUpdates(data.vupdates());
|
||||
ShowGiftUpgradedToast(weak, session, data.vupdates());
|
||||
}, [](const MTPDpayments_paymentVerificationNeeded &data) {
|
||||
done(Payments::CheckoutResult::Paid, &data.vupdates());
|
||||
}, [&](const MTPDpayments_paymentVerificationNeeded &data) {
|
||||
done(Payments::CheckoutResult::Failed, nullptr);
|
||||
});
|
||||
done(Payments::CheckoutResult::Paid);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->showToast(error.type());
|
||||
}
|
||||
done(Payments::CheckoutResult::Failed);
|
||||
done(Payments::CheckoutResult::Failed, nullptr);
|
||||
}).send();
|
||||
} else if (result == BalanceResult::Cancelled) {
|
||||
done(Payments::CheckoutResult::Cancelled);
|
||||
done(Payments::CheckoutResult::Cancelled, nullptr);
|
||||
} else {
|
||||
done(Payments::CheckoutResult::Failed);
|
||||
done(Payments::CheckoutResult::Failed, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1170,21 +1170,30 @@ void UpgradeGift(
|
|||
int stars,
|
||||
Fn<void(Payments::CheckoutResult)> done) {
|
||||
const auto session = &window->session();
|
||||
const auto weak = base::make_weak(window);
|
||||
auto formDone = [=](
|
||||
Payments::CheckoutResult result,
|
||||
const MTPUpdates *updates) {
|
||||
if (result == Payments::CheckoutResult::Paid && updates) {
|
||||
if (const auto strong = weak.get()) {
|
||||
ShowGiftUpgradedToast(strong, session, *updates);
|
||||
}
|
||||
}
|
||||
done(result);
|
||||
};
|
||||
if (stars <= 0) {
|
||||
using Flag = MTPpayments_UpgradeStarGift::Flag;
|
||||
const auto weak = base::make_weak(window);
|
||||
session->api().request(MTPpayments_UpgradeStarGift(
|
||||
MTP_flags(keepDetails ? Flag::f_keep_original_details : Flag()),
|
||||
MTP_int(messageId.bare)
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
session->api().applyUpdates(result);
|
||||
ShowGiftUpgradedToast(weak, session, result);
|
||||
done(Payments::CheckoutResult::Paid);
|
||||
formDone(Payments::CheckoutResult::Paid, &result);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->showToast(error.type());
|
||||
}
|
||||
done(Payments::CheckoutResult::Failed);
|
||||
formDone(Payments::CheckoutResult::Failed, nullptr);
|
||||
}).send();
|
||||
return;
|
||||
}
|
||||
|
@ -1194,7 +1203,7 @@ void UpgradeGift(
|
|||
MTP_inputInvoiceStarGiftUpgrade(
|
||||
MTP_flags(keepDetails ? Flag::f_keep_original_details : Flag()),
|
||||
MTP_int(messageId.bare)),
|
||||
std::move(done));
|
||||
std::move(formDone));
|
||||
}
|
||||
|
||||
void SoldOutBox(
|
||||
|
@ -2295,7 +2304,7 @@ void AddUniqueCloseButton(not_null<GenericBox*> box) {
|
|||
void RequestStarsFormAndSubmit(
|
||||
not_null<Window::SessionController*> window,
|
||||
MTPInputInvoice invoice,
|
||||
Fn<void(Payments::CheckoutResult)> done) {
|
||||
Fn<void(Payments::CheckoutResult, const MTPUpdates *)> done) {
|
||||
const auto weak = base::make_weak(window);
|
||||
window->session().api().request(MTPpayments_GetPaymentForm(
|
||||
MTP_flags(0),
|
||||
|
@ -2307,7 +2316,7 @@ void RequestStarsFormAndSubmit(
|
|||
const auto prices = data.vinvoice().data().vprices().v;
|
||||
const auto strong = weak.get();
|
||||
if (!strong) {
|
||||
done(Payments::CheckoutResult::Failed);
|
||||
done(Payments::CheckoutResult::Failed, nullptr);
|
||||
return;
|
||||
}
|
||||
const auto ready = [=](Settings::SmallBalanceResult result) {
|
||||
|
@ -2319,14 +2328,34 @@ void RequestStarsFormAndSubmit(
|
|||
Settings::SmallBalanceDeepLink{},
|
||||
ready);
|
||||
}, [&](const auto &) {
|
||||
done(Payments::CheckoutResult::Failed);
|
||||
done(Payments::CheckoutResult::Failed, nullptr);
|
||||
});
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->showToast(error.type());
|
||||
}
|
||||
done(Payments::CheckoutResult::Failed);
|
||||
done(Payments::CheckoutResult::Failed, nullptr);
|
||||
}).send();
|
||||
}
|
||||
|
||||
void ShowGiftTransferredToast(
|
||||
base::weak_ptr<Window::SessionController> weak,
|
||||
not_null<PeerData*> to,
|
||||
const MTPUpdates &result) {
|
||||
const auto gift = FindUniqueGift(&to->session(), result);
|
||||
if (const auto strong = gift ? weak.get() : nullptr) {
|
||||
strong->showToast({
|
||||
.title = tr::lng_gift_transferred_title(tr::now),
|
||||
.text = tr::lng_gift_transferred_about(
|
||||
tr::now,
|
||||
lt_name,
|
||||
Text::Bold(Data::UniqueGiftName(*gift)),
|
||||
lt_recipient,
|
||||
Text::Bold(to->shortName()),
|
||||
Ui::Text::WithEntities),
|
||||
.duration = kUpgradeDoneToastDuration,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -67,6 +67,11 @@ void AddUniqueCloseButton(not_null<GenericBox*> box);
|
|||
void RequestStarsFormAndSubmit(
|
||||
not_null<Window::SessionController*> window,
|
||||
MTPInputInvoice invoice,
|
||||
Fn<void(Payments::CheckoutResult)> done);
|
||||
Fn<void(Payments::CheckoutResult, const MTPUpdates *)> done);
|
||||
|
||||
void ShowGiftTransferredToast(
|
||||
base::weak_ptr<Window::SessionController> weak,
|
||||
not_null<PeerData*> to,
|
||||
const MTPUpdates &result);
|
||||
|
||||
} // namespace Ui
|
||||
|
|
|
@ -290,18 +290,28 @@ void TransferGift(
|
|||
|
||||
const auto session = &window->session();
|
||||
const auto weak = base::make_weak(window);
|
||||
auto formDone = [=](
|
||||
Payments::CheckoutResult result,
|
||||
const MTPUpdates *updates) {
|
||||
if (result == Payments::CheckoutResult::Paid && updates) {
|
||||
if (const auto strong = weak.get()) {
|
||||
Ui::ShowGiftTransferredToast(strong, to, *updates);
|
||||
}
|
||||
}
|
||||
done(result);
|
||||
};
|
||||
if (gift->starsForTransfer <= 0) {
|
||||
session->api().request(MTPpayments_TransferStarGift(
|
||||
MTP_int(messageId.bare),
|
||||
to->asUser()->inputUser
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
session->api().applyUpdates(result);
|
||||
done(Payments::CheckoutResult::Paid);
|
||||
formDone(Payments::CheckoutResult::Paid, &result);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->showToast(error.type());
|
||||
}
|
||||
done(Payments::CheckoutResult::Failed);
|
||||
formDone(Payments::CheckoutResult::Failed, nullptr);
|
||||
}).send();
|
||||
return;
|
||||
}
|
||||
|
@ -310,7 +320,7 @@ void TransferGift(
|
|||
MTP_inputInvoiceStarGiftTransfer(
|
||||
MTP_int(messageId.bare),
|
||||
to->asUser()->inputUser),
|
||||
std::move(done));
|
||||
std::move(formDone));
|
||||
}
|
||||
|
||||
void ShowTransferToBox(
|
||||
|
|
Loading…
Add table
Reference in a new issue