diff --git a/Telegram/SourceFiles/ayu/ui/ayu_styles.style b/Telegram/SourceFiles/ayu/ui/ayu_styles.style index f4d841d273..db9bf0a2bd 100644 --- a/Telegram/SourceFiles/ayu/ui/ayu_styles.style +++ b/Telegram/SourceFiles/ayu/ui/ayu_styles.style @@ -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); \ No newline at end of file +ayuBetaBadgePadding: margins(4px, 1px, 4px, 1px); diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp index f1603682bd..718c34a9b6 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp @@ -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 peer, + Info::Profile::Badge::Content content); + +private: + void updateInnerGeometry(); + + Info::Profile::Badge _badge; + +}; + +BadgeToastIcon::BadgeToastIcon( + QWidget *parent, + not_null 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 MakeBadgeToastIcon( + not_null peer, + Info::Profile::Badge::Content content) { + return (content.badge == Info::Profile::BadgeType::None) + ? object_ptr(nullptr) + : object_ptr(nullptr, peer, content); +} + } Main::Session *getSession(ID userId) { @@ -133,27 +189,33 @@ CustomBadge getCustomBadge(ID peerId) { return {}; } -rpl::producer ExteraBadgeTypeFromPeer(not_null peer) { +[[nodiscard]] Info::Profile::Badge::Content ComputeExteraBadgeContent( + not_null 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 ExteraBadgeTypeFromPeer(not_null peer) { + return rpl::single(ComputeExteraBadgeContent(peer)); } Fn badgeClickHandler(not_null 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 badgeClickHandler(not_null peer) { Ui::Toast::Show({ .text = text, + .iconContent = MakeBadgeToastIcon(peer, badge), .st = &st::exteraBadgeToast, .adaptive = true, .duration = 3 * crl::time(1000),