From 3fe12f1249cbe2d7c94a0a2bad22d338f26c518f Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 6 Nov 2017 18:13:56 +0400 Subject: [PATCH] Display verified badge in the info. --- Telegram/SourceFiles/info/info.style | 5 ++ .../info/profile/info_profile_cover.cpp | 52 +++++++++++++++---- .../info/profile/info_profile_cover.h | 2 + .../info/profile/info_profile_values.cpp | 12 +++++ .../info/profile/info_profile_values.h | 2 + 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index 615d77b67..c454a51ab 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -251,6 +251,11 @@ infoProfileNameLabel: FlatLabel(infoProfileStatusLabel) { linkFontOver: font(16px semibold underline); } } +infoVerifiedCheckPosition: point(10px, 2px); +infoVerifiedCheck: icon { + { "profile_verified_star", profileVerifiedCheckBg, point(0px, 0px) }, + { "profile_verified_check", profileVerifiedCheckFg, point(4px, 4px) } +}; infoProfileSkip: 12px; diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index 1108b4c9b..f217be9a3 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -264,17 +264,40 @@ void Cover::initViewers() { using Flag = Notify::PeerUpdate::Flag; Notify::PeerUpdateValue(_peer, Flag::PhotoChanged) | rpl::start_with_next( - [this] { this->refreshUserpicLink(); }, + [this] { refreshUserpicLink(); }, lifetime()); Notify::PeerUpdateValue(_peer, Flag::NameChanged) | rpl::start_with_next( - [this] { this->refreshNameText(); }, + [this] { refreshNameText(); }, lifetime()); Notify::PeerUpdateValue(_peer, Flag::UserOnlineChanged | Flag::MembersChanged) | rpl::start_with_next( - [this] { this->refreshStatusText(); }, + [this] { refreshStatusText(); }, lifetime()); + VerifiedValue(_peer) + | rpl::start_with_next( + [this](bool verified) { setVerified(verified); }, + lifetime()); +} + +void Cover::setVerified(bool verified) { + if ((_verifiedCheck != nullptr) == verified) { + return; + } + if (verified) { + _verifiedCheck.create(this); + _verifiedCheck->show(); + _verifiedCheck->resize(st::infoVerifiedCheck.size()); + _verifiedCheck->paintRequest() + | rpl::start_with_next([check = _verifiedCheck.data()] { + Painter p(check); + st::infoVerifiedCheck.paint(p, 0, 0, check->width()); + }, _verifiedCheck->lifetime()); + } else { + _verifiedCheck.destroy(); + } + refreshNameGeometry(width()); } void Cover::initUserpicButton() { @@ -338,15 +361,26 @@ Cover::~Cover() { } void Cover::refreshNameGeometry(int newWidth) { + auto nameLeft = st::infoProfileNameLeft; + auto nameTop = st::infoProfileNameTop; auto nameWidth = newWidth - - st::infoProfileNameLeft + - nameLeft - st::infoProfileNameRight - toggleSkip(); - _name->resizeToWidth(nameWidth); - _name->moveToLeft( - st::infoProfileNameLeft, - st::infoProfileNameTop, - newWidth); + if (_verifiedCheck) { + nameWidth -= st::infoVerifiedCheckPosition.x() + + st::infoVerifiedCheck.width(); + } + _name->resizeToNaturalWidth(nameWidth); + _name->moveToLeft(nameLeft, nameTop, newWidth); + if (_verifiedCheck) { + auto checkLeft = nameLeft + + _name->width() + + st::infoVerifiedCheckPosition.x(); + auto checkTop = nameTop + + st::infoVerifiedCheckPosition.y(); + _verifiedCheck->moveToLeft(checkLeft, checkTop, newWidth); + } } void Cover::refreshStatusGeometry(int newWidth) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.h b/Telegram/SourceFiles/info/profile/info_profile_cover.h index e1c54cee2..320d06a65 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.h +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.h @@ -81,12 +81,14 @@ private: void refreshStatusText(); void refreshNameGeometry(int newWidth); void refreshStatusGeometry(int newWidth); + void setVerified(bool verified); not_null _peer; int _onlineCount = 0; object_ptr<::Profile::UserpicButton> _userpic; object_ptr _name = { nullptr }; + object_ptr _verifiedCheck = { nullptr }; object_ptr _status = { nullptr }; //object_ptr _dropArea = { nullptr }; diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index b60320f48..05ddc58a0 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -214,5 +214,17 @@ rpl::producer CanAddMemberValue( return rpl::single(false); } +rpl::producer VerifiedValue( + not_null peer) { + if (auto user = peer->asUser()) { + return Data::PeerFlagValue(user, MTPDuser::Flag::f_verified); + } else if (auto channel = peer->asChannel()) { + return Data::PeerFlagValue( + channel, + MTPDchannel::Flag::f_verified); + } + return rpl::single(false); +} + } // namespace Profile } // namespace Info diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.h b/Telegram/SourceFiles/info/profile/info_profile_values.h index 5702ac0a6..a80a98ab2 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.h +++ b/Telegram/SourceFiles/info/profile/info_profile_values.h @@ -73,6 +73,8 @@ rpl::producer CommonGroupsCountValue( not_null user); rpl::producer CanAddMemberValue( not_null peer); +rpl::producer VerifiedValue( + not_null peer); } // namespace Profile } // namespace Info