Show who banned or restricted user in supergroup.

This commit is contained in:
John Preston 2017-08-01 20:06:40 +03:00
parent 1b46cec4fb
commit 27151d5e25
3 changed files with 46 additions and 13 deletions

View File

@ -658,6 +658,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
"lng_channel_admin_status_creator" = "Creator";
"lng_channel_admin_status_promoted_by" = "Promoted by {user}";
"lng_channel_admin_status_not_admin" = "Not administrator";
"lng_channel_banned_status_restricted_by" = "Restricted by {user}";
"lng_group_blocked_list_about" = "Banned users are removed from the group and can only come back if invited by an admin.\nInvite links don't work for them.";

View File

@ -157,6 +157,14 @@ void ParticipantsBoxController::HandleParticipant(const MTPChannelParticipant &p
auto &banned = participant.c_channelParticipantBanned();
if (auto user = App::userLoaded(banned.vuser_id.v)) {
additional->restrictedRights[user] = banned.vbanned_rights;
if (auto kickedby = App::userLoaded(banned.vkicked_by.v)) {
auto it = additional->restrictedBy.find(user);
if (it == additional->restrictedBy.end()) {
additional->restrictedBy.emplace(user, kickedby);
} else {
it->second = kickedby;
}
}
callback(user);
}
} else if (role == Role::Members && participant.type() == mtpc_channelParticipant) {
@ -367,6 +375,7 @@ void ParticipantsBoxController::editAdminDone(gsl::not_null<UserData*> user, con
_additional.adminRights[user] = rights;
_additional.kicked.erase(user);
_additional.restrictedRights.erase(user);
_additional.restrictedBy.erase(user);
if (_role == Role::Admins) {
prependRow(user);
} else {
@ -410,6 +419,7 @@ void ParticipantsBoxController::editRestrictedDone(gsl::not_null<UserData*> user
if (notBanned) {
_additional.kicked.erase(user);
_additional.restrictedRights.erase(user);
_additional.restrictedBy.erase(user);
if (_role != Role::Admins) {
removeRow(user);
}
@ -417,6 +427,7 @@ void ParticipantsBoxController::editRestrictedDone(gsl::not_null<UserData*> user
_additional.adminRights.erase(user);
_additional.adminCanEdit.erase(user);
_additional.adminPromotedBy.erase(user);
_additional.restrictedBy.emplace(user, App::self());
if (fullBanned) {
_additional.kicked.emplace(user);
_additional.restrictedRights.erase(user);
@ -482,9 +493,9 @@ bool ParticipantsBoxController::appendRow(gsl::not_null<UserData*> user) {
bool ParticipantsBoxController::prependRow(gsl::not_null<UserData*> user) {
if (auto row = delegate()->peerListFindRow(user->id)) {
refreshCustomStatus(row);
if (_role == Role::Admins) {
// Perhaps we've added a new admin from search.
refreshAdminCustomStatus(row);
delegate()->peerListPrependRowFromSearchResult(row);
}
return false;
@ -515,9 +526,7 @@ bool ParticipantsBoxController::removeRow(gsl::not_null<UserData*> user) {
std::unique_ptr<PeerListRow> ParticipantsBoxController::createRow(gsl::not_null<UserData*> user) const {
auto row = std::make_unique<PeerListRowWithLink>(user);
if (_role == Role::Admins) {
refreshAdminCustomStatus(row.get());
}
refreshCustomStatus(row.get());
if (_role == Role::Restricted || (_role == Role::Admins && _additional.adminCanEdit.find(user) != _additional.adminCanEdit.cend())) {
// row->setActionLink(lang(lng_profile_edit_permissions));
} else if (_role == Role::Kicked) {
@ -532,17 +541,26 @@ std::unique_ptr<PeerListRow> ParticipantsBoxController::createRow(gsl::not_null<
return std::move(row);
}
void ParticipantsBoxController::refreshAdminCustomStatus(gsl::not_null<PeerListRow*> row) const {
void ParticipantsBoxController::refreshCustomStatus(gsl::not_null<PeerListRow*> row) const {
auto user = row->peer()->asUser();
auto promotedBy = _additional.adminPromotedBy.find(user);
if (promotedBy == _additional.adminPromotedBy.cend()) {
if (user == _additional.creator) {
row->setCustomStatus(lang(lng_channel_admin_status_creator));
if (_role == Role::Admins) {
auto promotedBy = _additional.adminPromotedBy.find(user);
if (promotedBy == _additional.adminPromotedBy.cend()) {
if (user == _additional.creator) {
row->setCustomStatus(lang(lng_channel_admin_status_creator));
} else {
row->setCustomStatus(lang(lng_channel_admin_status_not_admin));
}
} else {
row->setCustomStatus(lang(lng_channel_admin_status_not_admin));
row->setCustomStatus(lng_channel_admin_status_promoted_by(lt_user, App::peerName(promotedBy->second)));
}
} else if (_role == Role::Kicked || _role == Role::Restricted) {
auto restrictedBy = _additional.restrictedBy.find(user);
if (restrictedBy == _additional.restrictedBy.cend()) {
row->setCustomStatus(lng_channel_banned_status_restricted_by(lt_user, "Unknown"));
} else {
row->setCustomStatus(lng_channel_banned_status_restricted_by(lt_user, App::peerName(restrictedBy->second)));
}
} else {
row->setCustomStatus(lng_channel_admin_status_promoted_by(lt_user, App::peerName(promotedBy->second)));
}
}
@ -878,6 +896,7 @@ void AddParticipantBoxController::showAdmin(gsl::not_null<UserData*> user, bool
void AddParticipantBoxController::editAdminDone(gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights) {
if (_editBox) _editBox->closeBox();
_additional.restrictedRights.erase(user);
_additional.restrictedBy.erase(user);
_additional.kicked.erase(user);
_additional.external.erase(user);
if (rights.c_channelAdminRights().vflags.v == 0) {
@ -961,6 +980,7 @@ void AddParticipantBoxController::editRestrictedDone(gsl::not_null<UserData*> us
_additional.adminPromotedBy.erase(user);
if (rights.c_channelBannedRights().vflags.v == 0) {
_additional.restrictedRights.erase(user);
_additional.restrictedBy.erase(user);
_additional.kicked.erase(user);
} else {
_additional.restrictedRights[user] = rights;
@ -969,6 +989,7 @@ void AddParticipantBoxController::editRestrictedDone(gsl::not_null<UserData*> us
} else {
_additional.kicked.erase(user);
}
_additional.restrictedBy.emplace(user, App::self());
}
if (_bannedDoneCallback) {
_bannedDoneCallback(user, rights);
@ -1047,6 +1068,7 @@ void AddParticipantBoxController::HandleParticipant(const MTPChannelParticipant
additional->infoNotLoaded.erase(user);
additional->restrictedRights.erase(user);
additional->kicked.erase(user);
additional->restrictedBy.erase(user);
additional->adminRights[user] = admin.vadmin_rights;
if (admin.is_can_edit()) {
additional->adminCanEdit.emplace(user);
@ -1087,6 +1109,14 @@ void AddParticipantBoxController::HandleParticipant(const MTPChannelParticipant
additional->kicked.erase(user);
}
additional->restrictedRights[user] = banned.vbanned_rights;
if (auto kickedby = App::userLoaded(banned.vkicked_by.v)) {
auto it = additional->restrictedBy.find(user);
if (it == additional->restrictedBy.end()) {
additional->restrictedBy.emplace(user, kickedby);
} else {
it->second = kickedby;
}
}
callback(user);
}
} break;
@ -1099,6 +1129,7 @@ void AddParticipantBoxController::HandleParticipant(const MTPChannelParticipant
additional->adminPromotedBy.erase(user);
additional->restrictedRights.erase(user);
additional->kicked.erase(user);
additional->restrictedBy.erase(user);
callback(user);
}
} break;

View File

@ -43,6 +43,7 @@ public:
std::map<gsl::not_null<UserData*>, gsl::not_null<UserData*>> adminPromotedBy;
std::map<gsl::not_null<UserData*>, MTPChannelBannedRights> restrictedRights;
std::set<gsl::not_null<UserData*>> kicked;
std::map<gsl::not_null<UserData*>, gsl::not_null<UserData*>> restrictedBy;
std::set<gsl::not_null<UserData*>> external;
std::set<gsl::not_null<UserData*>> infoNotLoaded;
UserData *creator = nullptr;
@ -78,7 +79,7 @@ private:
bool prependRow(gsl::not_null<UserData*> user);
bool removeRow(gsl::not_null<UserData*> user);
std::unique_ptr<PeerListRow> createRow(gsl::not_null<UserData*> user) const;
void refreshAdminCustomStatus(gsl::not_null<PeerListRow*> row) const;
void refreshCustomStatus(gsl::not_null<PeerListRow*> row) const;
bool feedMegagroupLastParticipants();
gsl::not_null<ChannelData*> _channel;