mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Changed calculation of discount for premium gifts relative to smallest.
This commit is contained in:
parent
d2170232af
commit
152bcb3570
2 changed files with 17 additions and 19 deletions
|
@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "boxes/gift_premium_box.h"
|
||||
|
||||
#include "api/api_premium.h"
|
||||
#include "apiwrap.h"
|
||||
#include "base/weak_ptr.h"
|
||||
#include "core/click_handler_types.h" // ClickHandlerContext.
|
||||
|
@ -46,28 +45,27 @@ struct GiftOption final {
|
|||
};
|
||||
using GiftOptions = std::vector<GiftOption>;
|
||||
|
||||
GiftOptions GiftOptionFromTL(
|
||||
const MTPDuserFull &data,
|
||||
int monthlyAmount,
|
||||
QString monthlyCurrency) {
|
||||
GiftOptions GiftOptionFromTL(const MTPDuserFull &data) {
|
||||
auto result = GiftOptions();
|
||||
const auto gifts = data.vpremium_gifts();
|
||||
if (!gifts) {
|
||||
return result;
|
||||
}
|
||||
const auto monthlyAmount = [&] {
|
||||
const auto &min = ranges::min_element(
|
||||
gifts->v,
|
||||
ranges::less(),
|
||||
[](const MTPPremiumGiftOption &o) { return o.data().vamount().v; }
|
||||
)->data();
|
||||
return min.vamount().v / float64(min.vmonths().v);
|
||||
}();
|
||||
result.reserve(gifts->v.size());
|
||||
for (const auto &gift : gifts->v) {
|
||||
const auto &option = gift.match([](const MTPDpremiumGiftOption &d
|
||||
) -> const MTPDpremiumGiftOption & {
|
||||
return d;
|
||||
});
|
||||
const auto &option = gift.data();
|
||||
const auto botUrl = qs(option.vbot_url());
|
||||
const auto months = option.vmonths().v;
|
||||
const auto amount = option.vamount().v;
|
||||
const auto currency = qs(option.vcurrency());
|
||||
if (monthlyCurrency != currency) {
|
||||
monthlyAmount = 500; // 5 USD.
|
||||
}
|
||||
const auto discount = [&] {
|
||||
const auto percent = monthlyAmount * months / float64(amount)
|
||||
- 1.;
|
||||
|
@ -76,7 +74,9 @@ GiftOptions GiftOptionFromTL(
|
|||
}();
|
||||
auto info = Ui::Premium::GiftInfo{
|
||||
.duration = Ui::FormatTTL(months * 86400 * 31),
|
||||
.discount = QString::fromUtf8("\xe2\x88\x92%1%").arg(discount),
|
||||
.discount = discount
|
||||
? QString::fromUtf8("\xe2\x88\x92%1%").arg(discount)
|
||||
: QString(),
|
||||
.perMonth = tr::lng_premium_gift_per(
|
||||
tr::now,
|
||||
lt_cost,
|
||||
|
@ -354,7 +354,6 @@ void GiftPremiumValidator::showBox(not_null<UserData*> user) {
|
|||
if (_requestId) {
|
||||
return;
|
||||
}
|
||||
_controller->session().api().premium().reload();
|
||||
_requestId = _api.request(MTPusers_GetFullUser(
|
||||
user->inputUser
|
||||
)).done([=](const MTPusers_UserFull &result) {
|
||||
|
@ -368,10 +367,7 @@ void GiftPremiumValidator::showBox(not_null<UserData*> user) {
|
|||
_controller->session().data().processChats(result.data().vchats());
|
||||
|
||||
const auto &fullUser = result.data().vfull_user().data();
|
||||
auto options = GiftOptionFromTL(
|
||||
fullUser,
|
||||
_controller->session().api().premium().monthlyAmount(),
|
||||
_controller->session().api().premium().monthlyCurrency());
|
||||
auto options = GiftOptionFromTL(fullUser);
|
||||
if (!options.empty()) {
|
||||
_controller->show(
|
||||
Box(GiftBox, _controller, user, std::move(options)));
|
||||
|
|
|
@ -1005,7 +1005,9 @@ void AddGiftOptions(
|
|||
|
||||
const auto discountFont = st::windowFiltersButton.badgeStyle.font;
|
||||
const auto discountWidth = discountFont->width(info.discount);
|
||||
const auto &discountMargins = st::premiumGiftRowBadgeMargins;
|
||||
const auto &discountMargins = discountWidth
|
||||
? st::premiumGiftRowBadgeMargins
|
||||
: style::margins();
|
||||
const auto discountRect = QRect(
|
||||
left,
|
||||
halfHeight + discountMargins.top(),
|
||||
|
|
Loading…
Add table
Reference in a new issue