Always show that bot-admin reads all messages.

A bot with any admin rights has access to messages.
This commit is contained in:
John Preston 2017-06-17 22:51:23 +03:00
parent 8fe56b9a7d
commit c3ad0ae129
8 changed files with 139 additions and 107 deletions

View File

@ -1430,8 +1430,8 @@ void ContactsBox::Inner::addSelectedAsChannelAdmin() {
}
if (_addAdminBox) _addAdminBox->deleteLater();
auto showBox = [this](auto &&currentRights) {
_addAdminBox = Ui::show(Box<EditAdminBox>(_channel, _addAdmin, currentRights, base::lambda_guarded(this, [this](const MTPChannelAdminRights &rights) {
auto showBox = [this](auto &&currentRights, bool hasAdminRights) {
_addAdminBox = Ui::show(Box<EditAdminBox>(_channel, _addAdmin, hasAdminRights, currentRights, base::lambda_guarded(this, [this](const MTPChannelAdminRights &rights) {
if (_addAdminRequestId) return;
_addAdminRequestId = MTP::send(MTPchannels_EditAdmin(_channel->inputChannel, _addAdmin->inputUser, rights), rpcDone(&Inner::addAdminDone, rights), rpcFail(&Inner::addAdminFail));
})), KeepOtherLayers);
@ -1449,7 +1449,7 @@ void ContactsBox::Inner::addSelectedAsChannelAdmin() {
if (auto rights = loadedRights()) {
if (rights->canEdit) {
showBox(rights->rights);
showBox(rights->rights, true);
} else {
Ui::show(Box<InformBox>(lang(lng_error_cant_edit_admin)), KeepOtherLayers);
}
@ -1462,12 +1462,12 @@ void ContactsBox::Inner::addSelectedAsChannelAdmin() {
_addAdminRequestId = 0;
if (participant.vparticipant.type() == mtpc_channelParticipantAdmin) {
if (participant.vparticipant.c_channelParticipantAdmin().is_can_edit()) {
showBox(participant.vparticipant.c_channelParticipantAdmin().vadmin_rights);
showBox(participant.vparticipant.c_channelParticipantAdmin().vadmin_rights, true);
} else {
Ui::show(Box<InformBox>(lang(lng_error_cant_edit_admin)), KeepOtherLayers);
}
} else {
showBox(EditAdminBox::DefaultRights(_channel));
showBox(EditAdminBox::DefaultRights(_channel), false);
}
})), ::rpcFail(base::lambda_guarded(this, [this](const RPCError &error) {
if (MTP::isDefaultHandledError(error)) {

View File

@ -72,9 +72,10 @@ void ApplyDependencies(CheckboxesMap &checkboxes, DependenciesMap &dependencies,
class EditParticipantBox::Inner : public TWidget {
public:
Inner(QWidget *parent, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user) : TWidget(parent)
, _channel(channel)
, _user(user) {
Inner(QWidget *parent, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights) : TWidget(parent)
, _channel(channel)
, _user(user)
, _hasAdminRights(hasAdminRights) {
}
template <typename Widget>
@ -92,6 +93,7 @@ protected:
private:
gsl::not_null<ChannelData*> _channel;
gsl::not_null<UserData*> _user;
bool _hasAdminRights = false;
std::vector<object_ptr<TWidget>> _rows;
};
@ -130,8 +132,7 @@ void EditParticipantBox::Inner::paintEvent(QPaintEvent *e) {
_user->nameText.drawLeftElided(p, namex, st::contactsNameTop, namew, width());
auto statusText = [this] {
if (_user->botInfo) {
auto isAdmin = _channel->mgInfo ? _channel->mgInfo->lastAdmins.contains(_user) : false;
auto seesAllMessages = (_user->botInfo->readsAllHistory || isAdmin);
auto seesAllMessages = (_user->botInfo->readsAllHistory || _hasAdminRights);
return lang(seesAllMessages ? lng_status_bot_reads_all : lng_status_bot_not_reads_all);
}
return App::onlineText(_user->onlineTill, unixtime());
@ -141,13 +142,14 @@ void EditParticipantBox::Inner::paintEvent(QPaintEvent *e) {
p.drawTextLeft(namex, st::contactsStatusTop, width(), statusText());
}
EditParticipantBox::EditParticipantBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user) : BoxContent()
EditParticipantBox::EditParticipantBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights) : BoxContent()
, _channel(channel)
, _user(user) {
, _user(user)
, _hasAdminRights(hasAdminRights) {
}
void EditParticipantBox::prepare() {
_inner = setInnerWidget(object_ptr<Inner>(this, _channel, _user));
_inner = setInnerWidget(object_ptr<Inner>(this, _channel, _user, hasAdminRights()));
}
template <typename Widget>
@ -161,7 +163,7 @@ void EditParticipantBox::resizeToContent() {
setDimensions(_inner->width(), _inner->height());
}
EditAdminBox::EditAdminBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights, base::lambda<void(MTPChannelAdminRights)> callback) : EditParticipantBox(nullptr, channel, user)
EditAdminBox::EditAdminBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights, const MTPChannelAdminRights &rights, base::lambda<void(MTPChannelAdminRights)> callback) : EditParticipantBox(nullptr, channel, user, hasAdminRights)
, _rights(rights)
, _saveCallback(std::move(callback)) {
auto dependency = [this](Flag dependent, Flag dependency) {
@ -261,7 +263,7 @@ void EditAdminBox::refreshAboutAddAdminsText() {
resizeToContent();
}
EditRestrictedBox::EditRestrictedBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, const MTPChannelBannedRights &rights, base::lambda<void(MTPChannelBannedRights)> callback) : EditParticipantBox(nullptr, channel, user)
EditRestrictedBox::EditRestrictedBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights, const MTPChannelBannedRights &rights, base::lambda<void(MTPChannelBannedRights)> callback) : EditParticipantBox(nullptr, channel, user, hasAdminRights)
, _rights(rights)
, _until(rights.c_channelBannedRights().vuntil_date.v)
, _saveCallback(std::move(callback)) {

View File

@ -32,7 +32,7 @@ class CalendarBox;
class EditParticipantBox : public BoxContent {
public:
EditParticipantBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user);
EditParticipantBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights);
protected:
void prepare() override;
@ -49,9 +49,14 @@ protected:
template <typename Widget>
QPointer<Widget> addControl(object_ptr<Widget> row);
bool hasAdminRights() const {
return _hasAdminRights;
}
private:
gsl::not_null<UserData*> _user;
gsl::not_null<ChannelData*> _channel;
gsl::not_null<UserData*> _user;
bool _hasAdminRights = false;
class Inner;
QPointer<Inner> _inner;
@ -60,7 +65,7 @@ private:
class EditAdminBox : public EditParticipantBox {
public:
EditAdminBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights, base::lambda<void(MTPChannelAdminRights)> callback);
EditAdminBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights, const MTPChannelAdminRights &rights, base::lambda<void(MTPChannelAdminRights)> callback);
static MTPChannelAdminRights DefaultRights(gsl::not_null<ChannelData*> channel);
@ -88,7 +93,7 @@ private:
class EditRestrictedBox : public EditParticipantBox {
public:
EditRestrictedBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, const MTPChannelBannedRights &rights, base::lambda<void(MTPChannelBannedRights)> callback);
EditRestrictedBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights, const MTPChannelBannedRights &rights, base::lambda<void(MTPChannelBannedRights)> callback);
static MTPChannelBannedRights DefaultRights(gsl::not_null<ChannelData*> channel);
static constexpr auto kRestrictUntilForever = TimeId(INT_MAX);

View File

@ -274,7 +274,8 @@ void MembersBox::Inner::actionPressed(Member &row) {
})), KeepOtherLayers);
} else {
auto currentRights = _rows[_kickSelected].adminRights;
_kickBox = Ui::show(Box<EditAdminBox>(_channel, user, currentRights, base::lambda_guarded(this, [this, user](const MTPChannelAdminRights &rights) {
auto hasAdminRights = true;
_kickBox = Ui::show(Box<EditAdminBox>(_channel, user, hasAdminRights, currentRights, base::lambda_guarded(this, [this, user](const MTPChannelAdminRights &rights) {
if (_kickBox) _kickBox->closeBox();
MTP::send(MTPchannels_EditAdmin(_channel->inputChannel, user->inputUser, rights), ::rpcDone(base::lambda_guarded(this, [this, user, rights](const MTPUpdates &result, mtpRequestId req) {
if (App::main()) App::main()->sentUpdatesReceived(result);

View File

@ -1741,11 +1741,17 @@ void HistoryWidget::fastShowAtEnd(History *h) {
void HistoryWidget::applyDraft(bool parseLinks, Ui::FlatTextarea::UndoHistoryAction undoHistoryAction) {
auto draft = _history ? _history->draft() : nullptr;
if (!draft || !canWriteMessage()) {
auto fieldAvailable = canWriteMessage();
if (!draft || (!_history->editDraft() && !fieldAvailable)) {
auto fieldWillBeHiddenAfterEdit = (!fieldAvailable && _editMsgId != 0);
clearFieldText(0, undoHistoryAction);
_field->setFocus();
_replyEditMsg = nullptr;
_editMsgId = _replyToId = 0;
if (fieldWillBeHiddenAfterEdit) {
updateControlsVisibility();
updateControlsGeometry();
}
return;
}
@ -1763,6 +1769,10 @@ void HistoryWidget::applyDraft(bool parseLinks, Ui::FlatTextarea::UndoHistoryAct
_editMsgId = 0;
_replyToId = readyToForward() ? 0 : _history->localDraft()->msgId;
}
if (!canWriteMessage()) {
updateControlsVisibility();
updateControlsGeometry();
}
if (parseLinks) {
onPreviewParse();
@ -2201,10 +2211,11 @@ void HistoryWidget::updateControlsVisibility() {
if (_reportSpamPanel) {
_reportSpamPanel->show();
}
if (isBlocked() || isJoinChannel() || isMuteUnmute()) {
if (!editingMessage() && (isBlocked() || isJoinChannel() || isMuteUnmute() || isBotStart())) {
if (isBlocked()) {
_joinChannel->hide();
_muteUnmute->hide();
_botStart->hide();
if (_unblock->isHidden()) {
_unblock->clearState();
_unblock->show();
@ -2212,6 +2223,7 @@ void HistoryWidget::updateControlsVisibility() {
} else if (isJoinChannel()) {
_unblock->hide();
_muteUnmute->hide();
_botStart->hide();
if (_joinChannel->isHidden()) {
_joinChannel->clearState();
_joinChannel->show();
@ -2219,16 +2231,23 @@ void HistoryWidget::updateControlsVisibility() {
} else if (isMuteUnmute()) {
_unblock->hide();
_joinChannel->hide();
_botStart->hide();
if (_muteUnmute->isHidden()) {
_muteUnmute->clearState();
_muteUnmute->show();
}
} else if (isBotStart()) {
_unblock->hide();
_joinChannel->hide();
_muteUnmute->hide();
if (_botStart->isHidden()) {
_botStart->clearState();
_botStart->show();
}
}
_kbShown = false;
_fieldAutocomplete->hide();
_send->hide();
_botStart->hide();
_attachToggle->hide();
_silent->hide();
_kbScroll->hide();
_fieldBarCancel->hide();
@ -2248,18 +2267,15 @@ void HistoryWidget::updateControlsVisibility() {
updateControlsGeometry();
update();
}
} else if (_canSendMessages) {
} else if (editingMessage() || _canSendMessages) {
onCheckFieldAutocomplete();
if (isBotStart()) {
_unblock->hide();
_joinChannel->hide();
_muteUnmute->hide();
if (_botStart->isHidden()) {
_botStart->clearState();
_botStart->show();
}
_kbShown = false;
_send->hide();
_unblock->hide();
_botStart->hide();
_joinChannel->hide();
_muteUnmute->hide();
_send->show();
updateSendButtonType();
if (_recording) {
_field->hide();
_tabbedSelectorToggle->hide();
_botKeyboardShow->hide();
@ -2267,75 +2283,57 @@ void HistoryWidget::updateControlsVisibility() {
_botCommandStart->hide();
_attachToggle->hide();
_silent->hide();
_kbScroll->hide();
_fieldBarCancel->hide();
} else {
_unblock->hide();
_botStart->hide();
_joinChannel->hide();
_muteUnmute->hide();
_send->show();
updateSendButtonType();
if (_recording) {
_field->hide();
_tabbedSelectorToggle->hide();
_botKeyboardShow->hide();
_botKeyboardHide->hide();
_botCommandStart->hide();
_attachToggle->hide();
_silent->hide();
if (_kbShown) {
_kbScroll->show();
} else {
_kbScroll->hide();
}
if (_kbShown) {
_kbScroll->show();
} else {
_field->show();
if (_kbShown) {
_kbScroll->show();
_tabbedSelectorToggle->hide();
_botKeyboardHide->show();
_botKeyboardShow->hide();
_botCommandStart->hide();
} else if (_kbReplyTo) {
_kbScroll->hide();
_tabbedSelectorToggle->show();
_botKeyboardHide->hide();
_botKeyboardShow->hide();
_kbScroll->hide();
}
} else {
_field->show();
if (_kbShown) {
_kbScroll->show();
_tabbedSelectorToggle->hide();
_botKeyboardHide->show();
_botKeyboardShow->hide();
_botCommandStart->hide();
} else if (_kbReplyTo) {
_kbScroll->hide();
_tabbedSelectorToggle->show();
_botKeyboardHide->hide();
_botKeyboardShow->hide();
_botCommandStart->hide();
} else {
_kbScroll->hide();
_tabbedSelectorToggle->show();
_botKeyboardHide->hide();
if (_keyboard->hasMarkup()) {
_botKeyboardShow->show();
_botCommandStart->hide();
} else {
_kbScroll->hide();
_tabbedSelectorToggle->show();
_botKeyboardHide->hide();
if (_keyboard->hasMarkup()) {
_botKeyboardShow->show();
_botCommandStart->hide();
_botKeyboardShow->hide();
if (_cmdStartShown) {
_botCommandStart->show();
} else {
_botKeyboardShow->hide();
if (_cmdStartShown) {
_botCommandStart->show();
} else {
_botCommandStart->hide();
}
_botCommandStart->hide();
}
}
_attachToggle->show();
if (hasSilentToggle()) {
_silent->show();
} else {
_silent->hide();
}
updateFieldPlaceholder();
}
if (_editMsgId || _replyToId || readyToForward() || (_previewData && _previewData->pendingTill >= 0) || _kbReplyTo) {
if (_fieldBarCancel->isHidden()) {
_fieldBarCancel->show();
updateControlsGeometry();
update();
}
_attachToggle->show();
if (hasSilentToggle()) {
_silent->show();
} else {
_fieldBarCancel->hide();
_silent->hide();
}
updateFieldPlaceholder();
}
if (_editMsgId || _replyToId || readyToForward() || (_previewData && _previewData->pendingTill >= 0) || _kbReplyTo) {
if (_fieldBarCancel->isHidden()) {
_fieldBarCancel->show();
updateControlsGeometry();
update();
}
} else {
_fieldBarCancel->hide();
}
} else {
_fieldAutocomplete->hide();
@ -4994,10 +4992,10 @@ void HistoryWidget::updateHistoryGeometry(bool initial, bool loadedDown, const S
}
auto newScrollHeight = height() - _topBar->height();
if (isBlocked() || isBotStart() || isJoinChannel() || isMuteUnmute()) {
if (!editingMessage() && (isBlocked() || isBotStart() || isJoinChannel() || isMuteUnmute())) {
newScrollHeight -= _unblock->height();
} else {
if (_canSendMessages) {
if (editingMessage() || _canSendMessages) {
newScrollHeight -= (_field->height() + 2 * st::historySendPadding);
} else if (isRestrictedWrite()) {
newScrollHeight -= _unblock->height();
@ -5883,6 +5881,9 @@ void HistoryWidget::cancelEdit() {
onTextChange();
_textUpdateEvents = old;
if (!canWriteMessage()) {
updateControlsVisibility();
}
updateBotKeyboard();
updateFieldPlaceholder();
@ -6556,7 +6557,7 @@ void HistoryWidget::paintEditHeader(Painter &p, const QRect &rect, int left, int
p.setFont(st::msgServiceNameFont);
p.drawTextLeft(left, top + st::msgReplyPadding.top(), width(), lang(lng_edit_message));
if (!_replyEditMsg) return;
if (!_replyEditMsg || _replyEditMsg->history()->peer->isSelf()) return;
QString editTimeLeftText;
int updateIn = -1;

View File

@ -543,6 +543,9 @@ private:
void updateReplyToName();
void checkForwardingInfo();
bool editingMessage() const {
return _editMsgId != 0;
}
MsgId _replyToId = 0;
Text _replyToName;

View File

@ -73,8 +73,10 @@ void GroupMembersWidget::editAdmin(gsl::not_null<UserData*> user) {
return; // not supported
}
auto defaultAdmin = MegagroupInfo::Admin { EditAdminBox::DefaultRights(megagroup) };
auto currentRights = megagroup->mgInfo->lastAdmins.value(user, defaultAdmin).rights;
Ui::show(Box<EditAdminBox>(megagroup, user, currentRights, base::lambda_guarded(this, [this, megagroup, user](const MTPChannelAdminRights &rights) {
auto currentRightsIt = megagroup->mgInfo->lastAdmins.find(user);
auto hasAdminRights = (currentRightsIt != megagroup->mgInfo->lastAdmins.cend());
auto currentRights = hasAdminRights ? currentRightsIt->rights : EditAdminBox::DefaultRights(megagroup);
Ui::show(Box<EditAdminBox>(megagroup, user, hasAdminRights, currentRights, base::lambda_guarded(this, [this, megagroup, user](const MTPChannelAdminRights &rights) {
Ui::hideLayer();
MTP::send(MTPchannels_EditAdmin(megagroup->inputChannel, user->inputUser, rights), rpcDone(base::lambda_guarded(this, [this, megagroup, user, rights](const MTPUpdates &result) {
if (App::main()) App::main()->sentUpdatesReceived(result);
@ -90,7 +92,8 @@ void GroupMembersWidget::restrictUser(gsl::not_null<UserData*> user) {
}
auto defaultRestricted = MegagroupInfo::Restricted { EditRestrictedBox::DefaultRights(megagroup) };
auto currentRights = megagroup->mgInfo->lastRestricted.value(user, defaultRestricted).rights;
Ui::show(Box<EditRestrictedBox>(megagroup, user, currentRights, [megagroup, user](const MTPChannelBannedRights &rights) {
auto hasAdminRights = megagroup->mgInfo->lastAdmins.find(user) != megagroup->mgInfo->lastAdmins.cend();
Ui::show(Box<EditRestrictedBox>(megagroup, user, hasAdminRights, currentRights, [megagroup, user](const MTPChannelBannedRights &rights) {
Ui::hideLayer();
MTP::send(MTPchannels_EditBanned(megagroup->inputChannel, user->inputUser, rights), rpcDone([megagroup, user, rights](const MTPUpdates &result) {
if (App::main()) App::main()->sentUpdatesReceived(result);
@ -101,6 +104,7 @@ void GroupMembersWidget::restrictUser(gsl::not_null<UserData*> user) {
void GroupMembersWidget::removePeer(PeerData *selectedPeer) {
auto user = selectedPeer->asUser();
t_assert(user != nullptr);
auto text = lng_profile_sure_kick(lt_user, user->firstName);
Ui::show(Box<ConfirmBox>(text, lang(lng_box_remove), base::lambda_guarded(this, [user, peer = peer()] {
Ui::hideLayer();
@ -246,7 +250,7 @@ void GroupMembersWidget::updateItemStatusText(Item *item) {
auto user = member->user();
if (member->statusText.isEmpty() || (member->onlineTextTill <= _now)) {
if (user->botInfo) {
bool seesAllMessages = (user->botInfo->readsAllHistory || member->hasAdminStar);
auto seesAllMessages = (user->botInfo->readsAllHistory || member->hasAdminStar);
member->statusText = lang(seesAllMessages ? lng_status_bot_reads_all : lng_status_bot_not_reads_all);
member->onlineTextTill = _now + 86400;
} else {
@ -461,7 +465,17 @@ void GroupMembersWidget::setItemFlags(Item *item, ChannelData *megagroup) {
auto isAdmin = (adminIt != megagroup->mgInfo->lastAdmins.cend());
auto isCreator = megagroup->mgInfo->creator == item->peer;
auto adminCanEdit = isAdmin && adminIt->canEdit;
item->hasAdminStar = amCreatorOrAdmin || isAdmin || isCreator;
auto hasAdminStar = amCreatorOrAdmin || isAdmin || isCreator;
if (item->hasAdminStar != hasAdminStar) {
item->hasAdminStar = hasAdminStar;
auto user = item->peer->asUser();
t_assert(user != nullptr);
if (user->botInfo) {
// Update "has access to messages" status.
item->statusText = QString();
updateItemStatusText(item);
}
}
if (item->peer->isSelf()) {
item->hasRemoveLink = false;
} else if (megagroup->amCreator() || (megagroup->canBanMembers() && (!item->hasAdminStar || adminCanEdit))) {

View File

@ -230,7 +230,8 @@ void ParticipantsBoxController::editAdmin(gsl::not_null<UserData*> user) {
auto it = _additional.adminRights.find(user);
t_assert(it != _additional.adminRights.cend());
auto weak = base::weak_unique_ptr<ParticipantsBoxController>(this);
_editBox = Ui::show(Box<EditAdminBox>(_channel, user, it->second, [megagroup = _channel.get(), user, weak](const MTPChannelAdminRights &rights) {
auto hasAdminRights = true;
_editBox = Ui::show(Box<EditAdminBox>(_channel, user, hasAdminRights, it->second, [megagroup = _channel.get(), user, weak](const MTPChannelAdminRights &rights) {
MTP::send(MTPchannels_EditAdmin(megagroup->inputChannel, user->inputUser, rights), rpcDone([megagroup, user, weak, rights](const MTPUpdates &result) {
AuthSession::Current().api().applyUpdates(result);
megagroup->applyEditAdmin(user, rights);
@ -276,7 +277,8 @@ void ParticipantsBoxController::editRestricted(gsl::not_null<UserData*> user) {
auto it = _additional.restrictedRights.find(user);
t_assert(it != _additional.restrictedRights.cend());
auto weak = base::weak_unique_ptr<ParticipantsBoxController>(this);
_editBox = Ui::show(Box<EditRestrictedBox>(_channel, user, it->second, [megagroup = _channel.get(), user, weak](const MTPChannelBannedRights &rights) {
auto hasAdminRights = false;
_editBox = Ui::show(Box<EditRestrictedBox>(_channel, user, hasAdminRights, it->second, [megagroup = _channel.get(), user, weak](const MTPChannelBannedRights &rights) {
MTP::send(MTPchannels_EditBanned(megagroup->inputChannel, user->inputUser, rights), rpcDone([megagroup, user, weak, rights](const MTPUpdates &result) {
AuthSession::Current().api().applyUpdates(result);
megagroup->applyEditBanned(user, rights);
@ -614,6 +616,7 @@ void AddParticipantBoxController::editAdmin(gsl::not_null<UserData*> user, bool
// Check restrictions.
auto weak = base::weak_unique_ptr<AddParticipantBoxController>(this);
auto alreadyIt = _additional.adminRights.find(user);
auto hasAdminRights = false;
auto currentRights = EditAdminBox::DefaultRights(_channel);
if (alreadyIt != _additional.adminRights.end() || _additional.creator == user) {
// The user is already an admin.
@ -621,6 +624,7 @@ void AddParticipantBoxController::editAdmin(gsl::not_null<UserData*> user, bool
Ui::show(Box<InformBox>(lang(lng_error_cant_edit_admin)), KeepOtherLayers);
return;
}
hasAdminRights = true;
currentRights = alreadyIt->second;
} else if (_additional.kicked.find(user) != _additional.kicked.end()) {
// The user is banned.
@ -663,7 +667,7 @@ void AddParticipantBoxController::editAdmin(gsl::not_null<UserData*> user, bool
}
// Finally edit the admin.
_editBox = Ui::show(Box<EditAdminBox>(_channel, user, currentRights, [channel = _channel.get(), user, weak](const MTPChannelAdminRights &rights) {
_editBox = Ui::show(Box<EditAdminBox>(_channel, user, hasAdminRights, currentRights, [channel = _channel.get(), user, weak](const MTPChannelAdminRights &rights) {
MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, rights), rpcDone([channel, user, weak, rights](const MTPUpdates &result) {
AuthSession::Current().api().applyUpdates(result);
channel->applyEditAdmin(user, rights);
@ -718,12 +722,14 @@ void AddParticipantBoxController::editRestricted(gsl::not_null<UserData*> user,
auto weak = base::weak_unique_ptr<AddParticipantBoxController>(this);
auto alreadyIt = _additional.restrictedRights.find(user);
auto currentRights = EditRestrictedBox::DefaultRights(_channel);
auto hasAdminRights = false;
if (alreadyIt != _additional.restrictedRights.end()) {
// The user is already banned or restricted.
currentRights = alreadyIt->second;
} else if (_additional.adminRights.find(user) != _additional.adminRights.end() || _additional.creator == user) {
// The user is an admin or creator.
if (_additional.adminCanEdit.find(user) != _additional.adminCanEdit.end()) {
hasAdminRights = true;
if (!sure) {
_editBox = Ui::show(Box<ConfirmBox>(lang(lng_sure_ban_admin), [weak, user] { weak->editRestricted(user, true); }), KeepOtherLayers);
return;
@ -735,7 +741,7 @@ void AddParticipantBoxController::editRestricted(gsl::not_null<UserData*> user,
}
// Finally edit the restricted.
_editBox = Ui::show(Box<EditRestrictedBox>(_channel, user, currentRights, [user, weak](const MTPChannelBannedRights &rights) {
_editBox = Ui::show(Box<EditRestrictedBox>(_channel, user, hasAdminRights, currentRights, [user, weak](const MTPChannelBannedRights &rights) {
if (weak) {
weak->restrictUserSure(user, rights);
}