Renamed GiftOption to SubscriptionOption.

This commit is contained in:
23rd 2022-08-25 05:14:33 +03:00 committed by John Preston
parent e03eaaaa98
commit fc759ac688
5 changed files with 40 additions and 28 deletions

View file

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_changes.h" #include "data/data_changes.h"
#include "data/data_peer_values.h" // Data::PeerPremiumValue. #include "data/data_peer_values.h" // Data::PeerPremiumValue.
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_subscription_option.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "main/main_session.h" #include "main/main_session.h"
@ -39,11 +40,8 @@ namespace {
constexpr auto kDiscountDivider = 5.; constexpr auto kDiscountDivider = 5.;
struct GiftOption final { using GiftOption = Data::SubscriptionOption;
QString url; using GiftOptions = Data::SubscriptionOptions;
Ui::Premium::GiftInfo info;
};
using GiftOptions = std::vector<GiftOption>;
GiftOptions GiftOptionFromTL(const MTPDuserFull &data) { GiftOptions GiftOptionFromTL(const MTPDuserFull &data) {
auto result = GiftOptions(); auto result = GiftOptions();
@ -72,7 +70,7 @@ GiftOptions GiftOptionFromTL(const MTPDuserFull &data) {
return std::round(percent * 100. / kDiscountDivider) return std::round(percent * 100. / kDiscountDivider)
* kDiscountDivider; * kDiscountDivider;
}(); }();
auto info = Ui::Premium::GiftInfo{ result.push_back({
.duration = Ui::FormatTTL(months * 86400 * 31), .duration = Ui::FormatTTL(months * 86400 * 31),
.discount = discount .discount = discount
? QString::fromUtf8("\xe2\x88\x92%1%").arg(discount) ? QString::fromUtf8("\xe2\x88\x92%1%").arg(discount)
@ -84,8 +82,8 @@ GiftOptions GiftOptionFromTL(const MTPDuserFull &data) {
amount / float64(months), amount / float64(months),
currency)), currency)),
.total = Ui::FillAmountAndCurrency(amount, currency), .total = Ui::FillAmountAndCurrency(amount, currency),
}; .botUrl = botUrl,
result.push_back({ .url = botUrl, .info = std::move(info) }); });
} }
return result; return result;
} }
@ -194,17 +192,10 @@ void GiftBox(
auto text = tr::lng_premium_gift_button( auto text = tr::lng_premium_gift_button(
tr::now, tr::now,
lt_cost, lt_cost,
options[value].info.total); options[value].total);
state->buttonText.fire(std::move(text)); state->buttonText.fire(std::move(text));
}); });
Ui::Premium::AddGiftOptions( Ui::Premium::AddGiftOptions(buttonsParent, group, options);
buttonsParent,
group,
ranges::views::all(
options
) | ranges::views::transform([](const GiftOption &option) {
return option.info;
}) | ranges::to_vector);
// Footer. // Footer.
auto terms = object_ptr<Ui::FlatLabel>( auto terms = object_ptr<Ui::FlatLabel>(
@ -244,7 +235,7 @@ void GiftBox(
const auto value = group->value(); const auto value = group->value();
Assert(value < options.size() && value >= 0); Assert(value < options.size() && value >= 0);
const auto local = Core::TryConvertUrlToLocal(options[value].url); const auto local = Core::TryConvertUrlToLocal(options[value].botUrl);
if (local.isEmpty()) { if (local.isEmpty()) {
return; return;
} }

View file

@ -0,0 +1,21 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace Data {
struct SubscriptionOption {
QString duration;
QString discount;
QString perMonth;
QString total;
QString botUrl;
};
using SubscriptionOptions = std::vector<SubscriptionOption>;
} // namespace Data

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "ui/effects/premium_graphics.h" #include "ui/effects/premium_graphics.h"
#include "data/data_subscription_option.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "ui/abstract_button.h" #include "ui/abstract_button.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
@ -937,7 +938,7 @@ void ShowListBox(
void AddGiftOptions( void AddGiftOptions(
not_null<Ui::VerticalLayout*> parent, not_null<Ui::VerticalLayout*> parent,
std::shared_ptr<Ui::RadiobuttonGroup> group, std::shared_ptr<Ui::RadiobuttonGroup> group,
std::vector<GiftInfo> gifts) { std::vector<Data::SubscriptionOption> gifts) {
struct Edges { struct Edges {
Ui::RpWidget *top = nullptr; Ui::RpWidget *top = nullptr;
@ -952,7 +953,7 @@ void AddGiftOptions(
const auto stops = GiftGradientStops(); const auto stops = GiftGradientStops();
const auto addRow = [&](const GiftInfo &info, int index) { const auto addRow = [&](const Data::SubscriptionOption &info, int index) {
const auto row = parent->add( const auto row = parent->add(
object_ptr<Ui::AbstractButton>(parent), object_ptr<Ui::AbstractButton>(parent),
st::premiumGiftRowPaddings); st::premiumGiftRowPaddings);

View file

@ -16,6 +16,10 @@ struct phrase;
enum lngtag_count : int; enum lngtag_count : int;
namespace Data {
struct SubscriptionOption;
} // namespace Data
namespace style { namespace style {
struct RoundImageCheckbox; struct RoundImageCheckbox;
struct TextStyle; struct TextStyle;
@ -29,13 +33,6 @@ class VerticalLayout;
namespace Premium { namespace Premium {
struct GiftInfo {
QString duration;
QString discount;
QString perMonth;
QString total;
};
void AddBubbleRow( void AddBubbleRow(
not_null<Ui::VerticalLayout*> parent, not_null<Ui::VerticalLayout*> parent,
rpl::producer<> showFinishes, rpl::producer<> showFinishes,
@ -93,7 +90,7 @@ void ShowListBox(
void AddGiftOptions( void AddGiftOptions(
not_null<Ui::VerticalLayout*> parent, not_null<Ui::VerticalLayout*> parent,
std::shared_ptr<Ui::RadiobuttonGroup> group, std::shared_ptr<Ui::RadiobuttonGroup> group,
std::vector<GiftInfo> gifts); std::vector<Data::SubscriptionOption> gifts);
} // namespace Premium } // namespace Premium
} // namespace Ui } // namespace Ui

View file

@ -67,6 +67,8 @@ PRIVATE
countries/countries_instance.cpp countries/countries_instance.cpp
countries/countries_instance.h countries/countries_instance.h
data/data_subscription_option.h
editor/controllers/undo_controller.cpp editor/controllers/undo_controller.cpp
editor/controllers/undo_controller.h editor/controllers/undo_controller.h
editor/editor_crop.cpp editor/editor_crop.cpp