mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added handler to subscribe box when balance is too small.
This commit is contained in:
parent
a13f0cb11e
commit
92f70a0ebb
4 changed files with 74 additions and 18 deletions
|
@ -2418,6 +2418,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_credits_small_balance_title#other" = "{count} Stars Needed";
|
"lng_credits_small_balance_title#other" = "{count} Stars Needed";
|
||||||
"lng_credits_small_balance_about" = "Buy **Stars** and use them on **{bot}** and other miniapps.";
|
"lng_credits_small_balance_about" = "Buy **Stars** and use them on **{bot}** and other miniapps.";
|
||||||
"lng_credits_small_balance_reaction" = "Buy **Stars** and send them to {channel} to support their posts.";
|
"lng_credits_small_balance_reaction" = "Buy **Stars** and send them to {channel} to support their posts.";
|
||||||
|
"lng_credits_small_balance_subscribe" = "Buy **Stars** and subscribe to **{channel}** and other channels.";
|
||||||
"lng_credits_purchase_blocked" = "Sorry, you can't purchase this item with Telegram Stars.";
|
"lng_credits_purchase_blocked" = "Sorry, you can't purchase this item with Telegram Stars.";
|
||||||
|
|
||||||
"lng_credits_gift_title" = "Gift Telegram Stars";
|
"lng_credits_gift_title" = "Gift Telegram Stars";
|
||||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "boxes/premium_limits_box.h"
|
#include "boxes/premium_limits_box.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
|
#include "data/components/credits.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_file_origin.h"
|
#include "data/data_file_origin.h"
|
||||||
#include "data/data_forum.h"
|
#include "data/data_forum.h"
|
||||||
|
@ -21,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "info/profile/info_profile_badge.h"
|
#include "info/profile/info_profile_badge.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "settings/settings_credits_graphics.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "ui/controls/userpic_button.h"
|
#include "ui/controls/userpic_button.h"
|
||||||
#include "ui/effects/premium_graphics.h"
|
#include "ui/effects/premium_graphics.h"
|
||||||
|
@ -35,6 +37,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_chat_helpers.h"
|
#include "styles/style_chat_helpers.h"
|
||||||
|
#include "styles/style_credits.h"
|
||||||
#include "styles/style_info.h"
|
#include "styles/style_info.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_premium.h"
|
#include "styles/style_premium.h"
|
||||||
|
@ -247,15 +250,26 @@ void ConfirmSubscriptionBox(
|
||||||
Ui::Text::RichLangValue),
|
Ui::Text::RichLangValue),
|
||||||
st::inviteLinkSubscribeBoxTerms)));
|
st::inviteLinkSubscribeBoxTerms)));
|
||||||
|
|
||||||
auto confirmText = tr::lng_channel_invite_subscription_button();
|
{
|
||||||
const auto weak = Ui::MakeWeak(box);
|
const auto balance = Settings::AddBalanceWidget(
|
||||||
state->saveButton = box->addButton(std::move(confirmText), [=] {
|
content,
|
||||||
if (state->api) {
|
session->credits().balanceValue(),
|
||||||
return;
|
true);
|
||||||
}
|
session->credits().load(true);
|
||||||
state->api.emplace(&session->mtp());
|
|
||||||
state->loading.force_assign(true);
|
|
||||||
|
|
||||||
|
rpl::combine(
|
||||||
|
balance->sizeValue(),
|
||||||
|
content->sizeValue()
|
||||||
|
) | rpl::start_with_next([=](const QSize &, const QSize &) {
|
||||||
|
balance->moveToRight(
|
||||||
|
st::creditsHistoryRightSkip * 2,
|
||||||
|
st::creditsHistoryRightSkip);
|
||||||
|
balance->update();
|
||||||
|
}, balance->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto sendCredits = [=, weak = Ui::MakeWeak(box)] {
|
||||||
|
const auto show = box->uiShow();
|
||||||
const auto buttonWidth = state->saveButton
|
const auto buttonWidth = state->saveButton
|
||||||
? state->saveButton->width()
|
? state->saveButton->width()
|
||||||
: 0;
|
: 0;
|
||||||
|
@ -264,22 +278,52 @@ void ConfirmSubscriptionBox(
|
||||||
MTP_flags(0),
|
MTP_flags(0),
|
||||||
MTP_long(formId),
|
MTP_long(formId),
|
||||||
MTP_inputInvoiceChatInviteSubscription(MTP_string(hash)))
|
MTP_inputInvoiceChatInviteSubscription(MTP_string(hash)))
|
||||||
).done([=](auto result) {
|
).done([=](const MTPpayments_PaymentResult &result) {
|
||||||
|
state->api = std::nullopt;
|
||||||
|
state->loading.force_assign(false);
|
||||||
|
result.match([&](const MTPDpayments_paymentResult &data) {
|
||||||
|
session->api().applyUpdates(data.vupdates());
|
||||||
|
}, [](const MTPDpayments_paymentVerificationNeeded &data) {
|
||||||
|
});
|
||||||
if (weak) {
|
if (weak) {
|
||||||
state->api = std::nullopt;
|
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
}
|
}
|
||||||
}).fail([=, show = box->uiShow()](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
const auto id = error.type();
|
const auto id = error.type();
|
||||||
if (weak) {
|
if (weak) {
|
||||||
state->api = std::nullopt;
|
state->api = std::nullopt;
|
||||||
}
|
}
|
||||||
show->showToast(id);
|
show->showToast(id);
|
||||||
|
state->loading.force_assign(false);
|
||||||
}).send();
|
}).send();
|
||||||
if (state->saveButton) {
|
if (state->saveButton) {
|
||||||
state->saveButton->resizeToWidth(buttonWidth);
|
state->saveButton->resizeToWidth(buttonWidth);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
auto confirmText = tr::lng_channel_invite_subscription_button();
|
||||||
|
state->saveButton = box->addButton(std::move(confirmText), [=] {
|
||||||
|
if (state->api) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state->api.emplace(&session->mtp());
|
||||||
|
state->loading.force_assign(true);
|
||||||
|
|
||||||
|
const auto done = [=](Settings::SmallBalanceResult result) {
|
||||||
|
if (result == Settings::SmallBalanceResult::Success) {
|
||||||
|
sendCredits();
|
||||||
|
} else {
|
||||||
|
state->api = std::nullopt;
|
||||||
|
state->loading.force_assign(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Settings::MaybeRequestBalanceIncrease(
|
||||||
|
Main::MakeSessionShow(box->uiShow(), session),
|
||||||
|
amount,
|
||||||
|
Settings::SmallBalanceSubscription{ .name = name },
|
||||||
|
done);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (const auto saveButton = state->saveButton) {
|
if (const auto saveButton = state->saveButton) {
|
||||||
using namespace Info::Statistics;
|
using namespace Info::Statistics;
|
||||||
const auto loadingAnimation = InfiniteRadialAnimationWidget(
|
const auto loadingAnimation = InfiniteRadialAnimationWidget(
|
||||||
|
|
|
@ -877,10 +877,12 @@ void SmallBalanceBox(
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto owner = &show->session().data();
|
const auto owner = &show->session().data();
|
||||||
const auto peer = v::match(source, [&](SmallBalanceBot value) {
|
const auto name = v::match(source, [&](SmallBalanceBot value) {
|
||||||
return owner->peer(peerFromUser(value.botId));
|
return owner->peer(peerFromUser(value.botId))->name();
|
||||||
}, [&](SmallBalanceReaction value) {
|
}, [&](SmallBalanceReaction value) {
|
||||||
return owner->peer(peerFromChannel(value.channelId));
|
return owner->peer(peerFromChannel(value.channelId))->name();
|
||||||
|
}, [](SmallBalanceSubscription value) {
|
||||||
|
return value.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
auto needed = show->session().credits().balanceValue(
|
auto needed = show->session().credits().balanceValue(
|
||||||
|
@ -897,14 +899,19 @@ void SmallBalanceBox(
|
||||||
rpl::duplicate(
|
rpl::duplicate(
|
||||||
needed
|
needed
|
||||||
) | rpl::filter(rpl::mappers::_1 > 0) | tr::to_count()),
|
) | rpl::filter(rpl::mappers::_1 > 0) | tr::to_count()),
|
||||||
.about = (peer->isBroadcast()
|
.about = (v::is<SmallBalanceSubscription>(source)
|
||||||
|
? tr::lng_credits_small_balance_subscribe(
|
||||||
|
lt_channel,
|
||||||
|
rpl::single(Ui::Text::Bold(name)),
|
||||||
|
Ui::Text::RichLangValue)
|
||||||
|
: v::is<SmallBalanceReaction>(source)
|
||||||
? tr::lng_credits_small_balance_reaction(
|
? tr::lng_credits_small_balance_reaction(
|
||||||
lt_channel,
|
lt_channel,
|
||||||
rpl::single(Ui::Text::Bold(peer->name())),
|
rpl::single(Ui::Text::Bold(name)),
|
||||||
Ui::Text::RichLangValue)
|
Ui::Text::RichLangValue)
|
||||||
: tr::lng_credits_small_balance_about(
|
: tr::lng_credits_small_balance_about(
|
||||||
lt_bot,
|
lt_bot,
|
||||||
rpl::single(TextWithEntities{ peer->name() }),
|
rpl::single(TextWithEntities{ name }),
|
||||||
Ui::Text::RichLangValue)),
|
Ui::Text::RichLangValue)),
|
||||||
.light = true,
|
.light = true,
|
||||||
.gradientStops = Ui::Premium::CreditsIconGradientStops(),
|
.gradientStops = Ui::Premium::CreditsIconGradientStops(),
|
||||||
|
|
|
@ -93,9 +93,13 @@ struct SmallBalanceBot {
|
||||||
struct SmallBalanceReaction {
|
struct SmallBalanceReaction {
|
||||||
ChannelId channelId = 0;
|
ChannelId channelId = 0;
|
||||||
};
|
};
|
||||||
|
struct SmallBalanceSubscription {
|
||||||
|
QString name;
|
||||||
|
};
|
||||||
struct SmallBalanceSource : std::variant<
|
struct SmallBalanceSource : std::variant<
|
||||||
SmallBalanceBot,
|
SmallBalanceBot,
|
||||||
SmallBalanceReaction> {
|
SmallBalanceReaction,
|
||||||
|
SmallBalanceSubscription> {
|
||||||
using variant::variant;
|
using variant::variant;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue