fix: badge toast

This commit is contained in:
AlexeyZavar
2026-04-04 18:15:39 +03:00
parent 814739b52b
commit 4b65fd1126
2 changed files with 79 additions and 12 deletions
+5 -1
View File
@@ -65,6 +65,10 @@ exteraBadgeToast: Toast(defaultToast) {
padding: margins(54px, 13px, 19px, 12px);
}
exteraBadgeToastBadge: InfoPeerBadge(infoPeerBadge) {
premiumFg: toastFg;
}
supportLogoSize: 96px;
unreadPillPadding: 12px;
@@ -112,4 +116,4 @@ ghostPickerButton: LinkButton(defaultLinkButton) {
overFont: font(boxFontSize);
}
ayuBetaBadgePadding: margins(4px, 1px, 4px, 1px);
ayuBetaBadgePadding: margins(4px, 1px, 4px, 1px);
@@ -41,6 +41,7 @@
#include "main/main_domain.h"
#include "main/main_session.h"
#include "styles/style_ayu_styles.h"
#include "styles/style_info.h"
#include "ui/emoji_config.h"
#include "ui/text/format_values.h"
#include "ui/text/text_entity.h"
@@ -67,6 +68,61 @@ const auto regDateBotFallbackUsername = QString("ayugrambot");
const auto kZalgoPattern = QStringLiteral(
"\\p{Mn}{3,}|[\\x{202A}-\\x{202E}\\x{2066}-\\x{2069}\\x{200E}\\x{200F}\\x{061C}]");
class BadgeToastIcon final : public Ui::RpWidget {
public:
BadgeToastIcon(
QWidget *parent,
not_null<PeerData*> peer,
Info::Profile::Badge::Content content);
private:
void updateInnerGeometry();
Info::Profile::Badge _badge;
};
BadgeToastIcon::BadgeToastIcon(
QWidget *parent,
not_null<PeerData*> peer,
Info::Profile::Badge::Content content)
: Ui::RpWidget(parent)
, _badge(
this,
st::infoPeerBadge,
&peer->session(),
rpl::single(content),
nullptr,
[] { return false; },
0,
Info::Profile::BadgeType::Extera
| Info::Profile::BadgeType::ExteraSupporter
| Info::Profile::BadgeType::ExteraCustom) {
setAttribute(Qt::WA_TransparentForMouseEvents);
_badge.setOverrideStyle(&st::exteraBadgeToastBadge);
_badge.updated() | rpl::on_next([=] {
updateInnerGeometry();
}, lifetime());
updateInnerGeometry();
}
void BadgeToastIcon::updateInnerGeometry() {
const auto widget = _badge.widget();
const auto size = widget ? widget->size() : QSize();
resize(size.width(), size.height());
if (widget) {
widget->moveToLeft(0, 0);
}
}
[[nodiscard]] object_ptr<Ui::RpWidget> MakeBadgeToastIcon(
not_null<PeerData*> peer,
Info::Profile::Badge::Content content) {
return (content.badge == Info::Profile::BadgeType::None)
? object_ptr<Ui::RpWidget>(nullptr)
: object_ptr<BadgeToastIcon>(nullptr, peer, content);
}
}
Main::Session *getSession(ID userId) {
@@ -133,27 +189,33 @@ CustomBadge getCustomBadge(ID peerId) {
return {};
}
rpl::producer<Info::Profile::Badge::Content> ExteraBadgeTypeFromPeer(not_null<PeerData*> peer) {
[[nodiscard]] Info::Profile::Badge::Content ComputeExteraBadgeContent(
not_null<PeerData*> peer) {
if (isCustomBadgePeer(getBareID(peer))) {
return rpl::single(Info::Profile::Badge::Content{
return Info::Profile::Badge::Content{
.badge = Info::Profile::BadgeType::ExteraCustom,
.emojiStatusId = getCustomBadge(getBareID(peer)).emojiStatusId
});
.emojiStatusId = getCustomBadge(getBareID(peer)).emojiStatusId,
};
} else if (isExteraPeer(getBareID(peer))) {
return rpl::single(Info::Profile::Badge::Content{
.badge = Info::Profile::BadgeType::Extera
});
return Info::Profile::Badge::Content{
.badge = Info::Profile::BadgeType::Extera,
};
} else if (isSupporterPeer(getBareID(peer))) {
return rpl::single(Info::Profile::Badge::Content{
.badge = Info::Profile::BadgeType::ExteraSupporter
});
return Info::Profile::Badge::Content{
.badge = Info::Profile::BadgeType::ExteraSupporter,
};
}
return rpl::single(Info::Profile::Badge::Content{Info::Profile::BadgeType::None});
return {};
}
rpl::producer<Info::Profile::Badge::Content> ExteraBadgeTypeFromPeer(not_null<PeerData*> peer) {
return rpl::single(ComputeExteraBadgeContent(peer));
}
Fn<void()> badgeClickHandler(not_null<PeerData*> peer) {
return [=]
{
const auto badge = ComputeExteraBadgeContent(peer);
const auto isCustomBadge = isCustomBadgePeer(getBareID(peer));
const auto isExtera = isExteraPeer(getBareID(peer));
const auto isSupporter = isSupporterPeer(getBareID(peer));
@@ -198,6 +260,7 @@ Fn<void()> badgeClickHandler(not_null<PeerData*> peer) {
Ui::Toast::Show({
.text = text,
.iconContent = MakeBadgeToastIcon(peer, badge),
.st = &st::exteraBadgeToast,
.adaptive = true,
.duration = 3 * crl::time(1000),