From 0913833f6c606605d7a506ab373d60404e47e9cd Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 11 Mar 2016 18:21:05 +0300 Subject: [PATCH] can_set_username bit support added --- Telegram/SourceFiles/boxes/addcontactbox.cpp | 18 ++++++++++++------ Telegram/SourceFiles/historywidget.cpp | 4 ++-- Telegram/SourceFiles/profilewidget.cpp | 6 +++--- Telegram/SourceFiles/structs.h | 3 +++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index 0d6f55d3af..3fcd143a66 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -944,7 +944,10 @@ bool SetupChannelBox::onCheckFail(const RPCError &error) { _checkRequestId = 0; QString err(error.type()); - if (err == "CHANNELS_ADMIN_PUBLIC_TOO_MUCH") { + if (err == qstr("CHANNEL_PUBLIC_GROUP_NA")) { + Ui::hideLayer(); + return true; + } else if (err == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { if (_existing) { Ui::showLayer(new InformBox(lang(lng_channels_too_much_public_existing))); } else { @@ -953,11 +956,11 @@ bool SetupChannelBox::onCheckFail(const RPCError &error) { onPrivacyChange(); } return true; - } else if (err == "USERNAME_INVALID") { + } else if (err == qstr("USERNAME_INVALID")) { _errorText = lang(lng_create_channel_link_invalid); update(); return true; - } else if (err == "USERNAME_OCCUPIED" && _checkUsername != _channel->username) { + } else if (err == qstr("USERNAME_OCCUPIED") && _checkUsername != _channel->username) { _errorText = lang(lng_create_channel_link_occupied); update(); return true; @@ -972,7 +975,10 @@ bool SetupChannelBox::onFirstCheckFail(const RPCError &error) { _checkRequestId = 0; QString err(error.type()); - if (err == "CHANNELS_ADMIN_PUBLIC_TOO_MUCH") { + if (err == qstr("CHANNEL_PUBLIC_GROUP_NA")) { + Ui::hideLayer(); + return true; + } else if (err == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { if (_existing) { Ui::showLayer(new InformBox(lang(lng_channels_too_much_public_existing))); } else { @@ -1213,7 +1219,7 @@ void EditChannelBox::showAll() { _description.show(); _save.show(); _cancel.show(); - if (_channel->amCreator()) { + if (_channel->canEditUsername()) { _publicLink.show(); } else { _publicLink.hide(); @@ -1264,7 +1270,7 @@ void EditChannelBox::updateMaxHeight() { if (!_channel->isMegagroup()) { h += st::newGroupPublicLinkPadding.top() + _sign.height() + st::newGroupPublicLinkPadding.bottom(); } - if (_channel->amCreator()) { + if (_channel->canEditUsername()) { h += st::newGroupPublicLinkPadding.top() + _publicLink.height() + st::newGroupPublicLinkPadding.bottom(); } h += st::boxPadding.bottom() + st::newGroupInfoPadding.bottom() + st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom(); diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index e26df0cf5b..63cb7abee8 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -4166,7 +4166,7 @@ void HistoryWidget::historyCleared(History *history) { bool HistoryWidget::messagesFailed(const RPCError &error, mtpRequestId requestId) { if (mtpIsFlood(error)) return false; - if (error.type() == qstr("CHANNEL_PRIVATE")) { + if (error.type() == qstr("CHANNEL_PRIVATE") || error.type() == qstr("CHANNEL_PUBLIC_GROUP_NA")) { PeerData *was = _peer; Ui::showChatsList(); Ui::showLayer(new InformBox(lang((was && was->isMegagroup()) ? lng_group_not_accessible : lng_channel_not_accessible))); @@ -4762,7 +4762,7 @@ bool HistoryWidget::joinFail(const RPCError &error, mtpRequestId req) { if (mtpIsFlood(error)) return false; if (_unblockRequest == req) _unblockRequest = 0; - if (error.type() == qstr("CHANNEL_PRIVATE")) { + if (error.type() == qstr("CHANNEL_PRIVATE") || error.type() == qstr("CHANNEL_PUBLIC_GROUP_NA")) { Ui::showLayer(new InformBox(lang((_peer && _peer->isMegagroup()) ? lng_group_not_accessible : lng_channel_not_accessible))); return true; } diff --git a/Telegram/SourceFiles/profilewidget.cpp b/Telegram/SourceFiles/profilewidget.cpp index 08e49d6ba9..6798f27067 100644 --- a/Telegram/SourceFiles/profilewidget.cpp +++ b/Telegram/SourceFiles/profilewidget.cpp @@ -859,7 +859,7 @@ void ProfileInner::paintEvent(QPaintEvent *e) { addbyname = st::profileStatusTop + st::linkFont->ascent - (st::profileNameTop + st::profileNameFont->ascent); p.setPen(st::black->p); p.drawText(_left + st::profilePhotoSize + st::profileStatusLeft, top + st::profileStatusTop + st::linkFont->ascent, '@' + _peerUser->username); - } else if (_peerChannel && (_peerChannel->isPublic() || _amCreator)) { + } else if (_peerChannel && (_peerChannel->isPublic() || _peerChannel->canEditUsername())) { addbyname = st::profileStatusTop + st::linkFont->ascent - (st::profileNameTop + st::profileNameFont->ascent); } if (!_peerChannel || !_peerChannel->canViewParticipants() || _peerChannel->isMegagroup()) { @@ -1374,7 +1374,7 @@ void ProfileInner::resizeEvent(QResizeEvent *e) { // profile top += st::profilePadding.top(); int32 addbyname = 0; - if (_peerChannel && (_amCreator || _peerChannel->isPublic())) { + if (_peerChannel && (_peerChannel->isPublic() || _peerChannel->canEditUsername())) { _username.move(_left + st::profilePhotoSize + st::profileStatusLeft, top + st::profileStatusTop); addbyname = st::profileStatusTop + st::linkFont->ascent - (st::profileNameTop + st::profileNameFont->ascent); } @@ -1760,7 +1760,7 @@ void ProfileInner::showAll() { } else { _deleteChannel.hide(); } - if (_peerChannel->isPublic() || _amCreator) { + if (_peerChannel->isPublic() || _peerChannel->canEditUsername()) { _username.show(); } else { _username.hide(); diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index f03d57fe60..629360d285 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -607,6 +607,9 @@ public: bool isPublic() const { return flags & MTPDchannel::flag_username; } + bool canEditUsername() const { + return amCreator() && (flagsFull & MTPDchannelFull::flag_can_set_username); + } bool amCreator() const { return flags & MTPDchannel::flag_creator; }