fix: more accurate channel badge

This commit is contained in:
AlexeyZavar 2024-04-18 20:58:53 +03:00
parent 5234c8af1a
commit daec2545b4
2 changed files with 11 additions and 3 deletions

View file

@ -534,6 +534,13 @@ void Message::refreshRightBadge() {
).append(many ? QString::number(boosts) : QString()); ).append(many ? QString::number(boosts) : QString());
badge.append(' ').append(Ui::Text::Colorized(added, 1)); badge.append(' ').append(Ui::Text::Colorized(added, 1));
} }
_rightBadgeIsChannel = 0;
if (
item->isDiscussionPost() && delegate()->elementContext() != Context::Replies ||
data()->history()->peer->isMegagroup() && data()->author()->isChannel() && !data()->out()
) {
_rightBadgeIsChannel = 1;
}
if (badge.empty()) { if (badge.empty()) {
_rightBadge.clear(); _rightBadge.clear();
} else { } else {
@ -825,7 +832,7 @@ QSize Message::performCountOptimalSize() {
: 0; : 0;
if (!_rightBadge.isEmpty()) { if (!_rightBadge.isEmpty()) {
const auto badgeWidth = const auto badgeWidth =
_rightBadge.toString() == tr::lng_channel_badge(tr::now) ? st::inChannelBadgeIcon.width() : _rightBadge.maxWidth(); _rightBadgeIsChannel ? st::inChannelBadgeIcon.width() : _rightBadge.maxWidth();
namew += st::msgPadding.right() namew += st::msgPadding.right()
+ std::max(badgeWidth, replyWidth); + std::max(badgeWidth, replyWidth);
} else if (replyWidth) { } else if (replyWidth) {
@ -1456,7 +1463,7 @@ void Message::paintFromName(
return; return;
} }
const auto badgeWidth = _rightBadge.isEmpty() ? 0 : const auto badgeWidth = _rightBadge.isEmpty() ? 0 :
_rightBadge.toString() == tr::lng_channel_badge(tr::now) ? context.messageStyle()->channelBadgeIcon.width() : _rightBadge.maxWidth(); _rightBadgeIsChannel ? context.messageStyle()->channelBadgeIcon.width() : _rightBadge.maxWidth();
const auto replyWidth = [&] { const auto replyWidth = [&] {
if (isUnderCursor() && displayFastReply()) { if (isUnderCursor() && displayFastReply()) {
return st::msgFont->width(FastReplyText()); return st::msgFont->width(FastReplyText());
@ -1556,7 +1563,7 @@ void Message::paintFromName(
trect.top() + st::msgFont->ascent, trect.top() + st::msgFont->ascent,
FastReplyText()); FastReplyText());
} else { } else {
if (_rightBadge.toString() == tr::lng_channel_badge(tr::now)) { if (_rightBadgeIsChannel) {
stm->channelBadgeIcon.paint( stm->channelBadgeIcon.paint(
p, p,
trect.left() + trect.width() - rightWidth, trect.left() + trect.width() - rightWidth,

View file

@ -309,6 +309,7 @@ private:
uint32 _invertMedia : 1 = 0; uint32 _invertMedia : 1 = 0;
uint32 _hideReply : 1 = 0; uint32 _hideReply : 1 = 0;
uint32 _rightBadgeHasBoosts : 1 = 0; uint32 _rightBadgeHasBoosts : 1 = 0;
uint32 _rightBadgeIsChannel : 1 = 0;
BottomInfo _bottomInfo; BottomInfo _bottomInfo;