From d1353b7e73a8ff3a8cbe3eea46d54d3cd2b0221c Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 4 Mar 2016 16:01:39 +0200 Subject: [PATCH] admin badge added to group/supergroup profile --- Telegram/Resources/lang.strings | 1 + Telegram/SourceFiles/profilewidget.cpp | 27 ++++++++++++++++++-------- Telegram/SourceFiles/profilewidget.h | 6 +++--- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Telegram/Resources/lang.strings b/Telegram/Resources/lang.strings index 387bdd0d7..39574f5a6 100644 --- a/Telegram/Resources/lang.strings +++ b/Telegram/Resources/lang.strings @@ -429,6 +429,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org "lng_profile_add_participant" = "Add Members"; "lng_profile_delete_and_exit" = "Leave"; "lng_profile_kick" = "Remove"; +"lng_profile_admin" = "admin"; "lng_profile_sure_kick" = "Remove {user} from the group?"; "lng_profile_sure_kick_channel" = "Remove {user} from the channel?"; "lng_profile_sure_kick_admin" = "Remove {user} from administrators?"; diff --git a/Telegram/SourceFiles/profilewidget.cpp b/Telegram/SourceFiles/profilewidget.cpp index 72e7bf515..1f36133c1 100644 --- a/Telegram/SourceFiles/profilewidget.cpp +++ b/Telegram/SourceFiles/profilewidget.cpp @@ -947,24 +947,31 @@ void ProfileInner::paintEvent(QPaintEvent *e) { } else { data->online = App::onlineText(user, l_time); } + if (_peerChat) { + data->admin = (peerFromUser(_peerChat->creator) == user->id) || (_peerChat->admins.constFind(user) != _peerChat->admins.cend()); + } else if (_peerChannel) { + data->admin = (_peerChannel->mgInfo->lastAdmins.constFind(user) != _peerChannel->mgInfo->lastAdmins.cend()); + } else { + data->admin = false; + } if (_amCreator) { data->cankick = (user != App::self()); } else if (_peerChat && _peerChat->amAdmin()) { - data->cankick = (user != App::self()) && (_peerChat->admins.constFind(user) == _peerChat->admins.cend()) && (peerFromUser(_peerChat->creator) != user->id); + data->cankick = (user != App::self()) && !data->admin; } else if (_peerChannel && _peerChannel->amEditor()) { - data->cankick = (user != App::self()) && (_peerChannel->mgInfo->lastAdmins.constFind(user) == _peerChannel->mgInfo->lastAdmins.cend()); + data->cankick = (user != App::self()) && !data->admin; } else { data->cankick = (user != App::self()) && !_peerChannel && (_peerChat->invitedByMe.constFind(user) != _peerChat->invitedByMe.cend()); } } - p.setPen(st::profileListNameColor->p); - p.setFont(st::linkFont->f); + p.setPen(st::profileListNameColor); + p.setFont(st::linkFont); data->name.drawElided(p, _left + st::profileListPhotoSize + st::profileListPadding.width(), top + st::profileListNameTop, _width - _kickWidth - st::profileListPadding.width() - st::profileListPhotoSize - st::profileListPadding.width()); - p.setFont(st::profileSubFont->f); - p.setPen((App::onlineColorUse(user, l_time) ? st::profileOnlineColor : st::profileOfflineColor)->p); + p.setFont(st::profileSubFont); + p.setPen(App::onlineColorUse(user, l_time) ? st::profileOnlineColor : st::profileOfflineColor); p.drawText(_left + st::profileListPhotoSize + st::profileListPadding.width(), top + st::profileListPadding.height() + st::profileListPhotoSize - st::profileListStatusBottom, data->online); - if (data->cankick) { + if (_selectedRow == cnt && data->cankick) { bool over = (user == _kickOver && (!_kickDown || _kickDown == _kickOver)); p.setFont((over ? st::linkOverFont : st::linkFont)->f); if (user == _kickOver && _kickOver == _kickDown) { @@ -972,7 +979,11 @@ void ProfileInner::paintEvent(QPaintEvent *e) { } else { p.setPen(st::btnDefLink.color->p); } - p.drawText(_left + _width - _kickWidth, top + st::profileListNameTop + st::linkFont->ascent, lang(lng_profile_kick)); + p.drawTextRight(width() - _left - _width, top + st::profileListNameTop, width(), lang(lng_profile_kick), _kickWidth); + } else if (data->admin) { + p.setFont(st::profileSubFont); + p.setPen(st::profileOfflineColor); + p.drawTextRight(width() - _left - _width, top + st::profileListNameTop, width(), lang(lng_profile_admin)); } } top += fullCnt * _pHeight; diff --git a/Telegram/SourceFiles/profilewidget.h b/Telegram/SourceFiles/profilewidget.h index d01c91b17..46d741a7f 100644 --- a/Telegram/SourceFiles/profilewidget.h +++ b/Telegram/SourceFiles/profilewidget.h @@ -193,11 +193,11 @@ private: uint64 _contactId; UserData *_kickOver, *_kickDown, *_kickConfirm; - typedef struct { + struct ParticipantData { Text name; QString online; - bool cankick; - } ParticipantData; + bool cankick, admin; + }; typedef QVector Participants; Participants _participants; typedef QVector ParticipantsData;