diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 7a2f254ca2..c3ef393533 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -1580,6 +1580,7 @@ void Element::overrideRightBadge(const QString &text, BadgeRole role) { const auto badge = Get(); badge->overridden = true; badge->role = role; + badge->channel = false; badge->tag.setMarkedText( st::defaultTextStyle, { text }, diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 8cb7594829..2e14bfa91d 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -139,6 +139,24 @@ struct BadgePillGeometry { }; } +[[nodiscard]] int ComputeRightBadgeWidth( + not_null badge) { + const auto boostWidth = badge->boosts.isEmpty() + ? 0 + : (st::msgTagBadgeBoostSkip + badge->boosts.maxWidth()); + if (badge->role == BadgeRole::User) { + const auto tagWidth = (badge->channel + && AyuSettings::getInstance().replaceBottomInfoWithIcons()) + ? st::inChannelBadgeIcon.width() + : badge->tag.isEmpty() + ? 0 + : badge->tag.maxWidth(); + return tagWidth + boostWidth; + } + const auto pill = ComputeBadgePillGeometry(badge); + return pill.width + boostWidth; +} + } // namespace struct Message::CommentsButton { @@ -315,6 +333,20 @@ void Message::refreshRightBadge() { return; } const auto item = data(); + const auto drawChannelBadge = [&] { + if (item->isDiscussionPost()) { + return (delegate()->elementContext() != Context::Replies); + } else if (item->author()->isMegagroup()) { + if (const auto msgsigned = item->Get()) { + if (!msgsigned->viaBusinessBot) { + return false; + } + } + } + return item->history()->peer->isMegagroup() + && item->author()->isChannel() + && !item->out(); + }(); const auto [text, role, special] = [&]() -> std::tuple { if (item->isDiscussionPost()) { return { @@ -322,7 +354,7 @@ void Message::refreshRightBadge() { ? QString() : tr::lng_channel_badge(tr::now), BadgeRole::User, - true, + drawChannelBadge, }; } else if (item->author()->isMegagroup()) { if (const auto msgsigned = item->Get()) { @@ -331,6 +363,12 @@ void Message::refreshRightBadge() { return { msgsigned->author, BadgeRole::User, false }; } } + } else if (drawChannelBadge) { + return { + tr::lng_channel_badge(tr::now), + BadgeRole::User, + true, + }; } const auto channel = item->history()->peer->asMegagroup(); const auto user = item->author()->asUser(); @@ -398,6 +436,7 @@ void Message::refreshRightBadge() { const auto badge = Get(); badge->role = role; badge->special = special || (text.isEmpty() && !tagText.empty()); + badge->channel = drawChannelBadge; badge->tagLink = nullptr; badge->ripple = nullptr; if (tagText.empty()) { @@ -421,30 +460,12 @@ void Message::refreshRightBadge() { } else { badge->boosts.clear(); } - const auto boostWidth = badge->boosts.isEmpty() - ? 0 - : (st::msgTagBadgeBoostSkip + badge->boosts.maxWidth()); - if (badge->role == BadgeRole::User) { - const auto tagWidth = badge->tag.isEmpty() - ? 0 - : badge->tag.maxWidth(); - badge->width = tagWidth + boostWidth; - } else { - const auto &padding = st::msgTagBadgePadding; - const auto textWidth = badge->tag.maxWidth(); - const auto contentWidth = padding.left() - + textWidth - + padding.right(); - const auto pillHeight = padding.top() - + st::msgFont->height - + padding.bottom(); - badge->width = std::max(contentWidth, pillHeight) + boostWidth; - } + badge->width = ComputeRightBadgeWidth(badge); } int Message::rightBadgeWidth() const { const auto badge = Get(); - return badge ? badge->width : 0; + return badge ? ComputeRightBadgeWidth(badge) : 0; } void Message::applyGroupAdminChanges( @@ -1854,8 +1875,18 @@ void Message::paintFromName( : st::rankUserFg->c; const auto badgeLeft = trect.left() + trect.width() - - badge->width; - if (badge->role != BadgeRole::User) { + - badgeWidth; + if (badge->channel + && AyuSettings::getInstance().replaceBottomInfoWithIcons()) { + const auto badgeTop = trect.top() + + (st::msgNameFont->height + - stm->channelBadgeIcon.height()) / 2; + stm->channelBadgeIcon.paint( + p, + badgeLeft, + badgeTop, + width()); + } else if (badge->role != BadgeRole::User) { auto bgColor = badgeColor; bgColor.setAlphaF(0.15); const auto pill = ComputeBadgePillGeometry(badge); diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 09c8c3ad52..c4fb3627f4 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -78,6 +78,7 @@ struct RightBadge : RuntimeComponent { BadgeRole role = BadgeRole::User; bool overridden = false; bool special = false; + bool channel = false; mutable std::unique_ptr ripple; mutable QPoint lastPoint; };