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_peer_values.h" // Data::PeerPremiumValue.
#include "data/data_session.h"
#include "data/data_subscription_option.h"
#include "data/data_user.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
@ -39,11 +40,8 @@ namespace {
constexpr auto kDiscountDivider = 5.;
struct GiftOption final {
QString url;
Ui::Premium::GiftInfo info;
};
using GiftOptions = std::vector<GiftOption>;
using GiftOption = Data::SubscriptionOption;
using GiftOptions = Data::SubscriptionOptions;
GiftOptions GiftOptionFromTL(const MTPDuserFull &data) {
auto result = GiftOptions();
@ -72,7 +70,7 @@ GiftOptions GiftOptionFromTL(const MTPDuserFull &data) {
return std::round(percent * 100. / kDiscountDivider)
* kDiscountDivider;
}();
auto info = Ui::Premium::GiftInfo{
result.push_back({
.duration = Ui::FormatTTL(months * 86400 * 31),
.discount = discount
? QString::fromUtf8("\xe2\x88\x92%1%").arg(discount)
@ -84,8 +82,8 @@ GiftOptions GiftOptionFromTL(const MTPDuserFull &data) {
amount / float64(months),
currency)),
.total = Ui::FillAmountAndCurrency(amount, currency),
};
result.push_back({ .url = botUrl, .info = std::move(info) });
.botUrl = botUrl,
});
}
return result;
}
@ -194,17 +192,10 @@ void GiftBox(
auto text = tr::lng_premium_gift_button(
tr::now,
lt_cost,
options[value].info.total);
options[value].total);
state->buttonText.fire(std::move(text));
});
Ui::Premium::AddGiftOptions(
buttonsParent,
group,
ranges::views::all(
options
) | ranges::views::transform([](const GiftOption &option) {
return option.info;
}) | ranges::to_vector);
Ui::Premium::AddGiftOptions(buttonsParent, group, options);
// Footer.
auto terms = object_ptr<Ui::FlatLabel>(
@ -244,7 +235,7 @@ void GiftBox(
const auto value = group->value();
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()) {
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 "data/data_subscription_option.h"
#include "lang/lang_keys.h"
#include "ui/abstract_button.h"
#include "ui/effects/animations.h"
@ -937,7 +938,7 @@ void ShowListBox(
void AddGiftOptions(
not_null<Ui::VerticalLayout*> parent,
std::shared_ptr<Ui::RadiobuttonGroup> group,
std::vector<GiftInfo> gifts) {
std::vector<Data::SubscriptionOption> gifts) {
struct Edges {
Ui::RpWidget *top = nullptr;
@ -952,7 +953,7 @@ void AddGiftOptions(
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(
object_ptr<Ui::AbstractButton>(parent),
st::premiumGiftRowPaddings);

View file

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

View file

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