mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Update API scheme, parse premium gifts for stars.
This commit is contained in:
parent
37dd648686
commit
928be4151b
6 changed files with 70 additions and 26 deletions
|
@ -3341,6 +3341,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_gift_send_anonymous" = "Hide My Name";
|
"lng_gift_send_anonymous" = "Hide My Name";
|
||||||
"lng_gift_send_anonymous_self" = "Hide my name and message from visitors to my profile.";
|
"lng_gift_send_anonymous_self" = "Hide my name and message from visitors to my profile.";
|
||||||
"lng_gift_send_anonymous_about" = "You can hide your name and message from visitors to {user}'s profile. {recipient} will still see your name and message.";
|
"lng_gift_send_anonymous_about" = "You can hide your name and message from visitors to {user}'s profile. {recipient} will still see your name and message.";
|
||||||
|
"lng_gift_send_anonymous_about_paid" = "You can hide your name from visitors to {user}'s profile. {recipient} will still see your name.";
|
||||||
"lng_gift_send_anonymous_about_channel" = "You can hide your name and message from all visitors of this channel except its admins.";
|
"lng_gift_send_anonymous_about_channel" = "You can hide your name and message from all visitors of this channel except its admins.";
|
||||||
"lng_gift_send_unique" = "Make Unique for {price}";
|
"lng_gift_send_unique" = "Make Unique for {price}";
|
||||||
"lng_gift_send_unique_about" = "Enable this to let {user} turn your gift into a unique collectible. {link}";
|
"lng_gift_send_unique_about" = "Enable this to let {user} turn your gift into a unique collectible. {link}";
|
||||||
|
|
|
@ -482,6 +482,7 @@ rpl::producer<rpl::no_value, QString> PremiumGiftCodeOptions::request() {
|
||||||
const auto token = Token{ data.vusers().v, data.vmonths().v };
|
const auto token = Token{ data.vusers().v, data.vmonths().v };
|
||||||
_stores[token] = Store{
|
_stores[token] = Store{
|
||||||
.amount = data.vamount().v,
|
.amount = data.vamount().v,
|
||||||
|
.currency = qs(data.vcurrency()),
|
||||||
.product = qs(data.vstore_product().value_or_empty()),
|
.product = qs(data.vstore_product().value_or_empty()),
|
||||||
.quantity = data.vstore_quantity().value_or_empty(),
|
.quantity = data.vstore_quantity().value_or_empty(),
|
||||||
};
|
};
|
||||||
|
@ -490,14 +491,14 @@ rpl::producer<rpl::no_value, QString> PremiumGiftCodeOptions::request() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const auto &[amount, tlOptions] : tlMapOptions) {
|
for (const auto &[amount, tlOptions] : tlMapOptions) {
|
||||||
if (amount == 1 && _optionsForOnePerson.currency.isEmpty()) {
|
if (amount == 1 && _optionsForOnePerson.currencies.empty()) {
|
||||||
_optionsForOnePerson.currency = qs(
|
|
||||||
tlOptions.front().data().vcurrency());
|
|
||||||
for (const auto &option : tlOptions) {
|
for (const auto &option : tlOptions) {
|
||||||
_optionsForOnePerson.months.push_back(
|
_optionsForOnePerson.months.push_back(
|
||||||
option.data().vmonths().v);
|
option.data().vmonths().v);
|
||||||
_optionsForOnePerson.totalCosts.push_back(
|
_optionsForOnePerson.totalCosts.push_back(
|
||||||
option.data().vamount().v);
|
option.data().vamount().v);
|
||||||
|
_optionsForOnePerson.currencies.push_back(
|
||||||
|
qs(option.data().vcurrency()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_subscriptionOptions[amount] = GiftCodesFromTL(tlOptions);
|
_subscriptionOptions[amount] = GiftCodesFromTL(tlOptions);
|
||||||
|
@ -555,7 +556,7 @@ Payments::InvoicePremiumGiftCode PremiumGiftCodeOptions::invoice(
|
||||||
const auto token = Token{ users, months };
|
const auto token = Token{ users, months };
|
||||||
const auto &store = _stores[token];
|
const auto &store = _stores[token];
|
||||||
return Payments::InvoicePremiumGiftCode{
|
return Payments::InvoicePremiumGiftCode{
|
||||||
.currency = _optionsForOnePerson.currency,
|
.currency = store.currency,
|
||||||
.storeProduct = store.product,
|
.storeProduct = store.product,
|
||||||
.randomId = randomId,
|
.randomId = randomId,
|
||||||
.amount = store.amount,
|
.amount = store.amount,
|
||||||
|
@ -568,14 +569,15 @@ Payments::InvoicePremiumGiftCode PremiumGiftCodeOptions::invoice(
|
||||||
std::vector<GiftOptionData> PremiumGiftCodeOptions::optionsForPeer() const {
|
std::vector<GiftOptionData> PremiumGiftCodeOptions::optionsForPeer() const {
|
||||||
auto result = std::vector<GiftOptionData>();
|
auto result = std::vector<GiftOptionData>();
|
||||||
|
|
||||||
if (!_optionsForOnePerson.currency.isEmpty()) {
|
if (!_optionsForOnePerson.currencies.empty()) {
|
||||||
const auto count = int(_optionsForOnePerson.months.size());
|
const auto count = int(_optionsForOnePerson.months.size());
|
||||||
result.reserve(count);
|
result.reserve(count);
|
||||||
for (auto i = 0; i != count; ++i) {
|
for (auto i = 0; i != count; ++i) {
|
||||||
Assert(i < _optionsForOnePerson.totalCosts.size());
|
Assert(i < _optionsForOnePerson.totalCosts.size());
|
||||||
|
Assert(i < _optionsForOnePerson.currencies.size());
|
||||||
result.push_back({
|
result.push_back({
|
||||||
.cost = _optionsForOnePerson.totalCosts[i],
|
.cost = _optionsForOnePerson.totalCosts[i],
|
||||||
.currency = _optionsForOnePerson.currency,
|
.currency = _optionsForOnePerson.currencies[i],
|
||||||
.months = _optionsForOnePerson.months[i],
|
.months = _optionsForOnePerson.months[i],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -596,7 +598,7 @@ Data::PremiumSubscriptionOptions PremiumGiftCodeOptions::options(int amount) {
|
||||||
MTP_int(_optionsForOnePerson.months[i]),
|
MTP_int(_optionsForOnePerson.months[i]),
|
||||||
MTPstring(),
|
MTPstring(),
|
||||||
MTPint(),
|
MTPint(),
|
||||||
MTP_string(_optionsForOnePerson.currency),
|
MTP_string(_optionsForOnePerson.currencies[i]),
|
||||||
MTP_long(_optionsForOnePerson.totalCosts[i] * amount)));
|
MTP_long(_optionsForOnePerson.totalCosts[i] * amount)));
|
||||||
}
|
}
|
||||||
_subscriptionOptions[amount] = GiftCodesFromTL(tlOptions);
|
_subscriptionOptions[amount] = GiftCodesFromTL(tlOptions);
|
||||||
|
|
|
@ -209,6 +209,7 @@ private:
|
||||||
};
|
};
|
||||||
struct Store final {
|
struct Store final {
|
||||||
uint64 amount = 0;
|
uint64 amount = 0;
|
||||||
|
QString currency;
|
||||||
QString product;
|
QString product;
|
||||||
int quantity = 0;
|
int quantity = 0;
|
||||||
};
|
};
|
||||||
|
@ -219,7 +220,7 @@ private:
|
||||||
struct {
|
struct {
|
||||||
std::vector<int> months;
|
std::vector<int> months;
|
||||||
std::vector<int64> totalCosts;
|
std::vector<int64> totalCosts;
|
||||||
QString currency;
|
std::vector<QString> currencies;
|
||||||
} _optionsForOnePerson;
|
} _optionsForOnePerson;
|
||||||
|
|
||||||
std::vector<int> _availablePresets;
|
std::vector<int> _availablePresets;
|
||||||
|
|
|
@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "chat_helpers/tabbed_panel.h"
|
#include "chat_helpers/tabbed_panel.h"
|
||||||
#include "chat_helpers/tabbed_selector.h"
|
#include "chat_helpers/tabbed_selector.h"
|
||||||
#include "core/ui_integration.h"
|
#include "core/ui_integration.h"
|
||||||
|
#include "data/data_changes.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_credits.h"
|
#include "data/data_credits.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
|
@ -80,6 +81,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/checkbox.h"
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "ui/widgets/popup_menu.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "ui/widgets/shadow.h"
|
#include "ui/widgets/shadow.h"
|
||||||
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
#include "window/section_widget.h"
|
#include "window/section_widget.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
|
@ -622,14 +624,27 @@ void PreviewWrap::paintEvent(QPaintEvent *e) {
|
||||||
list.reserve(options.size());
|
list.reserve(options.size());
|
||||||
auto minMonthsGift = GiftTypePremium();
|
auto minMonthsGift = GiftTypePremium();
|
||||||
for (const auto &option : options) {
|
for (const auto &option : options) {
|
||||||
list.push_back({
|
if (option.currency != kCreditsCurrency) {
|
||||||
.cost = option.cost,
|
list.push_back({
|
||||||
.currency = option.currency,
|
.cost = option.cost,
|
||||||
.months = option.months,
|
.currency = option.currency,
|
||||||
});
|
.months = option.months,
|
||||||
if (!minMonthsGift.months
|
});
|
||||||
|| option.months < minMonthsGift.months) {
|
if (!minMonthsGift.months
|
||||||
minMonthsGift = list.back();
|
|| option.months < minMonthsGift.months) {
|
||||||
|
minMonthsGift = list.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto &option : options) {
|
||||||
|
if (option.currency == kCreditsCurrency) {
|
||||||
|
const auto i = ranges::find(
|
||||||
|
list,
|
||||||
|
option.months,
|
||||||
|
&GiftTypePremium::months);
|
||||||
|
if (i != end(list)) {
|
||||||
|
i->stars = option.cost;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto &gift : list) {
|
for (auto &gift : list) {
|
||||||
|
@ -1424,6 +1439,7 @@ void SendGiftBox(
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
rpl::variable<GiftDetails> details;
|
rpl::variable<GiftDetails> details;
|
||||||
|
rpl::variable<bool> messageAllowed;
|
||||||
std::shared_ptr<Data::DocumentMedia> media;
|
std::shared_ptr<Data::DocumentMedia> media;
|
||||||
bool submitting = false;
|
bool submitting = false;
|
||||||
};
|
};
|
||||||
|
@ -1432,6 +1448,13 @@ void SendGiftBox(
|
||||||
.descriptor = descriptor,
|
.descriptor = descriptor,
|
||||||
.randomId = base::RandomValue<uint64>(),
|
.randomId = base::RandomValue<uint64>(),
|
||||||
};
|
};
|
||||||
|
peer->updateFull();
|
||||||
|
state->messageAllowed = peer->session().changes().peerFlagsValue(
|
||||||
|
peer,
|
||||||
|
Data::PeerUpdate::Flag::StarsPerMessage
|
||||||
|
) | rpl::map([=] {
|
||||||
|
return peer->starsPerMessageChecked() == 0;
|
||||||
|
});
|
||||||
|
|
||||||
auto cost = state->details.value(
|
auto cost = state->details.value(
|
||||||
) | rpl::map([session](const GiftDetails &details) {
|
) | rpl::map([session](const GiftDetails &details) {
|
||||||
|
@ -1462,10 +1485,17 @@ void SendGiftBox(
|
||||||
peer,
|
peer,
|
||||||
state->details.value()));
|
state->details.value()));
|
||||||
|
|
||||||
|
const auto messageWrap = container->add(
|
||||||
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
|
container,
|
||||||
|
object_ptr<Ui::VerticalLayout>(container)));
|
||||||
|
messageWrap->toggleOn(state->messageAllowed.value());
|
||||||
|
messageWrap->finishAnimating();
|
||||||
|
const auto messageInner = messageWrap->entity();
|
||||||
const auto limit = StarGiftMessageLimit(session);
|
const auto limit = StarGiftMessageLimit(session);
|
||||||
const auto text = AddPartInput(
|
const auto text = AddPartInput(
|
||||||
window,
|
window,
|
||||||
container,
|
messageInner,
|
||||||
box->getDelegate()->outerContainer(),
|
box->getDelegate()->outerContainer(),
|
||||||
tr::lng_gift_send_message(),
|
tr::lng_gift_send_message(),
|
||||||
QString(),
|
QString(),
|
||||||
|
@ -1509,7 +1539,6 @@ void SendGiftBox(
|
||||||
text,
|
text,
|
||||||
session,
|
session,
|
||||||
{ .suggestCustomEmoji = true, .allowCustomWithoutPremium = allow });
|
{ .suggestCustomEmoji = true, .allowCustomWithoutPremium = allow });
|
||||||
|
|
||||||
if (stars) {
|
if (stars) {
|
||||||
const auto cost = stars->info.starsToUpgrade;
|
const auto cost = stars->info.starsToUpgrade;
|
||||||
if (cost > 0 && !peer->isSelf()) {
|
if (cost > 0 && !peer->isSelf()) {
|
||||||
|
@ -1552,7 +1581,7 @@ void SendGiftBox(
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
}
|
}
|
||||||
v::match(descriptor, [&](const GiftTypePremium &) {
|
v::match(descriptor, [&](const GiftTypePremium &) {
|
||||||
AddDividerText(container, tr::lng_gift_send_premium_about(
|
AddDividerText(messageInner, tr::lng_gift_send_premium_about(
|
||||||
lt_user,
|
lt_user,
|
||||||
rpl::single(peer->shortName())));
|
rpl::single(peer->shortName())));
|
||||||
}, [&](const GiftTypeStars &) {
|
}, [&](const GiftTypeStars &) {
|
||||||
|
@ -1560,11 +1589,18 @@ void SendGiftBox(
|
||||||
? tr::lng_gift_send_anonymous_self()
|
? tr::lng_gift_send_anonymous_self()
|
||||||
: peer->isBroadcast()
|
: peer->isBroadcast()
|
||||||
? tr::lng_gift_send_anonymous_about_channel()
|
? tr::lng_gift_send_anonymous_about_channel()
|
||||||
: tr::lng_gift_send_anonymous_about(
|
: rpl::conditional(
|
||||||
lt_user,
|
state->messageAllowed.value(),
|
||||||
rpl::single(peer->shortName()),
|
tr::lng_gift_send_anonymous_about(
|
||||||
lt_recipient,
|
lt_user,
|
||||||
rpl::single(peer->shortName())));
|
rpl::single(peer->shortName()),
|
||||||
|
lt_recipient,
|
||||||
|
rpl::single(peer->shortName())),
|
||||||
|
tr::lng_gift_send_anonymous_about_paid(
|
||||||
|
lt_user,
|
||||||
|
rpl::single(peer->shortName()),
|
||||||
|
lt_recipient,
|
||||||
|
rpl::single(peer->shortName()))));
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto buttonWidth = st::boxWideWidth
|
const auto buttonWidth = st::boxWideWidth
|
||||||
|
@ -1575,7 +1611,10 @@ void SendGiftBox(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state->submitting = true;
|
state->submitting = true;
|
||||||
const auto details = state->details.current();
|
auto details = state->details.current();
|
||||||
|
if (!state->messageAllowed.current()) {
|
||||||
|
details.text = {};
|
||||||
|
}
|
||||||
const auto weak = MakeWeak(box);
|
const auto weak = MakeWeak(box);
|
||||||
const auto done = [=](Payments::CheckoutResult result) {
|
const auto done = [=](Payments::CheckoutResult result) {
|
||||||
if (result == Payments::CheckoutResult::Paid) {
|
if (result == Payments::CheckoutResult::Paid) {
|
||||||
|
|
|
@ -44,6 +44,7 @@ namespace Info::PeerGifts {
|
||||||
struct GiftTypePremium {
|
struct GiftTypePremium {
|
||||||
int64 cost = 0;
|
int64 cost = 0;
|
||||||
QString currency;
|
QString currency;
|
||||||
|
int stars = 0;
|
||||||
int months = 0;
|
int months = 0;
|
||||||
int discountPercent = 0;
|
int discountPercent = 0;
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ messageActionTopicEdit#c0944820 flags:# title:flags.0?string icon_emoji_id:flags
|
||||||
messageActionSuggestProfilePhoto#57de635e photo:Photo = MessageAction;
|
messageActionSuggestProfilePhoto#57de635e photo:Photo = MessageAction;
|
||||||
messageActionRequestedPeer#31518e9b button_id:int peers:Vector<Peer> = MessageAction;
|
messageActionRequestedPeer#31518e9b button_id:int peers:Vector<Peer> = MessageAction;
|
||||||
messageActionSetChatWallPaper#5060a3f4 flags:# same:flags.0?true for_both:flags.1?true wallpaper:WallPaper = MessageAction;
|
messageActionSetChatWallPaper#5060a3f4 flags:# same:flags.0?true for_both:flags.1?true wallpaper:WallPaper = MessageAction;
|
||||||
messageActionGiftCode#56d03994 flags:# via_giveaway:flags.0?true unclaimed:flags.2?true boost_peer:flags.1?Peer months:int slug:string currency:flags.2?string amount:flags.2?long crypto_currency:flags.3?string crypto_amount:flags.3?long message:flags.4?TextWithEntities = MessageAction;
|
messageActionGiftCode#56d03994 flags:# via_giveaway:flags.0?true unclaimed:flags.5?true boost_peer:flags.1?Peer months:int slug:string currency:flags.2?string amount:flags.2?long crypto_currency:flags.3?string crypto_amount:flags.3?long message:flags.4?TextWithEntities = MessageAction;
|
||||||
messageActionGiveawayLaunch#a80f51e4 flags:# stars:flags.0?long = MessageAction;
|
messageActionGiveawayLaunch#a80f51e4 flags:# stars:flags.0?long = MessageAction;
|
||||||
messageActionGiveawayResults#87e2f155 flags:# stars:flags.0?true winners_count:int unclaimed_count:int = MessageAction;
|
messageActionGiveawayResults#87e2f155 flags:# stars:flags.0?true winners_count:int unclaimed_count:int = MessageAction;
|
||||||
messageActionBoostApply#cc02aa6d boosts:int = MessageAction;
|
messageActionBoostApply#cc02aa6d boosts:int = MessageAction;
|
||||||
|
|
Loading…
Add table
Reference in a new issue