mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-18 22:17:01 +00:00
Display premium / fake / scam badge in group members.
This commit is contained in:
parent
3b379c67ac
commit
490f6f7e50
@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "base/unixtime.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "info/profile/info_profile_values.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "history/history.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
@ -1930,8 +1931,19 @@ auto ParticipantsBoxController::computeType(
|
||||
: (user && _additional.adminRights(user).has_value())
|
||||
? Rights::Admin
|
||||
: Rights::Normal;
|
||||
// result.canRemove = _additional.canRemoveParticipant(participant);
|
||||
result.adminRank = user ? _additional.adminRank(user) : QString();
|
||||
using Badge = Info::Profile::Badge;
|
||||
result.badge = !user
|
||||
? Badge::None
|
||||
: user->isScam()
|
||||
? Badge::Scam
|
||||
: user->isFake()
|
||||
? Badge::Fake
|
||||
: user->isVerified()
|
||||
? Badge::Verified
|
||||
: user->isPremium()
|
||||
? Badge::Premium
|
||||
: Badge::None;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -492,14 +492,6 @@ infoMembersAdminIconOver: icon {{
|
||||
profileOtherAdminStarFgOver,
|
||||
point(4px, 3px)
|
||||
}};
|
||||
infoMembersRemoveIcon: icon {{
|
||||
"simple_close",
|
||||
menuIconFg
|
||||
}};
|
||||
infoMembersRemoveIconOver: icon {{
|
||||
"simple_close",
|
||||
menuIconFgOver
|
||||
}};
|
||||
infoMembersAdminIconMarigns: margins(10px, 18px, 10px, 10px);
|
||||
infoMembersRemoveIconMargins: margins(10px, 12px, 12px, 10px);
|
||||
|
||||
|
@ -8,10 +8,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "info/profile/info_profile_members_controllers.h"
|
||||
|
||||
#include "boxes/peers/edit_participants_box.h"
|
||||
#include "info/profile/info_profile_values.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_user.h"
|
||||
#include "ui/unread_badge.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
|
||||
namespace Info {
|
||||
namespace Profile {
|
||||
@ -21,63 +25,48 @@ MemberListRow::MemberListRow(
|
||||
Type type)
|
||||
: PeerListRowWithLink(user)
|
||||
, _type(type) {
|
||||
PeerListRowWithLink::setActionLink(_type.adminRank);
|
||||
setType(type);
|
||||
}
|
||||
|
||||
void MemberListRow::setType(Type type) {
|
||||
_type = type;
|
||||
PeerListRowWithLink::setActionLink(_type.adminRank);
|
||||
_fakeScamSize = (_type.badge == Badge::Fake)
|
||||
? Ui::ScamBadgeSize(true)
|
||||
: (_type.badge == Badge::Scam)
|
||||
? Ui::ScamBadgeSize(false)
|
||||
: QSize();
|
||||
PeerListRowWithLink::setActionLink(!_type.adminRank.isEmpty()
|
||||
? _type.adminRank
|
||||
: (_type.rights == Rights::Creator)
|
||||
? tr::lng_owner_badge(tr::now)
|
||||
: (_type.rights == Rights::Admin)
|
||||
? tr::lng_admin_badge(tr::now)
|
||||
: QString());
|
||||
}
|
||||
|
||||
bool MemberListRow::rightActionDisabled() const {
|
||||
return !canRemove();
|
||||
}
|
||||
|
||||
QSize MemberListRow::rightActionSize() const {
|
||||
return canRemove()
|
||||
? QRect(
|
||||
QPoint(),
|
||||
st::infoMembersRemoveIcon.size()).marginsAdded(
|
||||
st::infoMembersRemoveIconMargins).size()
|
||||
: PeerListRowWithLink::rightActionSize();
|
||||
}
|
||||
|
||||
void MemberListRow::rightActionPaint(
|
||||
Painter &p,
|
||||
int x,
|
||||
int y,
|
||||
int outerWidth,
|
||||
bool selected,
|
||||
bool actionSelected) {
|
||||
if (_type.canRemove && selected) {
|
||||
x += st::infoMembersRemoveIconMargins.left();
|
||||
y += st::infoMembersRemoveIconMargins.top();
|
||||
(actionSelected
|
||||
? st::infoMembersRemoveIconOver
|
||||
: st::infoMembersRemoveIcon).paint(p, x, y, outerWidth);
|
||||
} else {
|
||||
PeerListRowWithLink::rightActionPaint(
|
||||
p,
|
||||
x,
|
||||
y,
|
||||
outerWidth,
|
||||
selected,
|
||||
actionSelected);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QMargins MemberListRow::rightActionMargins() const {
|
||||
return canRemove()
|
||||
? QMargins()
|
||||
: PeerListRowWithLink::rightActionMargins();
|
||||
const auto skip = st::contactsCheckPosition.x();
|
||||
return QMargins(
|
||||
skip,
|
||||
st::defaultPeerListItem.namePosition.y(),
|
||||
st::defaultPeerListItem.photoPosition.x() + skip,
|
||||
0);
|
||||
}
|
||||
|
||||
int MemberListRow::nameIconWidth() const {
|
||||
return (_type.rights == Rights::Admin)
|
||||
? st::infoMembersAdminIcon.width()
|
||||
: (_type.rights == Rights::Creator)
|
||||
? st::infoMembersCreatorIcon.width()
|
||||
: 0;
|
||||
switch (_type.badge) {
|
||||
case Badge::None: return 0;
|
||||
case Badge::Verified: return st::dialogsVerifiedIcon.width();
|
||||
case Badge::Premium: return st::dialogsPremiumIcon.width();
|
||||
case Badge::Scam:
|
||||
case Badge::Fake:
|
||||
return st::dialogsScamSkip + _fakeScamSize.width();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
not_null<UserData*> MemberListRow::user() const {
|
||||
@ -90,16 +79,31 @@ void MemberListRow::paintNameIcon(
|
||||
int y,
|
||||
int outerWidth,
|
||||
bool selected) {
|
||||
const auto icon = [&] {
|
||||
return (_type.rights == Rights::Admin)
|
||||
? (selected
|
||||
? &st::infoMembersAdminIconOver
|
||||
: &st::infoMembersAdminIcon)
|
||||
: (selected
|
||||
? &st::infoMembersCreatorIconOver
|
||||
: &st::infoMembersCreatorIcon);
|
||||
}();
|
||||
icon->paint(p, x, y, outerWidth);
|
||||
switch (_type.badge) {
|
||||
case Badge::None: return;
|
||||
case Badge::Verified:
|
||||
(selected
|
||||
? st::dialogsVerifiedIconOver
|
||||
: st::dialogsVerifiedIcon).paint(p, x, y, outerWidth);
|
||||
break;
|
||||
case Badge::Premium:
|
||||
(selected
|
||||
? st::dialogsPremiumIconOver
|
||||
: st::dialogsPremiumIcon).paint(p, x, y, outerWidth);
|
||||
break;
|
||||
case Badge::Scam:
|
||||
case Badge::Fake:
|
||||
return Ui::DrawScamBadge(
|
||||
(_type.badge == Badge::Fake),
|
||||
p,
|
||||
QRect(
|
||||
x + st::dialogsScamSkip,
|
||||
y + (st::normalFont->height - _fakeScamSize.height()) / 2,
|
||||
_fakeScamSize.width(),
|
||||
_fakeScamSize.height()),
|
||||
outerWidth,
|
||||
(selected ? st::dialogsScamFgOver : st::dialogsScamFg));
|
||||
}
|
||||
}
|
||||
|
||||
void MemberListRow::refreshStatus() {
|
||||
@ -114,10 +118,6 @@ void MemberListRow::refreshStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
bool MemberListRow::canRemove() const {
|
||||
return _type.canRemove;
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListController> CreateMembersController(
|
||||
not_null<Window::SessionNavigation*> navigation,
|
||||
not_null<PeerData*> peer) {
|
||||
|
@ -16,6 +16,8 @@ class SessionNavigation;
|
||||
namespace Info {
|
||||
namespace Profile {
|
||||
|
||||
enum class Badge;
|
||||
|
||||
class MemberListRow final : public PeerListRowWithLink {
|
||||
public:
|
||||
enum class Rights {
|
||||
@ -24,8 +26,8 @@ public:
|
||||
Creator,
|
||||
};
|
||||
struct Type {
|
||||
Badge badge;
|
||||
Rights rights;
|
||||
bool canRemove = false;
|
||||
QString adminRank;
|
||||
};
|
||||
|
||||
@ -34,14 +36,6 @@ public:
|
||||
void setType(Type type);
|
||||
bool rightActionDisabled() const override;
|
||||
QMargins rightActionMargins() const override;
|
||||
QSize rightActionSize() const override;
|
||||
void rightActionPaint(
|
||||
Painter &p,
|
||||
int x,
|
||||
int y,
|
||||
int outerWidth,
|
||||
bool selected,
|
||||
bool actionSelected) override;
|
||||
int nameIconWidth() const override;
|
||||
void paintNameIcon(
|
||||
Painter &p,
|
||||
@ -54,8 +48,8 @@ public:
|
||||
not_null<UserData*> user() const;
|
||||
|
||||
private:
|
||||
[[nodiscard]] bool canRemove() const;
|
||||
Type _type;
|
||||
QSize _fakeScamSize;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user