fix: badges

This commit is contained in:
AlexeyZavar 2025-01-29 02:49:21 +03:00
parent a43943ec3d
commit 5d96eab7b4
4 changed files with 58 additions and 32 deletions

View file

@ -85,6 +85,15 @@ bool isSupporterPeer(ID peerId) {
return RCManager::getInstance().supporters().contains(peerId); return RCManager::getInstance().supporters().contains(peerId);
} }
rpl::producer<Info::Profile::Badge::Content> ExteraBadgeTypeFromPeer(not_null<PeerData*> peer) {
if (isExteraPeer(getBareID(peer))) {
return rpl::single(Info::Profile::Badge::Content{Info::Profile::BadgeType::Extera });
} else if (isSupporterPeer(getBareID(peer))) {
return rpl::single(Info::Profile::Badge::Content{Info::Profile::BadgeType::ExteraSupporter });
}
return rpl::single(Info::Profile::Badge::Content{Info::Profile::BadgeType::None });
}
bool isMessageHidden(const not_null<HistoryItem*> item) { bool isMessageHidden(const not_null<HistoryItem*> item) {
if (AyuState::isHidden(item)) { if (AyuState::isHidden(item)) {
return true; return true;

View file

@ -10,6 +10,7 @@
#include "core/application.h" #include "core/application.h"
#include "dialogs/dialogs_main_list.h" #include "dialogs/dialogs_main_list.h"
#include "info/profile/info_profile_badge.h"
#include "main/main_domain.h" #include "main/main_domain.h"
using Callback = Fn<void(const QString &, UserData *)>; using Callback = Fn<void(const QString &, UserData *)>;
@ -23,6 +24,8 @@ ID getBareID(not_null<PeerData*> peer);
bool isExteraPeer(ID peerId); bool isExteraPeer(ID peerId);
bool isSupporterPeer(ID peerId); bool isSupporterPeer(ID peerId);
rpl::producer<Info::Profile::Badge::Content> ExteraBadgeTypeFromPeer(not_null<PeerData*> peer);
bool isMessageHidden(not_null<HistoryItem*> item); bool isMessageHidden(not_null<HistoryItem*> item);
void MarkAsReadChatList(not_null<Dialogs::MainList*> list); void MarkAsReadChatList(not_null<Dialogs::MainList*> list);

View file

@ -627,19 +627,19 @@ Cover::Cover(
return controller->isGifPausedAtLeastFor( return controller->isGifPausedAtLeastFor(
Window::GifPauseReason::Layer); Window::GifPauseReason::Layer);
})) }))
, _parentForTooltip(std::move(parentForTooltip))
, _badgeTooltipHide([=] { hideBadgeTooltip(); })
, _exteraBadge( , _exteraBadge(
std::make_unique<Badge>( std::make_unique<Badge>(
this, this,
st::infoPeerBadge, st::infoPeerBadge,
&peer->session(), &peer->session(),
VerifiedContentForPeer(peer), ExteraBadgeTypeFromPeer(peer),
_emojiStatusPanel.get(), _emojiStatusPanel.get(),
[=] { [=] {
return controller->isGifPausedAtLeastFor( return controller->isGifPausedAtLeastFor(
Window::GifPauseReason::Layer); Window::GifPauseReason::Layer);
})) }))
, _parentForTooltip(std::move(parentForTooltip))
, _badgeTooltipHide([=] { hideBadgeTooltip(); })
, _userpic(topic , _userpic(topic
? nullptr ? nullptr
: object_ptr<Ui::UserpicButton>( : object_ptr<Ui::UserpicButton>(
@ -681,7 +681,7 @@ Cover::Cover(
::Settings::ShowEmojiStatusPremium(_controller, _peer); ::Settings::ShowEmojiStatusPremium(_controller, _peer);
} }
}); });
if (_peer->isUser()) { if (_peer->isUser() && (isExteraPeer(getBareID(_peer)) || isSupporterPeer(getBareID(_peer)))) {
_exteraBadge->setPremiumClickCallback([=] _exteraBadge->setPremiumClickCallback([=]
{ {
TextWithEntities text; TextWithEntities text;
@ -718,14 +718,6 @@ Cover::Cover(
refreshNameGeometry(width()); refreshNameGeometry(width());
}, _name->lifetime()); }, _name->lifetime());
if (isExteraPeer(getBareID(_peer))) {
_exteraBadge->setContent(Info::Profile::Badge::Content{BadgeType::Extera});
} else if (isSupporterPeer(getBareID(_peer))) {
_exteraBadge->setContent(Info::Profile::Badge::Content{BadgeType::ExteraSupporter});
} else {
_exteraBadge->setContent(Info::Profile::Badge::Content{BadgeType::None});
}
initViewers(std::move(title)); initViewers(std::move(title));
setupChildGeometry(); setupChildGeometry();
setupUniqueBadgeTooltip(); setupUniqueBadgeTooltip();
@ -1064,6 +1056,7 @@ void Cover::refreshNameGeometry(int newWidth) {
auto nameWidth = newWidth - _st.nameLeft - _st.rightSkip; auto nameWidth = newWidth - _st.nameLeft - _st.rightSkip;
const auto verifiedWidget = _verified->widget(); const auto verifiedWidget = _verified->widget();
const auto badgeWidget = _badge->widget(); const auto badgeWidget = _badge->widget();
const auto exteraWidget = _exteraBadge->widget();
if (verifiedWidget) { if (verifiedWidget) {
nameWidth -= verifiedWidget->width(); nameWidth -= verifiedWidget->width();
} }
@ -1073,16 +1066,10 @@ void Cover::refreshNameGeometry(int newWidth) {
if (verifiedWidget || badgeWidget) { if (verifiedWidget || badgeWidget) {
nameWidth -= st::infoVerifiedCheckPosition.x(); nameWidth -= st::infoVerifiedCheckPosition.x();
} }
/* if (exteraWidget) {
if (const auto widget = _exteraBadge->widget()) { nameWidth -= exteraWidget->width();
nameWidth -= st::infoVerifiedCheckPosition.x() nameWidth -= st::infoVerifiedCheckPosition.x();
+ widget->width()
+ (_badge->widget()
? (_badge->widget()->width() +
st::infoVerifiedCheckPosition.x())
: 0);
} }
*/
auto nameLeft = _st.nameLeft; auto nameLeft = _st.nameLeft;
const auto badgeTop = _st.nameTop; const auto badgeTop = _st.nameTop;
const auto badgeBottom = _st.nameTop + _name->height(); const auto badgeBottom = _st.nameTop + _name->height();
@ -1104,15 +1091,16 @@ void Cover::refreshNameGeometry(int newWidth) {
badgeTop, badgeTop,
badgeBottom); badgeBottom);
/* const auto exteraBadgeLeft = badgeLeft
const auto devBadgeLeft = badgeLeft + (badgeWidget
+ (_badge->widget() ? (badgeWidget->width() + st::infoVerifiedCheckPosition.x())
? (_badge->widget()->width() + st::infoVerifiedCheckPosition.x()) : 0)
: 0); + (verifiedWidget
const auto devBadgeTop = _st.nameTop; ? (verifiedWidget->width() + st::infoVerifiedCheckPosition.x())
const auto devBadgeBottom = _st.nameTop + _name->height(); : 0);
_exteraBadge->move(devBadgeLeft, devBadgeTop, devBadgeBottom); const auto exteraBadgeTop = _st.nameTop;
*/ const auto exteraBadgeBottom = _st.nameTop + _name->height();
_exteraBadge->move(exteraBadgeLeft, exteraBadgeTop, exteraBadgeBottom);
} }
void Cover::refreshStatusGeometry(int newWidth) { void Cover::refreshStatusGeometry(int newWidth) {

View file

@ -78,7 +78,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
// AyuGram includes // AyuGram includes
#include "ayu/ui/settings/settings_ayu.h" #include "ayu/ui/settings/settings_ayu.h"
#include "ayu/ui/utils/ayu_profile_values.h" #include "ayu/ui/utils/ayu_profile_values.h"
#include "ayu/utils/telegram_helpers.h"
namespace Settings { namespace Settings {
namespace { namespace {
@ -103,6 +103,7 @@ private:
const not_null<UserData*> _user; const not_null<UserData*> _user;
Info::Profile::EmojiStatusPanel _emojiStatusPanel; Info::Profile::EmojiStatusPanel _emojiStatusPanel;
Info::Profile::Badge _badge; Info::Profile::Badge _badge;
Info::Profile::Badge _exteraBadge;
object_ptr<Ui::UserpicButton> _userpic; object_ptr<Ui::UserpicButton> _userpic;
object_ptr<Ui::FlatLabel> _name = { nullptr }; object_ptr<Ui::FlatLabel> _name = { nullptr };
@ -134,6 +135,18 @@ Cover::Cover(
}, },
0, // customStatusLoopsLimit 0, // customStatusLoopsLimit
Info::Profile::BadgeType::Premium) Info::Profile::BadgeType::Premium)
, _exteraBadge(
this,
st::infoPeerBadge,
&user->session(),
ExteraBadgeTypeFromPeer(user),
&_emojiStatusPanel,
[=] {
return controller->isGifPausedAtLeastFor(
Window::GifPauseReason::Layer);
},
0, // customStatusLoopsLimit
Info::Profile::BadgeType::Extera | Info::Profile::BadgeType::ExteraSupporter)
, _userpic( , _userpic(
this, this,
controller, controller,
@ -186,7 +199,10 @@ Cover::Cover(
_badge.widget(), _badge.widget(),
_badge.sizeTag()); _badge.sizeTag());
}); });
_badge.updated() | rpl::start_with_next([=] { rpl::combine(
_badge.updated(),
_exteraBadge.updated()
) | rpl::start_with_next([=] {
refreshNameGeometry(width()); refreshNameGeometry(width());
}, _name->lifetime()); }, _name->lifetime());
} }
@ -252,12 +268,22 @@ void Cover::refreshNameGeometry(int newWidth) {
if (const auto width = _badge.widget() ? _badge.widget()->width() : 0) { if (const auto width = _badge.widget() ? _badge.widget()->width() : 0) {
nameWidth -= st::infoVerifiedCheckPosition.x() + width; nameWidth -= st::infoVerifiedCheckPosition.x() + width;
} }
if (const auto width = _exteraBadge.widget() ? _exteraBadge.widget()->width() : 0) {
nameWidth -= st::infoVerifiedCheckPosition.x() + width;
}
_name->resizeToNaturalWidth(nameWidth); _name->resizeToNaturalWidth(nameWidth);
_name->moveToLeft(nameLeft, nameTop, newWidth); _name->moveToLeft(nameLeft, nameTop, newWidth);
const auto badgeLeft = nameLeft + _name->width(); const auto badgeLeft = nameLeft + _name->width();
const auto badgeTop = nameTop; const auto badgeTop = nameTop;
const auto badgeBottom = nameTop + _name->height(); const auto badgeBottom = nameTop + _name->height();
_badge.move(badgeLeft, badgeTop, badgeBottom); _badge.move(badgeLeft, badgeTop, badgeBottom);
const auto exteraBadgeLeft = badgeLeft
+ (_badge.widget()
? (_badge.widget()->width() + st::infoVerifiedCheckPosition.x())
: 0);
const auto exteraBadgeTop = nameTop;
const auto exteraBadgeBottom = nameTop + _name->height();
_exteraBadge.move(exteraBadgeLeft, exteraBadgeTop, exteraBadgeBottom);
} }
void Cover::refreshIdGeometry(int newWidth) { void Cover::refreshIdGeometry(int newWidth) {