Skip to content

Commit 667822c

Browse files
committed
Improve negative rating display.
1 parent 051b8c4 commit 667822c

File tree

9 files changed

+110
-25
lines changed

9 files changed

+110
-25
lines changed
Lines changed: 7 additions & 0 deletions
Loading

Telegram/Resources/langs/lang.strings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
18821882
"lng_stars_rating_pending#other" = "The rating updates in 21 days after purchases.\n{count} points are pending. {link}";
18831883
"lng_stars_rating_pending_preview" = "Preview {arrow}";
18841884
"lng_stars_rating_pending_back" = "Back {arrow}";
1885+
"lng_stars_rating_negative_label" = "Negative Rating";
1886+
"lng_stars_rating_negative" = "A negative rating indicates that **{name}'s** payments are unreliable.";
1887+
"lng_stars_rating_negative_your#one" = "A negative rating indicates that your payments are unreliable. Spend **{count} Star** to fix this issue.";
1888+
"lng_stars_rating_negative_your#other" = "A negative rating indicates that your payments are unreliable. Spend **{count} Stars** to fix this issue.";
18851889
"lng_stars_rating_about" = "This rating reflects **{name}'s** activity on Telegram. What affects it:";
18861890
"lng_stars_rating_about_your" = "This rating reflects your activity on Telegram. What affects it:";
18871891
"lng_stars_title_gifts_telegram" = "Gifts from Telegram";

Telegram/SourceFiles/data/data_peer_values.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,11 @@ rpl::producer<Data::StarsRating> StarsRatingValue(
525525
user,
526526
Data::PeerUpdate::Flag::StarsRating
527527
) | rpl::map([=] {
528-
return user->starsRating();
528+
auto result = user->starsRating();
529+
if (!user->isSelf() && result.level < 0) {
530+
result.stars = 0;
531+
}
532+
return result;
529533
});
530534
}
531535
return rpl::single(Data::StarsRating());

