fix: show supporter badge in account picker & menu

This commit is contained in:
AlexeyZavar
2026-03-08 02:17:01 +03:00
parent 6edf31beb6
commit 04eb23ae32
3 changed files with 108 additions and 16 deletions
@@ -72,6 +72,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
// AyuGram includes
#include "ayu/ui/ayu_userpic.h"
#include "ayu/utils/telegram_helpers.h"
#include "styles/style_info.h"
namespace Settings {
@@ -109,9 +111,11 @@ private:
rpl::variable<QString> _text;
rpl::event_stream<int> _unreadWidth;
rpl::event_stream<int> _premiumWidth;
rpl::event_stream<int> _exteraWidth;
QPointer<Ui::RpWidget> _unread;
Info::Profile::Badge _badge;
Info::Profile::Badge _exteraBadge;
};
@@ -130,9 +134,18 @@ ComposedBadge::ComposedBadge(
session,
Info::Profile::BadgeContentForPeer(session->user()),
nullptr,
std::move(animationPaused),
animationPaused,
kPlayStatusLimit,
Info::Profile::BadgeType::Premium) {
Info::Profile::BadgeType::Premium)
, _exteraBadge(
this,
st::infoPeerBadge,
session,
ExteraBadgeTypeFromPeer(session->user()),
nullptr,
std::move(animationPaused),
0,
Info::Profile::BadgeType::Extera | Info::Profile::BadgeType::ExteraSupporter | Info::Profile::BadgeType::ExteraCustom) {
if (hasUnread) {
_unread = Badge::CreateUnread(this, rpl::single(
rpl::empty
@@ -163,6 +176,16 @@ ComposedBadge::ComposedBadge(
}
}, lifetime());
_exteraBadge.updated(
) | rpl::on_next([=] {
if (const auto widget = _exteraBadge.widget()) {
widget->widthValue(
) | rpl::start_to_stream(_exteraWidth, widget->lifetime());
} else {
_exteraWidth.fire(0);
}
}, lifetime());
auto textWidth = _text.value() | rpl::map([=] {
return button->fullTextWidth();
});
@@ -171,11 +194,15 @@ ComposedBadge::ComposedBadge(
_premiumWidth.events_starting_with(_badge.widget()
? _badge.widget()->width()
: 0),
_exteraWidth.events_starting_with(_exteraBadge.widget()
? _exteraBadge.widget()->width()
: 0),
std::move(textWidth),
button->sizeValue()
) | rpl::on_next([=](
int unreadWidth,
int premiumWidth,
int exteraWidth,
int textWidth,
const QSize &buttonSize) {
const auto &st = button->st();
@@ -183,7 +210,14 @@ ComposedBadge::ComposedBadge(
const auto textRightPosition = st.padding.left()
+ textWidth
+ skip;
const auto minWidth = unreadWidth + premiumWidth + skip;
const auto exteraGap = exteraWidth
? st::infoVerifiedCheckPosition.x()
: 0;
const auto minWidth = unreadWidth
+ premiumWidth
+ exteraGap
+ exteraWidth
+ skip;
const auto maxTextWidth = buttonSize.width()
- minWidth
- st.padding.right();
@@ -198,6 +232,10 @@ ComposedBadge::ComposedBadge(
0,
st.padding.top(),
buttonSize.height() - st.padding.top());
_exteraBadge.move(
premiumWidth,
st.padding.top(),
buttonSize.height() - st.padding.top());
if (_unread) {
_unread->moveToRight(
0,
@@ -322,6 +322,15 @@ MainMenu::MainMenu(
[=] { return controller->isGifPausedAtLeastFor(GifPauseReason::Layer); },
kPlayStatusLimit,
Info::Profile::BadgeType::Premium))
, _exteraBadge(std::make_unique<Info::Profile::Badge>(
this,
st::infoPeerBadge,
&controller->session(),
ExteraBadgeTypeFromPeer(controller->session().user()),
nullptr,
[=] { return controller->isGifPausedAtLeastFor(GifPauseReason::Layer); },
0,
Info::Profile::BadgeType::Extera | Info::Profile::BadgeType::ExteraSupporter | Info::Profile::BadgeType::ExteraCustom))
, _scroll(this, st::defaultSolidScroll)
, _inner(_scroll->setOwnedWidget(
object_ptr<Ui::VerticalLayout>(_scroll.data())))
@@ -407,13 +416,23 @@ MainMenu::MainMenu(
rpl::combine(
_toggleAccounts->rightSkipValue(),
rpl::single(rpl::empty) | rpl::then(_badge->updated())
rpl::single(rpl::empty) | rpl::then(_badge->updated()),
rpl::single(rpl::empty) | rpl::then(_exteraBadge->updated())
) | rpl::on_next([=] {
moveBadge();
}, lifetime());
_badge->setPremiumClickCallback([=] {
chooseEmojiStatus();
});
{
const auto user = controller->session().user();
const auto isCustomBadge = isCustomBadgePeer(getBareID(user));
const auto isExtera = isExteraPeer(getBareID(user));
const auto isSupporter = isSupporterPeer(getBareID(user));
if (isExtera || isSupporter || isCustomBadge) {
_exteraBadge->setPremiumClickCallback(badgeClickHandler(user));
}
}
_controller->session().downloaderTaskFinished(
) | rpl::on_next([=] {
@@ -464,19 +483,42 @@ MainMenu::MainMenu(
MainMenu::~MainMenu() = default;
void MainMenu::moveBadge() {
if (!_badge->widget()) {
const auto badgeWidth = _badge->widget()
? _badge->widget()->width()
: 0;
const auto exteraBadgeWidth = _exteraBadge->widget()
? _exteraBadge->widget()->width()
: 0;
if (!badgeWidth && !exteraBadgeWidth) {
return;
}
const auto nameGap = badgeWidth ? st::semiboldFont->spacew : 0;
const auto exteraGap = exteraBadgeWidth
? st::infoVerifiedCheckPosition.x()
: 0;
const auto reserved = nameGap
+ badgeWidth
+ exteraGap
+ exteraBadgeWidth;
const auto available = width()
- st::mainMenuCoverNameLeft
- _toggleAccounts->rightSkip()
- _badge->widget()->width();
const auto left = st::mainMenuCoverNameLeft
+ std::min(_name.maxWidth() + st::semiboldFont->spacew, available);
_badge->move(
left,
st::mainMenuCoverNameTop,
st::mainMenuCoverNameTop + st::semiboldFont->height);
- reserved;
const auto nameLeft = st::mainMenuCoverNameLeft;
const auto nameEnd = nameLeft
+ std::min(_name.maxWidth(), available);
if (_badge->widget()) {
_badge->move(
nameEnd + nameGap,
st::mainMenuCoverNameTop,
st::mainMenuCoverNameTop + st::semiboldFont->height);
}
if (_exteraBadge->widget()) {
_exteraBadge->move(
nameEnd + nameGap + badgeWidth,
st::mainMenuCoverNameTop,
st::mainMenuCoverNameTop + st::semiboldFont->height);
}
}
void MainMenu::setupArchive() {
@@ -974,14 +1016,25 @@ void MainMenu::drawName(Painter &p) {
}
p.setFont(st::semiboldFont);
p.setPen(st::windowBoldFg);
const auto badgeWidth = _badge->widget()
? _badge->widget()->width()
: 0;
const auto exteraBadgeWidth = _exteraBadge->widget()
? _exteraBadge->widget()->width()
: 0;
const auto nameGap = badgeWidth ? st::semiboldFont->spacew : 0;
const auto exteraGap = exteraBadgeWidth
? st::infoVerifiedCheckPosition.x()
: 0;
const auto reserved = nameGap
+ badgeWidth
+ exteraGap
+ exteraBadgeWidth;
_name.drawLeftElided(
p,
st::mainMenuCoverNameLeft,
st::mainMenuCoverNameTop,
(widthText
- (_badge->widget()
? (st::semiboldFont->spacew + _badge->widget()->width())
: 0)),
widthText - reserved,
width());
}
@@ -93,6 +93,7 @@ private:
object_ptr<Ui::FlatLabel> _setEmojiStatus;
std::unique_ptr<Info::Profile::EmojiStatusPanel> _emojiStatusPanel;
std::unique_ptr<Info::Profile::Badge> _badge;
std::unique_ptr<Info::Profile::Badge> _exteraBadge;
object_ptr<ResetScaleButton> _resetScaleButton = { nullptr };
object_ptr<Ui::ScrollArea> _scroll;
not_null<Ui::VerticalLayout*> _inner;