Allow to delete users from exceptions.

This commit is contained in:
John Preston 2019-01-31 20:31:44 +03:00
parent d2d6a6daa4
commit 55d3d8adc3
4 changed files with 43 additions and 20 deletions

View File

@ -145,8 +145,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_sure_add_admin_invite_channel" = "This user is not a subscriber of this channel. Add them to the channel and promote them to admin?";
"lng_sure_add_admin_unremove" = "This user is currently restricted or removed. Are you sure you want to promote them?";
"lng_sure_ban_admin" = "This user is an admin. Are you sure you want to go ahead and restrict them?";
"lng_sure_remove_user_group" = "Remove {user} from the group?";
"lng_sure_remove_user_channel" = "Remove {user} from the channel?";
"lng_sure_enable_socks" = "Are you sure you want to enable this proxy?\n\nServer: {server}\nPort: {port}\n\nYou can change your proxy server later in the Settings (Connection Type).";
"lng_sure_enable" = "Enable";

View File

@ -710,27 +710,30 @@ void AddSpecialBoxController::kickUser(
// Finally kick him.
if (!sure) {
const auto text = ((_peer->isChat() || _peer->isMegagroup())
? lng_sure_remove_user_group
: lng_sure_remove_user_channel)(lt_user, App::peerName(user));
? lng_profile_sure_kick
: lng_profile_sure_kick_channel)(lt_user, App::peerName(user));
_editBox = Ui::show(
Box<ConfirmBox>(text, kickUserSure),
LayerOption::KeepOther);
return;
}
_editBox = nullptr;
const auto restrictedRights = _additional.restrictedRights(user);
const auto currentRights = restrictedRights
? *restrictedRights
: MTPChatBannedRights(MTP_chatBannedRights(
MTP_flags(0),
MTP_int(0)));
auto &session = _peer->session();
if (const auto chat = _peer->asChat()) {
session.api().kickParticipant(chat, user);
} else if (const auto channel = _peer->asChannel()) {
session.api().kickParticipant(channel, user, currentRights);
}
const auto done = crl::guard(this, [=](
const MTPChatBannedRights &newRights) {
editRestrictedDone(user, newRights);
});
const auto fail = crl::guard(this, [=] {
_editBox = nullptr;
});
const auto callback = SaveRestrictedCallback(_peer, user, done, fail);
callback(currentRights, ChannelData::KickedRestrictedRights());
}
bool AddSpecialBoxController::appendRow(not_null<UserData*> user) {

View File

@ -95,10 +95,6 @@ private:
not_null<UserData*> user,
const MTPChatBannedRights &rights);
void kickUser(not_null<UserData*> user, bool sure = false);
void restrictUserSure(
not_null<UserData*> user,
const MTPChatBannedRights &oldRights,
const MTPChatBannedRights &newRights);
bool appendRow(not_null<UserData*> user);
bool prependRow(not_null<UserData*> user);
std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user) const;

View File

@ -179,6 +179,26 @@ void SaveChannelRestriction(
}).send();
}
void SaveChatParticipantKick(
not_null<ChatData*> chat,
not_null<UserData*> user,
Fn<void()> onDone,
Fn<void()> onFail) {
chat->session().api().request(MTPmessages_DeleteChatUser(
chat->inputChat,
user->inputUser
)).done([=](const MTPUpdates &result) {
chat->session().api().applyUpdates(result);
if (onDone) {
onDone();
}
}).fail([=](const RPCError &error) {
if (onFail) {
onFail();
}
}).send();
}
} // namespace
Fn<void(
@ -249,7 +269,9 @@ Fn<void(
const MTPDchatBannedRights &data) {
return data.vflags.v;
});
if (!flags) {
if (flags & MTPDchatBannedRights::Flag::f_view_messages) {
SaveChatParticipantKick(chat, user, done, onFail);
} else if (!flags) {
done();
} else {
peer->session().api().migrateChat(chat, saveForChannel);
@ -1333,8 +1355,6 @@ void ParticipantsBoxController::rowActionClicked(
kickMember(user);
} else if (_role == Role::Admins) {
removeAdmin(user);
} else if (_role == Role::Restricted) {
showRestricted(user);
} else {
removeKicked(row, user);
}
@ -1628,6 +1648,10 @@ void ParticipantsBoxController::removeKicked(
not_null<PeerListRow*> row,
not_null<UserData*> user) {
delegate()->peerListRemoveRow(row);
if (_role != Role::Kicked
&& !delegate()->peerListFullRowsCount()) {
setDescriptionText(lang(lng_blocked_list_not_found));
}
delegate()->peerListRefreshRows();
removeKicked(user);
}
@ -1692,8 +1716,10 @@ std::unique_ptr<PeerListRow> ParticipantsBoxController::createRow(
&& _additional.adminRights(user).has_value()
&& _additional.canEditAdmin(user)) {
row->setActionLink(lang(lng_profile_kick));
} else if (_role == Role::Kicked) {
row->setActionLink(lang(lng_profile_delete_removed));
} else if (_role == Role::Kicked || _role == Role::Restricted) {
if (_additional.canRestrictUser(user)) {
row->setActionLink(lang(lng_profile_delete_removed));
}
} else if (_role == Role::Members) {
if ((chat ? chat->canBanMembers() : channel->canBanMembers())
&& !_additional.isCreator(user)