mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +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 "boxes/gift_premium_box.h"
|
||||||
|
|
||||||
#include "api/api_premium.h"
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "base/weak_ptr.h"
|
#include "base/weak_ptr.h"
|
||||||
#include "core/click_handler_types.h" // ClickHandlerContext.
|
#include "core/click_handler_types.h" // ClickHandlerContext.
|
||||||
|
@ -46,28 +45,27 @@ struct GiftOption final {
|
||||||
};
|
};
|
||||||
using GiftOptions = std::vector<GiftOption>;
|
using GiftOptions = std::vector<GiftOption>;
|
||||||
|
|
||||||
GiftOptions GiftOptionFromTL(
|
GiftOptions GiftOptionFromTL(const MTPDuserFull &data) {
|
||||||
const MTPDuserFull &data,
|
|
||||||
int monthlyAmount,
|
|
||||||
QString monthlyCurrency) {
|
|
||||||
auto result = GiftOptions();
|
auto result = GiftOptions();
|
||||||
const auto gifts = data.vpremium_gifts();
|
const auto gifts = data.vpremium_gifts();
|
||||||
if (!gifts) {
|
if (!gifts) {
|
||||||
return result;
|
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());
|
result.reserve(gifts->v.size());
|
||||||
for (const auto &gift : gifts->v) {
|
for (const auto &gift : gifts->v) {
|
||||||
const auto &option = gift.match([](const MTPDpremiumGiftOption &d
|
const auto &option = gift.data();
|
||||||
) -> const MTPDpremiumGiftOption & {
|
|
||||||
return d;
|
|
||||||
});
|
|
||||||
const auto botUrl = qs(option.vbot_url());
|
const auto botUrl = qs(option.vbot_url());
|
||||||
const auto months = option.vmonths().v;
|
const auto months = option.vmonths().v;
|
||||||
const auto amount = option.vamount().v;
|
const auto amount = option.vamount().v;
|
||||||
const auto currency = qs(option.vcurrency());
|
const auto currency = qs(option.vcurrency());
|
||||||
if (monthlyCurrency != currency) {
|
|
||||||
monthlyAmount = 500; // 5 USD.
|
|
||||||
}
|
|
||||||
const auto discount = [&] {
|
const auto discount = [&] {
|
||||||
const auto percent = monthlyAmount * months / float64(amount)
|
const auto percent = monthlyAmount * months / float64(amount)
|
||||||
- 1.;
|
- 1.;
|
||||||
|
@ -76,7 +74,9 @@ GiftOptions GiftOptionFromTL(
|
||||||
}();
|
}();
|
||||||
auto info = Ui::Premium::GiftInfo{
|
auto info = Ui::Premium::GiftInfo{
|
||||||
.duration = Ui::FormatTTL(months * 86400 * 31),
|
.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(
|
.perMonth = tr::lng_premium_gift_per(
|
||||||
tr::now,
|
tr::now,
|
||||||
lt_cost,
|
lt_cost,
|
||||||
|
@ -354,7 +354,6 @@ void GiftPremiumValidator::showBox(not_null<UserData*> user) {
|
||||||
if (_requestId) {
|
if (_requestId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_controller->session().api().premium().reload();
|
|
||||||
_requestId = _api.request(MTPusers_GetFullUser(
|
_requestId = _api.request(MTPusers_GetFullUser(
|
||||||
user->inputUser
|
user->inputUser
|
||||||
)).done([=](const MTPusers_UserFull &result) {
|
)).done([=](const MTPusers_UserFull &result) {
|
||||||
|
@ -368,10 +367,7 @@ void GiftPremiumValidator::showBox(not_null<UserData*> user) {
|
||||||
_controller->session().data().processChats(result.data().vchats());
|
_controller->session().data().processChats(result.data().vchats());
|
||||||
|
|
||||||
const auto &fullUser = result.data().vfull_user().data();
|
const auto &fullUser = result.data().vfull_user().data();
|
||||||
auto options = GiftOptionFromTL(
|
auto options = GiftOptionFromTL(fullUser);
|
||||||
fullUser,
|
|
||||||
_controller->session().api().premium().monthlyAmount(),
|
|
||||||
_controller->session().api().premium().monthlyCurrency());
|
|
||||||
if (!options.empty()) {
|
if (!options.empty()) {
|
||||||
_controller->show(
|
_controller->show(
|
||||||
Box(GiftBox, _controller, user, std::move(options)));
|
Box(GiftBox, _controller, user, std::move(options)));
|
||||||
|
|
|
@ -1005,7 +1005,9 @@ void AddGiftOptions(
|
||||||
|
|
||||||
const auto discountFont = st::windowFiltersButton.badgeStyle.font;
|
const auto discountFont = st::windowFiltersButton.badgeStyle.font;
|
||||||
const auto discountWidth = discountFont->width(info.discount);
|
const auto discountWidth = discountFont->width(info.discount);
|
||||||
const auto &discountMargins = st::premiumGiftRowBadgeMargins;
|
const auto &discountMargins = discountWidth
|
||||||
|
? st::premiumGiftRowBadgeMargins
|
||||||
|
: style::margins();
|
||||||
const auto discountRect = QRect(
|
const auto discountRect = QRect(
|
||||||
left,
|
left,
|
||||||
halfHeight + discountMargins.top(),
|
halfHeight + discountMargins.top(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue