mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
fix: restore channel badge
This commit is contained in:
@@ -1580,6 +1580,7 @@ void Element::overrideRightBadge(const QString &text, BadgeRole role) {
|
||||
const auto badge = Get<RightBadge>();
|
||||
badge->overridden = true;
|
||||
badge->role = role;
|
||||
badge->channel = false;
|
||||
badge->tag.setMarkedText(
|
||||
st::defaultTextStyle,
|
||||
{ text },
|
||||
|
||||
@@ -139,6 +139,24 @@ struct BadgePillGeometry {
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]] int ComputeRightBadgeWidth(
|
||||
not_null<const RightBadge*> 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<HistoryMessageSigned>()) {
|
||||
if (!msgsigned->viaBusinessBot) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return item->history()->peer->isMegagroup()
|
||||
&& item->author()->isChannel()
|
||||
&& !item->out();
|
||||
}();
|
||||
const auto [text, role, special] = [&]() -> std::tuple<QString, BadgeRole, bool> {
|
||||
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<HistoryMessageSigned>()) {
|
||||
@@ -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<RightBadge>();
|
||||
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<RightBadge>();
|
||||
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);
|
||||
|
||||
@@ -78,6 +78,7 @@ struct RightBadge : RuntimeComponent<RightBadge, Element> {
|
||||
BadgeRole role = BadgeRole::User;
|
||||
bool overridden = false;
|
||||
bool special = false;
|
||||
bool channel = false;
|
||||
mutable std::unique_ptr<Ui::RippleAnimation> ripple;
|
||||
mutable QPoint lastPoint;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user