Added support of subscription status when it is cancelled by bot.

This commit is contained in:
23rd 2024-11-13 10:33:43 +03:00 committed by John Preston
parent ccc0bf57a1
commit fbce06cb26
3 changed files with 53 additions and 17 deletions

View file

@ -2520,12 +2520,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_credits_subscription_off_button" = "Renew Subscription"; "lng_credits_subscription_off_button" = "Renew Subscription";
"lng_credits_subscription_off_about" = "You have canceled your subscription."; "lng_credits_subscription_off_about" = "You have canceled your subscription.";
"lng_credits_subscription_off_by_bot_about" = "{bot} has canceled your subscription.";
"lng_credits_subscription_status_on" = "renews on {date}"; "lng_credits_subscription_status_on" = "renews on {date}";
"lng_credits_subscription_status_off" = "expires on {date}"; "lng_credits_subscription_status_off" = "expires on {date}";
"lng_credits_subscription_status_none" = "expired on {date}"; "lng_credits_subscription_status_none" = "expired on {date}";
"lng_credits_subscription_status_off_right" = "canceled"; "lng_credits_subscription_status_off_right" = "canceled";
"lng_credits_subscription_status_none_right" = "expired"; "lng_credits_subscription_status_none_right" = "expired";
"lng_credits_subscription_status_off_by_bot_right" = "canceled\nby bot";
"lng_credits_small_balance_title#one" = "{count} Star Needed"; "lng_credits_small_balance_title#one" = "{count} Star Needed";
"lng_credits_small_balance_title#other" = "{count} Stars Needed"; "lng_credits_small_balance_title#other" = "{count} Stars Needed";

View file

@ -955,16 +955,29 @@ PaintRoundImageCallback CreditsRow::generatePaintUserpicCallback(bool force) {
return _paintUserpicCallback; return _paintUserpicCallback;
} }
[[nodiscard]] QString RightActionText(const Data::SubscriptionEntry &s) {
return s.cancelledByBot
? tr::lng_credits_subscription_status_off_by_bot_right(tr::now)
: s.cancelled
? tr::lng_credits_subscription_status_off_right(tr::now)
: s.expired
? tr::lng_credits_subscription_status_none_right(tr::now)
: QString();
}
QSize CreditsRow::rightActionSize() const { QSize CreditsRow::rightActionSize() const {
if (_rightLabel) { if (_rightLabel) {
return _rightLabel->size; return _rightLabel->size;
} else if (_subscription.cancelled || _subscription.expired) { } else if (const auto t = RightActionText(_subscription); !t.isEmpty()) {
const auto text = _subscription.cancelled const auto lines = t.split('\n');
? tr::lng_credits_subscription_status_off_right(tr::now) auto maxWidth = 0;
: tr::lng_credits_subscription_status_none_right(tr::now); for (const auto &line : lines) {
return QSize( const auto width = st::contactsStatusFont->width(line);
st::contactsStatusFont->width(text) + st::boxRowPadding.right(), if (width > maxWidth) {
_rowHeight); maxWidth = width;
}
}
return QSize(maxWidth + st::boxRowPadding.right(), _rowHeight);
} else if (_subscription || _entry) { } else if (_subscription || _entry) {
return QSize( return QSize(
_rightText.maxWidth() + st::boxRowPadding.right() / 2, _rightText.maxWidth() + st::boxRowPadding.right() / 2,
@ -994,18 +1007,31 @@ void CreditsRow::rightActionPaint(
const auto rightSkip = st::boxRowPadding.right(); const auto rightSkip = st::boxRowPadding.right();
if (_rightLabel) { if (_rightLabel) {
return _rightLabel->draw(p, x, y, _rowHeight); return _rightLabel->draw(p, x, y, _rowHeight);
} else if (_subscription.cancelled || _subscription.expired) { } else if (const auto t = RightActionText(_subscription); !t.isEmpty()) {
const auto &statusFont = st::contactsStatusFont; const auto &statusFont = st::contactsStatusFont;
y += _rowHeight / 2; y += _rowHeight / 2;
p.setFont(statusFont); p.setFont(statusFont);
p.setPen(st::attentionButtonFg); p.setPen(st::attentionButtonFg);
p.drawTextRight(
rightSkip, const auto lines = t.split('\n');
y - statusFont->height / 2, if (lines.size() > 1) {
outerWidth, const auto rect = QRect(x, 0, outerWidth - x, _rowHeight);
_subscription.expired const auto lineHeight = statusFont->height;
? tr::lng_credits_subscription_status_none_right(tr::now) const auto totalHeight = lines.size() * lineHeight;
: tr::lng_credits_subscription_status_off_right(tr::now)); auto startY = rect.top()
+ (rect.height() - totalHeight) / 2
+ statusFont->ascent;
for (const auto &line : lines) {
const auto lineWidth = statusFont->width(line);
const auto startX = rect.left()
+ (rect.width() - lineWidth) / 2;
p.drawText(startX, startY, line);
startY += lineHeight;
}
return;
}
p.drawTextRight(rightSkip, y - statusFont->height / 2, outerWidth, t);
return; return;
} }
y += _rowHeight / 2; y += _rowHeight / 2;
@ -1143,7 +1169,9 @@ void CreditsController::applySlice(const Data::CreditsStatusSlice &slice) {
.entry = i, .entry = i,
.subscription = s, .subscription = s,
.context = _context, .context = _context,
.rowHeight = computeListSt().item.height, .rowHeight = ((!s || !s.title.isEmpty())
? computeListSt().item
: st::boostsListBox.item).height,
.updateCallback = [=](not_null<PeerListRow*> row) { .updateCallback = [=](not_null<PeerListRow*> row) {
delegate()->peerListUpdateRow(row); delegate()->peerListUpdateRow(row);
}, },

View file

@ -1270,10 +1270,16 @@ void ReceiptCreditsBox(
st::creditsBoxAboutDivider))); st::creditsBoxAboutDivider)));
} }
if (s) { if (s) {
const auto user = peer ? peer->asUser() : nullptr;
const auto bot = (user && !user->isSelf()) ? user : nullptr;
Ui::AddSkip(content); Ui::AddSkip(content);
auto label = object_ptr<Ui::FlatLabel>( auto label = object_ptr<Ui::FlatLabel>(
box, box,
s.cancelled (s.cancelledByBot && bot)
? tr::lng_credits_subscription_off_by_bot_about(
lt_bot,
rpl::single(bot->name()))
: s.cancelled
? tr::lng_credits_subscription_off_about() ? tr::lng_credits_subscription_off_about()
: tr::lng_credits_subscription_on_about( : tr::lng_credits_subscription_on_about(
lt_date, lt_date,