Telegram/SourceFiles/info/profile/info_levels.style

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ level80: LevelShape(levelBase) {
7474
level90: LevelShape(levelBase) {
7575
icon: icon {{ "levels/level90_inner-31x31", windowBgActive }};
7676
}
77+
levelNegative: LevelShape(levelBase) {
78+
icon: icon {{ "levels/level_warning-18x18", attentionButtonFg, point(6px, 7px) }};
79+
}
80+
levelNegativeBubble: icon {{ "levels/level_warning-28x28", windowFgActive }};

Telegram/SourceFiles/ui/controls/stars_rating.cpp

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,19 @@ void FillRatingLimit(
157157
rpl::producer<> showFinished,
158158
not_null<VerticalLayout*> container,
159159
rpl::producer<Counters> data,
160+
Premium::BubbleType type,
160161
style::margins limitLinePadding,
161-
int starsForScale) {
162+
int starsForScale,
163+
bool hideCount) {
162164
const auto addSkip = [&](int skip) {
163165
container->add(object_ptr<Ui::FixedHeightWidget>(container, skip));
164166
};
165167

168+
const auto negative = (type == Premium::BubbleType::NegativeRating);
166169
const auto ratio = [=](Counters rating) {
170+
if (negative) {
171+
return 0.5;
172+
}
167173
const auto min = rating.thisLevelStars;
168174
const auto max = rating.nextLevelStars;
169175

@@ -213,12 +219,14 @@ void FillRatingLimit(
213219
});
214220
Premium::AddBubbleRow(
215221
container,
216-
st::boostBubble,
222+
(hideCount ? st::iconOnlyPremiumBubble : st::boostBubble),
217223
std::move(showFinished),
218224
rpl::duplicate(bubbleRowState),
219-
Premium::BubbleType::StarRating,
220-
BubbleTextFactory(starsForScale),
221-
&st::infoStarsCrown,
225+
type,
226+
(hideCount
227+
? [](int) { return QString(); }
228+
: BubbleTextFactory(starsForScale)),
229+
negative ? &st::levelNegativeBubble : &st::infoStarsCrown,
222230
limitLinePadding);
223231
addSkip(st::premiumLineTextSkip);
224232

@@ -227,30 +235,35 @@ void FillRatingLimit(
227235
};
228236
auto limitState = std::move(
229237
bubbleRowState
230-
) | rpl::map([](const Premium::BubbleRowState &state) {
238+
) | rpl::map([negative](const Premium::BubbleRowState &state) {
231239
return Premium::LimitRowState{
232-
.ratio = state.ratio,
233-
.animateFromZero = state.animateFromZero,
240+
.ratio = negative ? 0.5 : state.ratio,
241+
.animateFromZero = !negative && state.animateFromZero,
234242
.dynamic = state.dynamic
235243
};
236244
});
237245
auto left = rpl::duplicate(
238246
adjustedData
239247
) | rpl::map([=](Counters counters) {
240-
return level(counters.level);
248+
return (counters.level < 0) ? QString() : level(counters.level);
241249
});
242250
auto right = rpl::duplicate(
243251
adjustedData
244252
) | rpl::map([=](Counters counters) {
245-
return level(counters.level + 1);
253+
return (counters.level < 0)
254+
? tr::lng_stars_rating_negative_label(tr::now)
255+
: level(counters.level + 1);
246256
});
247257
Premium::AddLimitRow(
248258
container,
249-
st::boostLimits,
259+
(negative ? st::negativeStarsLimits : st::boostLimits),
250260
Premium::LimitRowLabels{
251261
.leftLabel = std::move(left),
252262
.rightLabel = std::move(right),
253-
.activeLineBg = [=] { return st::windowBgActive->b; },
263+
.activeLineBg = [=] { return negative
264+
? st::attentionButtonFg->b
265+
: st::windowBgActive->b;
266+
},
254267
},
255268
std::move(limitState),
256269
limitLinePadding);
@@ -276,8 +289,12 @@ void AboutRatingBox(
276289
BoxShowFinishes(box),
277290
box->verticalLayout(),
278291
state->data.value(),
292+
(data.level < 0
293+
? Premium::BubbleType::NegativeRating
294+
: Premium::BubbleType::StarRating),
279295
st::boxRowPadding,
280-
data.stars);
296+
data.stars,
297+
(data.level < 0 && !data.stars));
281298

282299
box->setMaxHeight(st::boostBoxMaxHeight);
283300

@@ -294,10 +311,40 @@ void AboutRatingBox(
294311
: tr::lng_stars_rating_about_your(
295312
Ui::Text::RichLangValue) | rpl::type_erased();
296313

314+
if (data.level < 0) {
315+
auto text = (data.stars < 0)
316+
? tr::lng_stars_rating_negative_your(
317+
lt_count_decimal,
318+
rpl::single(-data.stars * 1.),
319+
Ui::Text::RichLangValue)
320+
: tr::lng_stars_rating_negative(
321+
lt_name,
322+
rpl::single(TextWithEntities{ name }),
323+
Ui::Text::RichLangValue);
324+
const auto aboutNegative = box->addRow(
325+
object_ptr<Ui::FlatLabel>(
326+
box,
327+
std::move(text),
328+
st::boostTextNegative),
329+
(st::boxRowPadding
330+
+ QMargins(0, st::boostTextSkip, 0, st::boostBottomSkip)));
331+
aboutNegative->setTryMakeSimilarLines(true);
332+
}
333+
297334
box->addRow(
298335
object_ptr<Ui::FlatLabel>(box, std::move(title), st::infoStarsTitle),
299336
st::boxRowPadding + QMargins(0, st::boostTitleSkip / 2, 0, 0));
300337

338+
AssertIsDebug();
339+
pending = {
340+
.value = {
341+
.level = 10,
342+
.stars = 100,
343+
.thisLevelStars = 90,
344+
.nextLevelStars = 110,
345+
},
346+
.date = 86400,
347+
};
301348
if (pending) {
302349
auto text = state->pending.value(
303350
) | rpl::map([=](bool value) {
@@ -398,6 +445,9 @@ void AboutRatingBox(
398445
}
399446

400447
[[nodiscard]] not_null<const style::LevelShape*> SelectShape(int level) {
448+
if (level < 0) {
449+
return &st::levelNegative;
450+
}
401451
struct Shape {
402452
int level = 0;
403453
not_null<const style::LevelShape*> shape;
@@ -480,7 +530,9 @@ void StarsRating::updateData(Data::StarsRating rating) {
480530
_shape = SelectShape(rating.level);
481531
_collapsedText.setText(
482532
st::levelStyle,
483-
Lang::FormatCountDecimal(rating.level));
533+
(rating.level < 0
534+
? QString()
535+
: Lang::FormatCountDecimal(rating.level)));
484536
_widthValue = _shape->icon.width() - st::levelMargin.left();
485537
}
486538
updateWidth();

Telegram/SourceFiles/ui/effects/premium.style

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ boostLimits: PremiumLimits(defaultPremiumLimits) {
255255
gradientFromLeft: true;
256256
nonPremiumBg: windowBgRipple;
257257
}
258+
negativeStarsLimits: PremiumLimits(boostLimits) {
259+
gradientFromLeft: false;
260+
}
258261
boostBubble: PremiumBubble(defaultPremiumBubble) {
259262
height: 32px;
260263
padding: margins(7px, 0px, 11px, 0px);
@@ -263,6 +266,10 @@ boostBubble: PremiumBubble(defaultPremiumBubble) {
263266
tailSize: size(14px, 6px);
264267
font: font(16px);
265268
}
269+
iconOnlyPremiumBubble: PremiumBubble(boostBubble) {
270+
padding: margins(7px, 0px, 7px, 0px);
271+
textSkip: 0px;
272+
}
266273
boostTitleSkip: 32px;
267274
boostTitle: FlatLabel(defaultFlatLabel) {
268275
minWidth: 40px;
@@ -289,6 +296,9 @@ boostText: FlatLabel(defaultFlatLabel) {
289296
boostTextPending: FlatLabel(boostText) {
290297
textFg: windowSubTextFg;
291298
}
299+
boostTextNegative: FlatLabel(boostText) {
300+
textFg: attentionButtonFg;
301+
}
292302
boostReassignText: FlatLabel(defaultFlatLabel) {
293303
minWidth: 40px;
294304
align: align(top);

Telegram/SourceFiles/ui/effects/premium_bubble.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ For license and copyright information please follow this link:
1515
#include "ui/wrap/padding_wrap.h"
1616
#include "ui/wrap/vertical_layout.h"
1717
#include "ui/painter.h"
18+
#include "styles/style_info_levels.h"
1819
#include "styles/style_layers.h"
1920
#include "styles/style_premium.h"
2021

@@ -181,11 +182,9 @@ void Bubble::paintBubble(QPainter &p, const QRect &r, const QBrush &brush) {
181182
p.setPen(st::activeButtonFg);
182183
p.setFont(_st.font);
183184
const auto iconLeft = r.x() + _st.padding.left();
184-
_icon->paint(
185-
p,
186-
iconLeft,
187-
bubbleRect.y() + (bubbleRect.height() - _icon->height()) / 2,
188-
bubbleRect.width());
185+
const auto iconTop = bubbleRect.y()
186+
+ (bubbleRect.height() - _icon->height()) / 2;
187+
_icon->paint(p, iconLeft, iconTop, bubbleRect.width());
189188
_numberAnimation.paint(
190189
p,
191190
iconLeft + _icon->width() + _st.textSkip,
@@ -424,6 +423,7 @@ void BubbleWidget::paintEvent(QPaintEvent *e) {
424423
switch (_type) {
425424
case BubbleType::NoPremium:
426425
case BubbleType::StarRating: return st::windowBgActive->b;
426+
case BubbleType::NegativeRating: return st::attentionButtonFg->b;
427427
case BubbleType::Premium: return QBrush(_cachedGradient);
428428
case BubbleType::Credits: return st::creditsBg3->b;
429429
}

Telegram/SourceFiles/ui/effects/premium_bubble.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct BubbleRowState {
8989

9090
enum class BubbleType : uchar {
9191
StarRating,
92+
NegativeRating,
9293
NoPremium,
9394
Premium,
9495
Credits,

Telegram/SourceFiles/ui/effects/premium_graphics.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ void Line::recache(const QSize &s) {
372372
}
373373
};
374374
const auto textPadding = st::premiumLineTextSkip;
375-
const auto textTop = (s.height() - _leftLabel.minHeight()) / 2;
376375
const auto rwidth = _rightLabel.maxWidth();
377376
const auto pen = [&](bool gradient) {
378377
return gradient ? st::activeButtonFg : _st.nonPremiumFg;
@@ -385,8 +384,10 @@ void Line::recache(const QSize &s) {
385384
if (_dynamic) {
386385
p.setFont(st::normalFont);
387386
p.setPen(pen(_st.gradientFromLeft));
388-
_leftLabel.drawLeft(p, textPadding, textTop, width, width);
389-
_rightLabel.drawRight(p, textPadding, textTop, rwidth, width);
387+
const auto leftTop = (s.height() - _leftLabel.minHeight()) / 2;
388+
_leftLabel.drawLeft(p, textPadding, leftTop, width, width);
389+
const auto rightTop = (s.height() - _rightLabel.minHeight()) / 2;
390+
_rightLabel.drawRight(p, textPadding, rightTop, rwidth, width);
390391
}
391392
_leftPixmap = std::move(leftPixmap);
392393
}
@@ -398,8 +399,10 @@ void Line::recache(const QSize &s) {
398399
if (_dynamic) {
399400
p.setFont(st::normalFont);
400401
p.setPen(pen(!_st.gradientFromLeft));
401-
_leftLabel.drawLeft(p, textPadding, textTop, width, width);
402-
_rightLabel.drawRight(p, textPadding, textTop, rwidth, width);
402+
const auto leftTop = (s.height() - _leftLabel.minHeight()) / 2;
403+
_leftLabel.drawLeft(p, textPadding, leftTop, width, width);
404+
const auto rightTop = (s.height() - _rightLabel.minHeight()) / 2;
405+
_rightLabel.drawRight(p, textPadding, rightTop, rwidth, width);
403406
}
404407
_rightPixmap = std::move(rightPixmap);
405408
}

0 commit comments

Comments
 (0)