tdesktop/Telegram/SourceFiles/info/profile/info_profile_members_contro...

117 lines
2.8 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/profile/info_profile_members_controllers.h"
#include <rpl/variable.h>
#include "base/weak_ptr.h"
#include "boxes/peers/edit_participants_box.h"
#include "ui/widgets/popup_menu.h"
#include "lang/lang_keys.h"
#include "apiwrap.h"
2019-07-24 11:45:24 +00:00
#include "main/main_session.h"
#include "mainwidget.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_user.h"
2021-10-18 21:36:55 +00:00
#include "ui/boxes/confirm_box.h"
#include "window/window_session_controller.h"
#include "styles/style_info.h"
#include "data/data_peer_values.h"
namespace Info {
namespace Profile {
MemberListRow::MemberListRow(
not_null<UserData*> user,
Type type)
: PeerListRow(user)
, _type(type) {
}
void MemberListRow::setType(Type type) {
_type = type;
}
QSize MemberListRow::actionSize() const {
return canRemove()
? QRect(
QPoint(),
st::infoMembersRemoveIcon.size()).marginsAdded(
st::infoMembersRemoveIconMargins).size()
: QSize();
}
void MemberListRow::paintAction(
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);
}
}
int MemberListRow::nameIconWidth() const {
return (_type.rights == Rights::Admin)
? st::infoMembersAdminIcon.width()
: (_type.rights == Rights::Creator)
? st::infoMembersCreatorIcon.width()
: 0;
}
not_null<UserData*> MemberListRow::user() const {
return peer()->asUser();
}
void MemberListRow::paintNameIcon(
Painter &p,
int x,
int y,
2017-11-08 16:45:30 +00:00
int outerWidth,
bool selected) {
auto icon = [&] {
return (_type.rights == Rights::Admin)
2017-11-08 16:45:30 +00:00
? (selected
? &st::infoMembersAdminIconOver
: &st::infoMembersAdminIcon)
: (selected
? &st::infoMembersCreatorIconOver
: &st::infoMembersCreatorIcon);
}();
icon->paint(p, x, y, outerWidth);
}
2020-04-30 15:31:44 +00:00
void MemberListRow::refreshStatus() {
if (user()->isBot()) {
auto seesAllMessages = (user()->botInfo->readsAllHistory || _type.rights != Rights::Normal);
setCustomStatus(seesAllMessages
? tr::lng_status_bot_reads_all(tr::now)
: tr::lng_status_bot_not_reads_all(tr::now));
} else {
PeerListRow::refreshStatus();
}
}
std::unique_ptr<PeerListController> CreateMembersController(
not_null<Window::SessionNavigation*> navigation,
not_null<PeerData*> peer) {
return std::make_unique<ParticipantsBoxController>(
navigation,
peer,
ParticipantsBoxController::Role::Profile);
}
} // namespace Profile
} // namespace Info