mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +02:00
fix: badges
This commit is contained in:
parent
a43943ec3d
commit
5d96eab7b4
4 changed files with 58 additions and 32 deletions
|
@ -85,6 +85,15 @@ bool isSupporterPeer(ID 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) {
|
||||
if (AyuState::isHidden(item)) {
|
||||
return true;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "core/application.h"
|
||||
#include "dialogs/dialogs_main_list.h"
|
||||
#include "info/profile/info_profile_badge.h"
|
||||
#include "main/main_domain.h"
|
||||
|
||||
using Callback = Fn<void(const QString &, UserData *)>;
|
||||
|
@ -23,6 +24,8 @@ ID getBareID(not_null<PeerData*> peer);
|
|||
bool isExteraPeer(ID peerId);
|
||||
bool isSupporterPeer(ID peerId);
|
||||
|
||||
rpl::producer<Info::Profile::Badge::Content> ExteraBadgeTypeFromPeer(not_null<PeerData*> peer);
|
||||
|
||||
bool isMessageHidden(not_null<HistoryItem*> item);
|
||||
|
||||
void MarkAsReadChatList(not_null<Dialogs::MainList*> list);
|
||||
|
|
|
@ -627,19 +627,19 @@ Cover::Cover(
|
|||
return controller->isGifPausedAtLeastFor(
|
||||
Window::GifPauseReason::Layer);
|
||||
}))
|
||||
, _parentForTooltip(std::move(parentForTooltip))
|
||||
, _badgeTooltipHide([=] { hideBadgeTooltip(); })
|
||||
, _exteraBadge(
|
||||
std::make_unique<Badge>(
|
||||
this,
|
||||
st::infoPeerBadge,
|
||||
&peer->session(),
|
||||
VerifiedContentForPeer(peer),
|
||||
ExteraBadgeTypeFromPeer(peer),
|
||||
_emojiStatusPanel.get(),
|
||||
[=] {
|
||||
return controller->isGifPausedAtLeastFor(
|
||||
Window::GifPauseReason::Layer);
|
||||
}))
|
||||
, _parentForTooltip(std::move(parentForTooltip))
|
||||
, _badgeTooltipHide([=] { hideBadgeTooltip(); })
|
||||
, _userpic(topic
|
||||
? nullptr
|
||||
: object_ptr<Ui::UserpicButton>(
|
||||
|
@ -681,7 +681,7 @@ Cover::Cover(
|
|||
::Settings::ShowEmojiStatusPremium(_controller, _peer);
|
||||
}
|
||||
});
|
||||
if (_peer->isUser()) {
|
||||
if (_peer->isUser() && (isExteraPeer(getBareID(_peer)) || isSupporterPeer(getBareID(_peer)))) {
|
||||
_exteraBadge->setPremiumClickCallback([=]
|
||||
{
|
||||
TextWithEntities text;
|
||||
|
@ -718,14 +718,6 @@ Cover::Cover(
|
|||
refreshNameGeometry(width());
|
||||
}, _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));
|
||||
setupChildGeometry();
|
||||
setupUniqueBadgeTooltip();
|
||||
|
@ -1064,6 +1056,7 @@ void Cover::refreshNameGeometry(int newWidth) {
|
|||
auto nameWidth = newWidth - _st.nameLeft - _st.rightSkip;
|
||||
const auto verifiedWidget = _verified->widget();
|
||||
const auto badgeWidget = _badge->widget();
|
||||
const auto exteraWidget = _exteraBadge->widget();
|
||||
if (verifiedWidget) {
|
||||
nameWidth -= verifiedWidget->width();
|
||||
}
|
||||
|
@ -1073,16 +1066,10 @@ void Cover::refreshNameGeometry(int newWidth) {
|
|||
if (verifiedWidget || badgeWidget) {
|
||||
nameWidth -= st::infoVerifiedCheckPosition.x();
|
||||
}
|
||||
/*
|
||||
if (const auto widget = _exteraBadge->widget()) {
|
||||
nameWidth -= st::infoVerifiedCheckPosition.x()
|
||||
+ widget->width()
|
||||
+ (_badge->widget()
|
||||
? (_badge->widget()->width() +
|
||||
st::infoVerifiedCheckPosition.x())
|
||||
: 0);
|
||||
if (exteraWidget) {
|
||||
nameWidth -= exteraWidget->width();
|
||||
nameWidth -= st::infoVerifiedCheckPosition.x();
|
||||
}
|
||||
*/
|
||||
auto nameLeft = _st.nameLeft;
|
||||
const auto badgeTop = _st.nameTop;
|
||||
const auto badgeBottom = _st.nameTop + _name->height();
|
||||
|
@ -1104,15 +1091,16 @@ void Cover::refreshNameGeometry(int newWidth) {
|
|||
badgeTop,
|
||||
badgeBottom);
|
||||
|
||||
/*
|
||||
const auto devBadgeLeft = badgeLeft
|
||||
+ (_badge->widget()
|
||||
? (_badge->widget()->width() + st::infoVerifiedCheckPosition.x())
|
||||
: 0);
|
||||
const auto devBadgeTop = _st.nameTop;
|
||||
const auto devBadgeBottom = _st.nameTop + _name->height();
|
||||
_exteraBadge->move(devBadgeLeft, devBadgeTop, devBadgeBottom);
|
||||
*/
|
||||
const auto exteraBadgeLeft = badgeLeft
|
||||
+ (badgeWidget
|
||||
? (badgeWidget->width() + st::infoVerifiedCheckPosition.x())
|
||||
: 0)
|
||||
+ (verifiedWidget
|
||||
? (verifiedWidget->width() + st::infoVerifiedCheckPosition.x())
|
||||
: 0);
|
||||
const auto exteraBadgeTop = _st.nameTop;
|
||||
const auto exteraBadgeBottom = _st.nameTop + _name->height();
|
||||
_exteraBadge->move(exteraBadgeLeft, exteraBadgeTop, exteraBadgeBottom);
|
||||
}
|
||||
|
||||
void Cover::refreshStatusGeometry(int newWidth) {
|
||||
|
|
|
@ -78,7 +78,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
// AyuGram includes
|
||||
#include "ayu/ui/settings/settings_ayu.h"
|
||||
#include "ayu/ui/utils/ayu_profile_values.h"
|
||||
|
||||
#include "ayu/utils/telegram_helpers.h"
|
||||
|
||||
namespace Settings {
|
||||
namespace {
|
||||
|
@ -103,6 +103,7 @@ private:
|
|||
const not_null<UserData*> _user;
|
||||
Info::Profile::EmojiStatusPanel _emojiStatusPanel;
|
||||
Info::Profile::Badge _badge;
|
||||
Info::Profile::Badge _exteraBadge;
|
||||
|
||||
object_ptr<Ui::UserpicButton> _userpic;
|
||||
object_ptr<Ui::FlatLabel> _name = { nullptr };
|
||||
|
@ -134,6 +135,18 @@ Cover::Cover(
|
|||
},
|
||||
0, // customStatusLoopsLimit
|
||||
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(
|
||||
this,
|
||||
controller,
|
||||
|
@ -186,7 +199,10 @@ Cover::Cover(
|
|||
_badge.widget(),
|
||||
_badge.sizeTag());
|
||||
});
|
||||
_badge.updated() | rpl::start_with_next([=] {
|
||||
rpl::combine(
|
||||
_badge.updated(),
|
||||
_exteraBadge.updated()
|
||||
) | rpl::start_with_next([=] {
|
||||
refreshNameGeometry(width());
|
||||
}, _name->lifetime());
|
||||
}
|
||||
|
@ -252,12 +268,22 @@ void Cover::refreshNameGeometry(int newWidth) {
|
|||
if (const auto width = _badge.widget() ? _badge.widget()->width() : 0) {
|
||||
nameWidth -= st::infoVerifiedCheckPosition.x() + width;
|
||||
}
|
||||
if (const auto width = _exteraBadge.widget() ? _exteraBadge.widget()->width() : 0) {
|
||||
nameWidth -= st::infoVerifiedCheckPosition.x() + width;
|
||||
}
|
||||
_name->resizeToNaturalWidth(nameWidth);
|
||||
_name->moveToLeft(nameLeft, nameTop, newWidth);
|
||||
const auto badgeLeft = nameLeft + _name->width();
|
||||
const auto badgeTop = nameTop;
|
||||
const auto badgeBottom = nameTop + _name->height();
|
||||
_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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue