Display verified badge in the info.

This commit is contained in:
John Preston 2017-11-06 18:13:56 +04:00
parent 230c83d218
commit 3fe12f1249
5 changed files with 64 additions and 9 deletions

View File

@ -251,6 +251,11 @@ infoProfileNameLabel: FlatLabel(infoProfileStatusLabel) {
linkFontOver: font(16px semibold underline); 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; infoProfileSkip: 12px;

View File

@ -264,17 +264,40 @@ void Cover::initViewers() {
using Flag = Notify::PeerUpdate::Flag; using Flag = Notify::PeerUpdate::Flag;
Notify::PeerUpdateValue(_peer, Flag::PhotoChanged) Notify::PeerUpdateValue(_peer, Flag::PhotoChanged)
| rpl::start_with_next( | rpl::start_with_next(
[this] { this->refreshUserpicLink(); }, [this] { refreshUserpicLink(); },
lifetime()); lifetime());
Notify::PeerUpdateValue(_peer, Flag::NameChanged) Notify::PeerUpdateValue(_peer, Flag::NameChanged)
| rpl::start_with_next( | rpl::start_with_next(
[this] { this->refreshNameText(); }, [this] { refreshNameText(); },
lifetime()); lifetime());
Notify::PeerUpdateValue(_peer, Notify::PeerUpdateValue(_peer,
Flag::UserOnlineChanged | Flag::MembersChanged) Flag::UserOnlineChanged | Flag::MembersChanged)
| rpl::start_with_next( | rpl::start_with_next(
[this] { this->refreshStatusText(); }, [this] { refreshStatusText(); },
lifetime()); 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() { void Cover::initUserpicButton() {
@ -338,15 +361,26 @@ Cover::~Cover() {
} }
void Cover::refreshNameGeometry(int newWidth) { void Cover::refreshNameGeometry(int newWidth) {
auto nameLeft = st::infoProfileNameLeft;
auto nameTop = st::infoProfileNameTop;
auto nameWidth = newWidth auto nameWidth = newWidth
- st::infoProfileNameLeft - nameLeft
- st::infoProfileNameRight - st::infoProfileNameRight
- toggleSkip(); - toggleSkip();
_name->resizeToWidth(nameWidth); if (_verifiedCheck) {
_name->moveToLeft( nameWidth -= st::infoVerifiedCheckPosition.x()
st::infoProfileNameLeft, + st::infoVerifiedCheck.width();
st::infoProfileNameTop, }
newWidth); _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) { void Cover::refreshStatusGeometry(int newWidth) {

View File

@ -81,12 +81,14 @@ private:
void refreshStatusText(); void refreshStatusText();
void refreshNameGeometry(int newWidth); void refreshNameGeometry(int newWidth);
void refreshStatusGeometry(int newWidth); void refreshStatusGeometry(int newWidth);
void setVerified(bool verified);
not_null<PeerData*> _peer; not_null<PeerData*> _peer;
int _onlineCount = 0; int _onlineCount = 0;
object_ptr<::Profile::UserpicButton> _userpic; object_ptr<::Profile::UserpicButton> _userpic;
object_ptr<Ui::FlatLabel> _name = { nullptr }; object_ptr<Ui::FlatLabel> _name = { nullptr };
object_ptr<Ui::RpWidget> _verifiedCheck = { nullptr };
object_ptr<Ui::FlatLabel> _status = { nullptr }; object_ptr<Ui::FlatLabel> _status = { nullptr };
//object_ptr<CoverDropArea> _dropArea = { nullptr }; //object_ptr<CoverDropArea> _dropArea = { nullptr };

View File

@ -214,5 +214,17 @@ rpl::producer<bool> CanAddMemberValue(
return rpl::single(false); return rpl::single(false);
} }
rpl::producer<bool> VerifiedValue(
not_null<PeerData*> 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 Profile
} // namespace Info } // namespace Info

View File

@ -73,6 +73,8 @@ rpl::producer<int> CommonGroupsCountValue(
not_null<UserData*> user); not_null<UserData*> user);
rpl::producer<bool> CanAddMemberValue( rpl::producer<bool> CanAddMemberValue(
not_null<PeerData*> peer); not_null<PeerData*> peer);
rpl::producer<bool> VerifiedValue(
not_null<PeerData*> peer);
} // namespace Profile } // namespace Profile
} // namespace Info } // namespace Info