From 034adfab2b3a5a7e5f39c2f94bc3616de535c401 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 23 Mar 2016 19:50:40 +0300 Subject: [PATCH] Delete button for large channels is hidden now (server doesn't allow to delete large channels any more). Error message added in a case when the current user (not admin) tries to add to a supergroup a user who was kicked by admin (and blacklisted by this action). --- Telegram/Resources/lang.strings | 1 + Telegram/SourceFiles/mainwidget.cpp | 18 ++++++++++++++++-- Telegram/SourceFiles/mainwidget.h | 1 + Telegram/SourceFiles/profilewidget.cpp | 20 +++++++++++++------- Telegram/SourceFiles/profilewidget.h | 1 + 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Telegram/Resources/lang.strings b/Telegram/Resources/lang.strings index f567608f2..9b89f7ad0 100644 --- a/Telegram/Resources/lang.strings +++ b/Telegram/Resources/lang.strings @@ -682,6 +682,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org "lng_cant_invite_not_contact" = "Sorry, you can only add mutual contacts\nto groups at the moment.\n{more_info}"; "lng_cant_invite_not_contact_channel" = "Sorry, you can only add mutual contacts\nto channels at the moment.\n{more_info}"; "lng_cant_more_info" = "More info ยป"; +"lng_cant_invite_banned" = "Sorry, only admin can add this user."; "lng_cant_invite_privacy" = "Sorry, you cannot add this user to groups because of the privacy settings."; "lng_cant_invite_privacy_channel" = "Sorry, you cannot add this user to channels because of the privacy settings."; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 8bfcb4886..a4a98df02 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1147,7 +1147,9 @@ bool MainWidget::addParticipantFail(UserData *user, const RPCError &error) { if (mtpIsFlood(error)) return false; QString text = lang(lng_failed_add_participant); - if (error.type() == "USER_LEFT_CHAT") { // trying to return banned user to his group + if (error.type() == "USER_LEFT_CHAT") { // trying to return a user who has left + } else if (error.type() == "USER_KICKED") { // trying to return a user who was kicked by admin + text = lang(lng_cant_invite_banned); } else if (error.type() == "USER_PRIVACY_RESTRICTED") { text = lang(lng_cant_invite_privacy); } else if (error.type() == "USER_NOT_MUTUAL_CONTACT") { // trying to return user who does not have me in contacts @@ -1166,8 +1168,10 @@ bool MainWidget::addParticipantsFail(ChannelData *channel, const RPCError &error QString text = lang(lng_failed_add_participant); if (error.type() == "USER_LEFT_CHAT") { // trying to return banned user to his group + } else if (error.type() == "USER_KICKED") { // trying to return a user who was kicked by admin + text = lang(lng_cant_invite_banned); } else if (error.type() == "USER_PRIVACY_RESTRICTED") { - text = lang(lng_cant_invite_privacy_channel); + text = lang(channel->isMegagroup() ? lng_cant_invite_privacy : lng_cant_invite_privacy_channel); } else if (error.type() == "USER_NOT_MUTUAL_CONTACT") { // trying to return user who does not have me in contacts text = lang(channel->isMegagroup() ? lng_failed_add_not_mutual : lng_failed_add_not_mutual_channel); } else if (error.type() == "PEER_FLOOD") { @@ -2595,6 +2599,16 @@ void MainWidget::sentUpdatesReceived(uint64 randomId, const MTPUpdates &result) App::emitPeerUpdated(); } +bool MainWidget::deleteChannelFailed(const RPCError &error) { + if (mtpIsFlood(error)) return false; + + //if (error.type() == qstr("CHANNEL_TOO_LARGE")) { + // Ui::showLayer(new InformBox(lang(lng_cant_delete_channel))); + //} + + return true; +} + void MainWidget::inviteToChannelDone(ChannelData *channel, const MTPUpdates &updates) { sentUpdatesReceived(updates); QTimer::singleShot(ReloadChannelMembersTimeout, this, SLOT(onActiveChannelUpdateFull())); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 88ee43f4f..67c2398f0 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -251,6 +251,7 @@ public: void sentUpdatesReceived(const MTPUpdates &updates) { return sentUpdatesReceived(0, updates); } + bool deleteChannelFailed(const RPCError &error); void inviteToChannelDone(ChannelData *channel, const MTPUpdates &updates); void historyToDown(History *hist); void dialogsToUp(); diff --git a/Telegram/SourceFiles/profilewidget.cpp b/Telegram/SourceFiles/profilewidget.cpp index 95dc8911b..bf5f9bb2e 100644 --- a/Telegram/SourceFiles/profilewidget.cpp +++ b/Telegram/SourceFiles/profilewidget.cpp @@ -364,7 +364,7 @@ void ProfileInner::onDeleteChannelSure() { if (_peerChannel->migrateFrom()) { App::main()->deleteConversation(_peerChannel->migrateFrom()); } - MTP::send(MTPchannels_DeleteChannel(_peerChannel->inputChannel), App::main()->rpcDone(&MainWidget::sentUpdatesReceived)); + MTP::send(MTPchannels_DeleteChannel(_peerChannel->inputChannel), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::deleteChannelFailed)); } } void ProfileInner::onBlockUser() { @@ -978,7 +978,7 @@ void ProfileInner::paintEvent(QPaintEvent *e) { } if (_peerUser && peerToUser(_peerUser->id) != MTP::authedId()) { top += st::setSectionSkip + _blockUser.height(); - } else if (_peerChannel && _amCreator) { + } else if (canDeleteChannel()) { top += (_peerChannel->isMegagroup() ? 0 : (st::setSectionSkip - st::setLittleSkip)) + _deleteChannel.height(); } @@ -1115,8 +1115,10 @@ void ProfileInner::updateSelected() { } int32 participantsTop = 0; - if (_peerChannel && _amCreator) { + if (canDeleteChannel()) { participantsTop = _deleteChannel.y() + _deleteChannel.height(); + } else if (_peerChannel && _amCreator) { + participantsTop = _searchInPeer.y() + _searchInPeer.height(); } else { participantsTop = _deleteConversation.y() + _deleteConversation.height(); } @@ -1365,6 +1367,10 @@ bool ProfileInner::migrateFail(const RPCError &error) { return true; } +bool ProfileInner::canDeleteChannel() const { + return _peerChannel && _amCreator && (_peerChannel->count <= 1000); +} + void ProfileInner::resizeEvent(QResizeEvent *e) { _width = qMin(width() - st::profilePadding.left() - st::profilePadding.right(), int(st::profileMaxWidth)); _left = (width() - _width) / 2; @@ -1482,7 +1488,7 @@ void ProfileInner::resizeEvent(QResizeEvent *e) { if (_peerUser && peerToUser(_peerUser->id) != MTP::authedId()) { top += st::setSectionSkip; _blockUser.move(_left, top); top += _blockUser.height(); - } else if (_peerChannel && _amCreator) { + } else if (canDeleteChannel()) { top += (_peerChannel->isMegagroup() ? 0 : (st::setSectionSkip - st::setLittleSkip)); _deleteChannel.move(_left, top); top += _deleteChannel.height(); } @@ -1602,9 +1608,9 @@ int32 ProfileInner::countMinHeight() { h += st::profileHeaderSkip; } } else if (_peerChannel) { - if (_amCreator) { + if (canDeleteChannel()) { h = _deleteChannel.y() + _deleteChannel.height() + st::profileHeaderSkip; - } else if (_peerChannel->amIn()) { + } else if (_peerChannel->amIn() && !_amCreator) { h = _deleteConversation.y() + _deleteConversation.height() + st::profileHeaderSkip; } else { h = _searchInPeer.y() + _searchInPeer.height() + st::profileHeaderSkip; @@ -1755,7 +1761,7 @@ void ProfileInner::showAll() { _addParticipant.hide(); } _blockUser.hide(); - if (_amCreator) { + if (canDeleteChannel()) { _deleteChannel.show(); } else { _deleteChannel.hide(); diff --git a/Telegram/SourceFiles/profilewidget.h b/Telegram/SourceFiles/profilewidget.h index 23b6fcd02..24b6364f2 100644 --- a/Telegram/SourceFiles/profilewidget.h +++ b/Telegram/SourceFiles/profilewidget.h @@ -191,6 +191,7 @@ private: UserBlockedStatus _wasBlocked; mtpRequestId _blockRequest; LinkButton _blockUser, _deleteChannel; + bool canDeleteChannel() const; // participants int32 _pHeight;