mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-18 22:17:01 +00:00
Support non-premium-supported limit boxes.
This commit is contained in:
parent
1572af3a71
commit
368a1e4231
@ -411,10 +411,10 @@ void SimpleLimitBox(
|
||||
rpl::producer<TextWithEntities> text,
|
||||
const QString &refAddition,
|
||||
const InfographicDescriptor &descriptor,
|
||||
bool premium,
|
||||
bool fixed = false) {
|
||||
box->setWidth(st::boxWideWidth);
|
||||
|
||||
const auto premiumPossible = session->premiumPossible();
|
||||
const auto top = fixed
|
||||
? box->setPinnedToTopContent(object_ptr<Ui::VerticalLayout>(box))
|
||||
: box->verticalLayout();
|
||||
@ -426,11 +426,17 @@ void SimpleLimitBox(
|
||||
descriptor.defaultLimit,
|
||||
descriptor.current,
|
||||
descriptor.premiumLimit,
|
||||
premiumPossible,
|
||||
descriptor.phrase,
|
||||
descriptor.icon);
|
||||
Settings::AddSkip(top, st::premiumLineTextSkip);
|
||||
Ui::Premium::AddLimitRow(top, descriptor.premiumLimit, descriptor.phrase);
|
||||
Settings::AddSkip(top, st::premiumInfographicPadding.bottom());
|
||||
if (premiumPossible) {
|
||||
Ui::Premium::AddLimitRow(
|
||||
top,
|
||||
descriptor.premiumLimit,
|
||||
descriptor.phrase);
|
||||
Settings::AddSkip(top, st::premiumInfographicPadding.bottom());
|
||||
}
|
||||
|
||||
box->setTitle(std::move(title));
|
||||
|
||||
@ -443,7 +449,7 @@ void SimpleLimitBox(
|
||||
st::aboutRevokePublicLabel),
|
||||
padding);
|
||||
|
||||
if (premium) {
|
||||
if (session->premium() || !premiumPossible) {
|
||||
box->addButton(tr::lng_box_ok(), [=] {
|
||||
box->closeBox();
|
||||
});
|
||||
@ -451,11 +457,11 @@ void SimpleLimitBox(
|
||||
box->addButton(tr::lng_limits_increase(), [=] {
|
||||
Settings::ShowPremium(session, LimitsPremiumRef(refAddition));
|
||||
});
|
||||
}
|
||||
|
||||
box->addButton(tr::lng_cancel(), [=] {
|
||||
box->closeBox();
|
||||
});
|
||||
box->addButton(tr::lng_cancel(), [=] {
|
||||
box->closeBox();
|
||||
});
|
||||
}
|
||||
|
||||
if (fixed) {
|
||||
Settings::AddSkip(top, st::settingsButton.padding.bottom());
|
||||
@ -477,6 +483,7 @@ void SimplePinsLimitBox(
|
||||
int limitPremium,
|
||||
int currentCount) {
|
||||
const auto premium = session->premium();
|
||||
const auto premiumPossible = session->premiumPossible();
|
||||
|
||||
const auto defaultLimit = Limit(session, keyDefault, limitDefault);
|
||||
const auto premiumLimit = Limit(session, keyPremium, limitPremium);
|
||||
@ -490,7 +497,7 @@ void SimplePinsLimitBox(
|
||||
lt_count,
|
||||
rpl::single(premium ? premiumLimit : defaultLimit),
|
||||
Ui::Text::RichLangValue),
|
||||
(premium
|
||||
((premium || !premiumPossible)
|
||||
? rpl::single(TextWithEntities())
|
||||
: tr::lng_filter_pin_limit2(
|
||||
lt_count,
|
||||
@ -507,8 +514,7 @@ void SimplePinsLimitBox(
|
||||
tr::lng_filter_pin_limit_title(),
|
||||
std::move(text),
|
||||
refAddition,
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconPins },
|
||||
premium);
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconPins });
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -517,6 +523,7 @@ void ChannelsLimitBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Main::Session*> session) {
|
||||
const auto premium = session->premium();
|
||||
const auto premiumPossible = session->premiumPossible();
|
||||
|
||||
const auto defaultLimit = Limit(session, "channels_limit_default", 500);
|
||||
const auto premiumLimit = Limit(session, "channels_limit_premium", 1000);
|
||||
@ -527,7 +534,7 @@ void ChannelsLimitBox(
|
||||
lt_count,
|
||||
rpl::single(current),
|
||||
Ui::Text::RichLangValue),
|
||||
(premium
|
||||
((premium || !premiumPossible)
|
||||
? tr::lng_channels_limit2_final(Ui::Text::RichLangValue)
|
||||
: tr::lng_channels_limit2(
|
||||
lt_count,
|
||||
@ -544,7 +551,6 @@ void ChannelsLimitBox(
|
||||
std::move(text),
|
||||
"channels",
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconGroups },
|
||||
premium,
|
||||
true);
|
||||
|
||||
AddSubsectionTitle(box->verticalLayout(), tr::lng_channels_leave_title());
|
||||
@ -607,6 +613,7 @@ void PublicLinksLimitBox(
|
||||
Fn<void()> retry) {
|
||||
const auto session = &navigation->session();
|
||||
const auto premium = session->premium();
|
||||
const auto premiumPossible = session->premiumPossible();
|
||||
|
||||
const auto defaultLimit = Limit(
|
||||
session,
|
||||
@ -623,7 +630,7 @@ void PublicLinksLimitBox(
|
||||
lt_count,
|
||||
rpl::single(current),
|
||||
Ui::Text::RichLangValue),
|
||||
(premium
|
||||
((premium || !premiumPossible)
|
||||
? tr::lng_links_limit2_final(Ui::Text::RichLangValue)
|
||||
: tr::lng_links_limit2(
|
||||
lt_count,
|
||||
@ -640,7 +647,6 @@ void PublicLinksLimitBox(
|
||||
std::move(text),
|
||||
"channels_public",
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconLinks },
|
||||
premium,
|
||||
true);
|
||||
|
||||
AddSubsectionTitle(box->verticalLayout(), tr::lng_links_revoke_title());
|
||||
@ -673,6 +679,7 @@ void FilterChatsLimitBox(
|
||||
not_null<Main::Session*> session,
|
||||
int currentCount) {
|
||||
const auto premium = session->premium();
|
||||
const auto premiumPossible = session->premiumPossible();
|
||||
|
||||
const auto defaultLimit = Limit(
|
||||
session,
|
||||
@ -692,7 +699,7 @@ void FilterChatsLimitBox(
|
||||
lt_count,
|
||||
rpl::single(premium ? premiumLimit : defaultLimit),
|
||||
Ui::Text::RichLangValue),
|
||||
(premium
|
||||
((premium || !premiumPossible)
|
||||
? rpl::single(TextWithEntities())
|
||||
: tr::lng_filter_chats_limit2(
|
||||
lt_count,
|
||||
@ -710,14 +717,14 @@ void FilterChatsLimitBox(
|
||||
tr::lng_filter_chats_limit_title(),
|
||||
std::move(text),
|
||||
"dialog_filters_chats",
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconChats },
|
||||
premium);
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconChats });
|
||||
}
|
||||
|
||||
void FiltersLimitBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
not_null<Main::Session*> session) {
|
||||
const auto premium = session->premium();
|
||||
const auto premiumPossible = session->premiumPossible();
|
||||
|
||||
const auto defaultLimit = Limit(
|
||||
session,
|
||||
@ -736,7 +743,7 @@ void FiltersLimitBox(
|
||||
lt_count,
|
||||
rpl::single(premium ? premiumLimit : defaultLimit),
|
||||
Ui::Text::RichLangValue),
|
||||
(premium
|
||||
((premium || !premiumPossible)
|
||||
? rpl::single(TextWithEntities())
|
||||
: tr::lng_filters_limit2(
|
||||
lt_count,
|
||||
@ -753,8 +760,7 @@ void FiltersLimitBox(
|
||||
tr::lng_filters_limit_title(),
|
||||
std::move(text),
|
||||
"dialog_filters",
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconFolders },
|
||||
premium);
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconFolders });
|
||||
}
|
||||
|
||||
void FilterPinsLimitBox(
|
||||
@ -805,6 +811,7 @@ void CaptionLimitBox(
|
||||
not_null<Main::Session*> session,
|
||||
int remove) {
|
||||
const auto premium = session->premium();
|
||||
const auto premiumPossible = session->premiumPossible();
|
||||
|
||||
const auto defaultLimit = Limit(
|
||||
session,
|
||||
@ -825,12 +832,16 @@ void CaptionLimitBox(
|
||||
lt_count,
|
||||
rpl::single(currentLimit),
|
||||
Ui::Text::RichLangValue),
|
||||
tr::lng_caption_limit2(
|
||||
(!premiumPossible
|
||||
? rpl::single(TextWithEntities())
|
||||
: tr::lng_caption_limit2(
|
||||
lt_count,
|
||||
rpl::single(premiumLimit),
|
||||
Ui::Text::RichLangValue)
|
||||
Ui::Text::RichLangValue))
|
||||
) | rpl::map([](TextWithEntities &&a, TextWithEntities &&b) {
|
||||
return a.append(QChar(' ')).append(std::move(b));
|
||||
return b.text.isEmpty()
|
||||
? a
|
||||
: a.append(QChar(' ')).append(std::move(b));
|
||||
});
|
||||
|
||||
SimpleLimitBox(
|
||||
@ -839,8 +850,7 @@ void CaptionLimitBox(
|
||||
tr::lng_caption_limit_title(),
|
||||
std::move(text),
|
||||
"caption_length",
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconChats },
|
||||
premium);
|
||||
{ defaultLimit, current, premiumLimit, &st::premiumIconChats });
|
||||
}
|
||||
|
||||
void CaptionLimitReachedBox(
|
||||
@ -867,6 +877,7 @@ void FileSizeLimitBox(
|
||||
not_null<Main::Session*> session,
|
||||
uint64 fileSizeBytes) {
|
||||
const auto premium = session->premium();
|
||||
const auto premiumPossible = session->premiumPossible();
|
||||
|
||||
const auto defaultLimit = Limit(
|
||||
session,
|
||||
@ -894,10 +905,12 @@ void FileSizeLimitBox(
|
||||
lt_size,
|
||||
rpl::single(Ui::Text::Bold(gb(defaultGb))),
|
||||
Ui::Text::RichLangValue),
|
||||
tr::lng_file_size_limit2(
|
||||
lt_size,
|
||||
rpl::single(Ui::Text::Bold(gb(premiumGb))),
|
||||
Ui::Text::RichLangValue)
|
||||
(!premiumPossible
|
||||
? rpl::single(TextWithEntities())
|
||||
: tr::lng_file_size_limit2(
|
||||
lt_size,
|
||||
rpl::single(Ui::Text::Bold(gb(premiumGb))),
|
||||
Ui::Text::RichLangValue))
|
||||
) | rpl::map([](TextWithEntities &&a, TextWithEntities &&b) {
|
||||
return a.append(QChar(' ')).append(std::move(b));
|
||||
});
|
||||
@ -914,8 +927,7 @@ void FileSizeLimitBox(
|
||||
premiumGb,
|
||||
&st::premiumIconFiles,
|
||||
tr::lng_file_size_limit
|
||||
},
|
||||
premium);
|
||||
});
|
||||
}
|
||||
|
||||
void AccountsLimitBox(
|
||||
@ -925,6 +937,7 @@ void AccountsLimitBox(
|
||||
const auto premiumLimit = Main::Domain::kPremiumMaxAccounts;
|
||||
|
||||
const auto accounts = session->domain().orderedAccounts();
|
||||
const auto premiumPossible = session->premiumPossible();
|
||||
const auto current = int(accounts.size());
|
||||
|
||||
auto text = rpl::combine(
|
||||
@ -953,6 +966,7 @@ void AccountsLimitBox(
|
||||
0,
|
||||
current,
|
||||
(current > defaultLimit) ? current : (defaultLimit * 2),
|
||||
premiumPossible,
|
||||
std::nullopt,
|
||||
&st::premiumIconAccounts);
|
||||
Settings::AddSkip(top, st::premiumLineTextSkip);
|
||||
|
@ -429,6 +429,10 @@ void ReactionsSettingsBox(
|
||||
st::settingsButton);
|
||||
|
||||
const auto premium = r.premium;
|
||||
if (premium && !controller->session().premiumPossible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto iconSize = st::settingsReactionSize;
|
||||
AddReactionLottieIcon(
|
||||
button,
|
||||
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "main/main_session_settings.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/session/send_as_peers.h"
|
||||
#include "mtproto/mtproto_config.h"
|
||||
#include "chat_helpers/stickers_emoji_pack.h"
|
||||
@ -222,6 +223,12 @@ bool Session::premium() const {
|
||||
return _user->isPremium();
|
||||
}
|
||||
|
||||
bool Session::premiumPossible() const {
|
||||
return !_account->appConfig().get<bool>(
|
||||
"premium_purchase_blocked",
|
||||
false);
|
||||
}
|
||||
|
||||
uint64 Session::uniqueId() const {
|
||||
// See also Account::willHaveSessionUniqueId.
|
||||
return userId().bare
|
||||
|
@ -81,6 +81,7 @@ public:
|
||||
[[nodiscard]] Storage::Domain &domainLocal() const;
|
||||
|
||||
[[nodiscard]] bool premium() const;
|
||||
[[nodiscard]] bool premiumPossible() const;
|
||||
[[nodiscard]] uint64 uniqueId() const; // userId() with TestDC shift.
|
||||
[[nodiscard]] UserId userId() const;
|
||||
[[nodiscard]] PeerId userPeerId() const;
|
||||
|
@ -72,7 +72,8 @@ public:
|
||||
Bubble(
|
||||
Fn<void()> updateCallback,
|
||||
TextFactory textFactory,
|
||||
const style::icon *icon);
|
||||
const style::icon *icon,
|
||||
bool premiumPossible);
|
||||
|
||||
[[nodiscard]] int counter() const;
|
||||
[[nodiscard]] int height() const;
|
||||
@ -85,7 +86,6 @@ public:
|
||||
void paintBubble(Painter &p, const QRect &r, const QBrush &brush);
|
||||
|
||||
[[nodiscard]] rpl::producer<> widthChanges() const;
|
||||
[[nodiscard]] rpl::producer<> updateRequests() const;
|
||||
|
||||
private:
|
||||
[[nodiscard]] int filledWidth() const;
|
||||
@ -100,6 +100,7 @@ private:
|
||||
const QSize _tailSize;
|
||||
const int _height;
|
||||
const int _textTop;
|
||||
const bool _premiumPossible;
|
||||
|
||||
int _counter = -1;
|
||||
EdgeProgress _tailEdge = 0.;
|
||||
@ -111,7 +112,8 @@ private:
|
||||
Bubble::Bubble(
|
||||
Fn<void()> updateCallback,
|
||||
TextFactory textFactory,
|
||||
const style::icon *icon)
|
||||
const style::icon *icon,
|
||||
bool premiumPossible)
|
||||
: _updateCallback(std::move(updateCallback))
|
||||
, _textFactory(std::move(textFactory))
|
||||
, _font(st::premiumBubbleFont)
|
||||
@ -120,7 +122,8 @@ Bubble::Bubble(
|
||||
, _numberAnimation(_font, _updateCallback)
|
||||
, _tailSize(st::premiumBubbleTailSize)
|
||||
, _height(st::premiumBubbleHeight + _tailSize.height())
|
||||
, _textTop((_height - _tailSize.height() - _font->height) / 2) {
|
||||
, _textTop((_height - _tailSize.height() - _font->height) / 2)
|
||||
, _premiumPossible(premiumPossible) {
|
||||
_numberAnimation.setDisabledMonospace(true);
|
||||
_numberAnimation.setWidthChangedCallback([=] {
|
||||
_widthChanges.fire({});
|
||||
@ -208,13 +211,14 @@ void Bubble::paintBubble(Painter &p, const QRect &r, const QBrush &brush) {
|
||||
? std::max(float64(tailCenter), float64(bottomMax))
|
||||
: right;
|
||||
}();
|
||||
pathTail.moveTo(tailLeftFull, tailTop);
|
||||
pathTail.lineTo(tailLeft, tailTop);
|
||||
pathTail.lineTo(tailCenter, tailTop + _tailSize.height());
|
||||
pathTail.lineTo(tailRight, tailTop);
|
||||
pathTail.lineTo(tailRight, tailTop - radius);
|
||||
pathTail.moveTo(tailLeftFull, tailTop);
|
||||
|
||||
if (_premiumPossible) {
|
||||
pathTail.moveTo(tailLeftFull, tailTop);
|
||||
pathTail.lineTo(tailLeft, tailTop);
|
||||
pathTail.lineTo(tailCenter, tailTop + _tailSize.height());
|
||||
pathTail.lineTo(tailRight, tailTop);
|
||||
pathTail.lineTo(tailRight, tailTop - radius);
|
||||
pathTail.moveTo(tailLeftFull, tailTop);
|
||||
}
|
||||
auto pathBubble = QPainterPath();
|
||||
pathBubble.setFillRule(Qt::WindingFill);
|
||||
pathBubble.addRoundedRect(bubbleRect, radius, radius);
|
||||
@ -255,6 +259,7 @@ public:
|
||||
TextFactory textFactory,
|
||||
int current,
|
||||
int maxCounter,
|
||||
bool premiumPossible,
|
||||
rpl::producer<> showFinishes,
|
||||
const style::icon *icon);
|
||||
|
||||
@ -268,6 +273,7 @@ private:
|
||||
const int _maxCounter;
|
||||
Bubble _bubble;
|
||||
const int _maxBubbleWidth;
|
||||
const bool _premiumPossible;
|
||||
|
||||
Ui::Animations::Simple _appearanceAnimation;
|
||||
QSize _spaceForDeflection;
|
||||
@ -287,13 +293,15 @@ BubbleWidget::BubbleWidget(
|
||||
TextFactory textFactory,
|
||||
int current,
|
||||
int maxCounter,
|
||||
bool premiumPossible,
|
||||
rpl::producer<> showFinishes,
|
||||
const style::icon *icon)
|
||||
: RpWidget(parent)
|
||||
, _currentCounter(current)
|
||||
, _maxCounter(maxCounter)
|
||||
, _bubble([=] { update(); }, std::move(textFactory), icon)
|
||||
, _bubble([=] { update(); }, std::move(textFactory), icon, premiumPossible)
|
||||
, _maxBubbleWidth(_bubble.countMaxWidth(_maxCounter))
|
||||
, _premiumPossible(premiumPossible)
|
||||
, _deflection(kDeflection)
|
||||
, _stepBeforeDeflection(kStepBeforeDeflection)
|
||||
, _stepAfterDeflection(kStepAfterDeflection) {
|
||||
@ -430,7 +438,10 @@ void BubbleWidget::paintEvent(QPaintEvent *e) {
|
||||
p.translate(-offsetX, -offsetY);
|
||||
}
|
||||
|
||||
_bubble.paintBubble(p, bubbleRect, QBrush(_cachedGradient));
|
||||
_bubble.paintBubble(
|
||||
p,
|
||||
bubbleRect,
|
||||
_premiumPossible ? QBrush(_cachedGradient) : st::windowBgActive->b);
|
||||
}
|
||||
|
||||
class Line final : public Ui::RpWidget {
|
||||
@ -575,6 +586,7 @@ void AddBubbleRow(
|
||||
int min,
|
||||
int current,
|
||||
int max,
|
||||
bool premiumPossible,
|
||||
std::optional<tr::phrase<lngtag_count>> phrase,
|
||||
const style::icon *icon) {
|
||||
const auto container = parent->add(
|
||||
@ -584,6 +596,7 @@ void AddBubbleRow(
|
||||
ProcessTextFactory(phrase),
|
||||
current,
|
||||
max,
|
||||
premiumPossible,
|
||||
std::move(showFinishes),
|
||||
icon);
|
||||
rpl::combine(
|
||||
|
@ -34,6 +34,7 @@ void AddBubbleRow(
|
||||
int min,
|
||||
int current,
|
||||
int max,
|
||||
bool premiumPossible,
|
||||
std::optional<tr::phrase<lngtag_count>> phrase,
|
||||
const style::icon *icon);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user