From 6d7abd171886515b22f0442c74c636d125c0b8fe Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 14 Jan 2025 11:25:56 +0400 Subject: [PATCH] Don't use double-badge in profile, use two. --- .../view/history_view_chat_preview.cpp | 16 ++++- .../info/profile/info_profile_badge.cpp | 63 +++++++++---------- .../info/profile/info_profile_badge.h | 15 ++--- .../info/profile/info_profile_cover.cpp | 45 ++++++++++--- .../info/profile/info_profile_cover.h | 3 +- .../settings/settings_information.cpp | 3 +- .../SourceFiles/settings/settings_main.cpp | 3 +- .../SourceFiles/window/window_main_menu.cpp | 3 +- 8 files changed, 91 insertions(+), 60 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_chat_preview.cpp b/Telegram/SourceFiles/history/view/history_view_chat_preview.cpp index ced357db0..6b62e06a9 100644 --- a/Telegram/SourceFiles/history/view/history_view_chat_preview.cpp +++ b/Telegram/SourceFiles/history/view/history_view_chat_preview.cpp @@ -251,7 +251,20 @@ struct StatusFields { } Unexpected("Peer type in ChatPreview Item."); }); +} +[[nodiscard]] rpl::producer ContentForPeer( + not_null peer) { + using namespace Info::Profile; + return rpl::combine( + BadgeContentForPeer(peer), + VerifiedContentForPeer(peer) + ) | rpl::map([](Badge::Content &&content, Badge::Content &&verified) { + if (verified.badge == BadgeType::Verified) { + content.badge = BadgeType::Verified; + } + return content; + }); } Item::Item(not_null parent, not_null thread) @@ -274,7 +287,8 @@ Item::Item(not_null parent, not_null thread) , _badge( _top.get(), st::settingsInfoPeerBadge, - _peer, + _session, + ContentForPeer(_peer), nullptr, nullptr, 1) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_badge.cpp b/Telegram/SourceFiles/info/profile/info_profile_badge.cpp index 1bc2cbdd7..b87931bae 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_badge.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_badge.cpp @@ -24,22 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Info::Profile { namespace { -[[nodiscard]] rpl::producer ContentForPeer( - not_null peer) { - const auto statusOnlyForPremium = peer->isUser(); - return rpl::combine( - BadgeValue(peer), - EmojiStatusIdValue(peer) - ) | rpl::map([=](BadgeType badge, EmojiStatusId emojiStatusId) { - if (statusOnlyForPremium && badge != BadgeType::Premium) { - emojiStatusId = EmojiStatusId(); - } else if (emojiStatusId && badge == BadgeType::None) { - badge = BadgeType::Premium; - } - return Badge::Content{ badge, emojiStatusId }; - }); -} - [[nodiscard]] bool HasPremiumClick(const Badge::Content &content) { return content.badge == BadgeType::Premium || (content.badge == BadgeType::Verified && content.emojiStatusId); @@ -47,25 +31,6 @@ namespace { } // namespace -Badge::Badge( - not_null parent, - const style::InfoPeerBadge &st, - not_null peer, - EmojiStatusPanel *emojiStatusPanel, - Fn animationPaused, - int customStatusLoopsLimit, - base::flags allowed) -: Badge( - parent, - st, - &peer->session(), - ContentForPeer(peer), - emojiStatusPanel, - std::move(animationPaused), - customStatusLoopsLimit, - allowed) { -} - Badge::Badge( not_null parent, const style::InfoPeerBadge &st, @@ -237,4 +202,32 @@ Data::CustomEmojiSizeTag Badge::sizeTag() const { : SizeTag::Normal; } +rpl::producer BadgeContentForPeer(not_null peer) { + const auto statusOnlyForPremium = peer->isUser(); + return rpl::combine( + BadgeValue(peer), + EmojiStatusIdValue(peer) + ) | rpl::map([=](BadgeType badge, EmojiStatusId emojiStatusId) { + if (badge == BadgeType::Verified) { + badge = BadgeType::None; + } + if (statusOnlyForPremium && badge != BadgeType::Premium) { + emojiStatusId = EmojiStatusId(); + } else if (emojiStatusId && badge == BadgeType::None) { + badge = BadgeType::Premium; + } + return Badge::Content{ badge, emojiStatusId }; + }); +} + +rpl::producer VerifiedContentForPeer( + not_null peer) { + return BadgeValue(peer) | rpl::map([=](BadgeType badge) { + if (badge != BadgeType::Verified) { + badge = BadgeType::None; + } + return Badge::Content{ badge }; + }); +} + } // namespace Info::Profile diff --git a/Telegram/SourceFiles/info/profile/info_profile_badge.h b/Telegram/SourceFiles/info/profile/info_profile_badge.h index 10bf43b9b..b8495d659 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_badge.h +++ b/Telegram/SourceFiles/info/profile/info_profile_badge.h @@ -47,16 +47,6 @@ inline constexpr bool is_flag_type(BadgeType) { return true; } class Badge final { public: - Badge( - not_null parent, - const style::InfoPeerBadge &st, - not_null peer, - EmojiStatusPanel *emojiStatusPanel, - Fn animationPaused, - int customStatusLoopsLimit = 0, - base::flags allowed - = base::flags::from_raw(-1)); - struct Content { BadgeType badge = BadgeType::None; EmojiStatusId emojiStatusId; @@ -103,4 +93,9 @@ private: }; +[[nodiscard]] rpl::producer BadgeContentForPeer( + not_null peer); +[[nodiscard]] rpl::producer VerifiedContentForPeer( + not_null peer); + } // namespace Info::Profile diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index f76e8b6c9..ca657245e 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -303,7 +303,7 @@ Cover::Cover( std::move(title)) { } -[[nodiscard]] rpl::producer VerifyBadgeForPeer( +[[nodiscard]] rpl::producer BotVerifyBadgeForPeer( not_null peer) { return peer->session().changes().peerFlagsValue( peer, @@ -332,12 +332,12 @@ Cover::Cover( , _emojiStatusPanel(peer->isSelf() ? std::make_unique() : nullptr) -, _verify( +, _botVerify( std::make_unique( this, st::infoPeerBadge, &peer->session(), - VerifyBadgeForPeer(peer), + BotVerifyBadgeForPeer(peer), nullptr, [=] { return controller->isGifPausedAtLeastFor( @@ -347,7 +347,19 @@ Cover::Cover( std::make_unique( this, st::infoPeerBadge, - peer, + &peer->session(), + BadgeContentForPeer(peer), + _emojiStatusPanel.get(), + [=] { + return controller->isGifPausedAtLeastFor( + Window::GifPauseReason::Layer); + })) +, _verified( + std::make_unique( + this, + st::infoPeerBadge, + &peer->session(), + VerifiedContentForPeer(peer), _emojiStatusPanel.get(), [=] { return controller->isGifPausedAtLeastFor( @@ -395,8 +407,9 @@ Cover::Cover( } }); rpl::merge( - _verify->updated(), - _badge->updated() + _botVerify->updated(), + _badge->updated(), + _verified->updated() ) | rpl::start_with_next([=] { refreshNameGeometry(width()); }, _name->lifetime()); @@ -734,16 +747,24 @@ Cover::~Cover() { void Cover::refreshNameGeometry(int newWidth) { auto nameWidth = newWidth - _st.nameLeft - _st.rightSkip; - if (const auto widget = _badge->widget()) { - nameWidth -= st::infoVerifiedCheckPosition.x() + widget->width(); + const auto verifiedWidget = _verified->widget(); + const auto badgeWidget = _badge->widget(); + if (verifiedWidget) { + nameWidth -= verifiedWidget->width(); + } + if (badgeWidget) { + nameWidth -= badgeWidget->width(); + } + if (verifiedWidget || badgeWidget) { + nameWidth -= st::infoVerifiedCheckPosition.x(); } auto nameLeft = _st.nameLeft; const auto badgeTop = _st.nameTop; const auto badgeBottom = _st.nameTop + _name->height(); const auto margins = LargeCustomEmojiMargins(); - _verify->move(nameLeft - margins.left(), badgeTop, badgeBottom); - if (const auto widget = _verify->widget()) { + _botVerify->move(nameLeft - margins.left(), badgeTop, badgeBottom); + if (const auto widget = _botVerify->widget()) { const auto skip = widget->width() + st::infoVerifiedCheckPosition.x(); nameLeft += skip; @@ -753,6 +774,10 @@ void Cover::refreshNameGeometry(int newWidth) { _name->moveToLeft(nameLeft, _st.nameTop, newWidth); const auto badgeLeft = nameLeft + _name->width(); _badge->move(badgeLeft, badgeTop, badgeBottom); + _verified->move( + badgeLeft + (badgeWidget ? badgeWidget->width() : 0), + badgeTop, + badgeBottom); } void Cover::refreshStatusGeometry(int newWidth) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.h b/Telegram/SourceFiles/info/profile/info_profile_cover.h index f3404f977..9b972fc36 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.h +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.h @@ -147,8 +147,9 @@ private: const not_null _controller; const not_null _peer; const std::unique_ptr _emojiStatusPanel; - const std::unique_ptr _verify; + const std::unique_ptr _botVerify; const std::unique_ptr _badge; + const std::unique_ptr _verified; rpl::variable _onlineCount; const object_ptr _userpic; diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 0bbd9a1bb..a087aed74 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -104,7 +104,8 @@ ComposedBadge::ComposedBadge( , _badge( this, st::settingsInfoPeerBadge, - session->user(), + session, + Info::Profile::BadgeContentForPeer(session->user()), nullptr, std::move(animationPaused), kPlayStatusLimit, diff --git a/Telegram/SourceFiles/settings/settings_main.cpp b/Telegram/SourceFiles/settings/settings_main.cpp index e0b68cc32..bcc61bcba 100644 --- a/Telegram/SourceFiles/settings/settings_main.cpp +++ b/Telegram/SourceFiles/settings/settings_main.cpp @@ -120,7 +120,8 @@ Cover::Cover( , _badge( this, st::infoPeerBadge, - user, + &user->session(), + Info::Profile::BadgeContentForPeer(user), &_emojiStatusPanel, [=] { return controller->isGifPausedAtLeastFor( diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 93d8e5759..61157fe22 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -391,7 +391,8 @@ MainMenu::MainMenu( , _badge(std::make_unique( this, st::settingsInfoPeerBadge, - controller->session().user(), + &controller->session(), + Info::Profile::BadgeContentForPeer(controller->session().user()), _emojiStatusPanel.get(), [=] { return controller->isGifPausedAtLeastFor(GifPauseReason::Layer); }, kPlayStatusLimit,