diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 5869bb67c4..54dfa5334d 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -332,6 +332,7 @@ private: void showEditLinkedChatBox(); void fillPrivacyTypeButton(); void fillLinkedChatButton(); + void fillInviteLinkButton(); void fillSignaturesButton(); void fillHistoryVisibilityButton(); void fillManageSection(); @@ -640,8 +641,6 @@ void Controller::refreshHistoryVisibility(anim::type animated) { void Controller::showEditPeerTypeBox( std::optional> error) { - Expects(_privacySavedValue.has_value()); - const auto boxCallback = crl::guard(this, [=]( Privacy checked, QString publicLink) { _privacyTypeUpdates.fire(std::move(checked)); @@ -654,7 +653,7 @@ void Controller::showEditPeerTypeBox( _peer, _channelHasLocationOriginalValue, boxCallback, - *_privacySavedValue, + _privacySavedValue, _usernameSavedValue, error), Ui::LayerOption::KeepOther); @@ -800,6 +799,20 @@ void Controller::fillLinkedChatButton() { _linkedChatUpdates.fire_copy(*_linkedChatSavedValue); } +void Controller::fillInviteLinkButton() { + Expects(_controls.buttonsLayout != nullptr); + + const auto buttonCallback = [=] { + Ui::show(Box(_peer), Ui::LayerOption::KeepOther); + }; + + AddButtonWithText( + _controls.buttonsLayout, + tr::lng_profile_invite_link_section(), + rpl::single(QString()), //Empty text. + buttonCallback); +} + void Controller::fillSignaturesButton() { Expects(_controls.buttonsLayout != nullptr); @@ -880,13 +893,6 @@ void Controller::fillManageSection() { ? channel->canEditUsername() : chat->canEditUsername(); }(); - const auto canEditInviteLink = [&] { - return isChannel - ? (channel->amCreator() - || (channel->adminRights() & ChatAdminRight::f_invite_users)) - : (chat->amCreator() - || (chat->adminRights() & ChatAdminRight::f_invite_users)); - }(); const auto canEditSignatures = [&] { return isChannel ? (channel->canEditSignatures() && !channel->isMegagroup()) @@ -953,6 +959,8 @@ void Controller::fillManageSection() { if (canEditUsername) { fillPrivacyTypeButton(); + } else if (canEditInviteLinks) { + fillInviteLinkButton(); } if (canViewOrEditLinkedChat) { fillLinkedChatButton(); @@ -965,7 +973,7 @@ void Controller::fillManageSection() { } if (canEditPreHistoryHidden || canEditSignatures - || canEditInviteLink + || canEditInviteLinks || canViewOrEditLinkedChat || canEditUsername) { AddSkip( diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index 231b385b85..bc33af5023 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -64,7 +64,7 @@ public: not_null container, not_null peer, bool useLocationPhrases, - Privacy privacySavedValue, + std::optional privacySavedValue, std::optional usernameSavedValue); void createContent(); @@ -72,7 +72,9 @@ public: void setFocusUsername(); rpl::producer getTitle() { - return _isGroup + return !_privacySavedValue + ? tr::lng_create_invite_link_title() + : _isGroup ? tr::lng_manage_peer_group_type() : tr::lng_manage_peer_channel_type(); } @@ -120,7 +122,7 @@ private: void fillPrivaciesButtons( not_null parent, - Privacy savedValue); + std::optional savedValue); void addRoundButton( not_null container, Privacy value, @@ -132,7 +134,7 @@ private: not_null _peer; MTP::Sender _api; - Privacy _privacySavedValue = Privacy(); + std::optional _privacySavedValue; std::optional _usernameSavedValue; bool _useLocationPhrases = false; @@ -153,7 +155,7 @@ Controller::Controller( not_null container, not_null peer, bool useLocationPhrases, - Privacy privacySavedValue, + std::optional privacySavedValue, std::optional usernameSavedValue) : _peer(peer) , _api(&_peer->session().mtp()) @@ -172,10 +174,14 @@ void Controller::createContent() { fillPrivaciesButtons(_wrap, _privacySavedValue); // Skip. - _wrap->add(object_ptr(_wrap)); + if (_privacySavedValue) { + _wrap->add(object_ptr(_wrap)); + } // _wrap->add(createInviteLinkBlock()); - _wrap->add(createUsernameEdit()); + if (_privacySavedValue) { + _wrap->add(createUsernameEdit()); + } //using namespace Settings; // #TODO links //AddSkip(_wrap.get()); @@ -192,15 +198,20 @@ void Controller::createContent() { //AddSkip(_wrap.get()); //AddDividerText(_wrap.get(), tr::lng_group_invite_manage_about()); - if (_controls.privacy->value() == Privacy::NoUsername) { - checkUsernameAvailability(); + if (_controls.privacy) { + if (_controls.privacy->value() == Privacy::NoUsername) { + checkUsernameAvailability(); + } + const auto forShowing = _privacySavedValue.value_or(Privacy::NoUsername); + _controls.inviteLinkWrap->toggle( + (forShowing != Privacy::HasUsername), + anim::type::instant); + _controls.usernameWrap->toggle( + (forShowing == Privacy::HasUsername), + anim::type::instant); + } else { + _controls.inviteLinkWrap->show(anim::type::instant); } - _controls.inviteLinkWrap->toggle( - (_privacySavedValue != Privacy::HasUsername), - anim::type::instant); - _controls.usernameWrap->toggle( - (_privacySavedValue == Privacy::HasUsername), - anim::type::instant); } void Controller::addRoundButton( @@ -228,7 +239,7 @@ void Controller::addRoundButton( void Controller::fillPrivaciesButtons( not_null parent, - Privacy savedValue) { + std::optional savedValue) { const auto canEditUsername = [&] { if (const auto chat = _peer->asChat()) { return chat->canEditUsername(); @@ -251,7 +262,8 @@ void Controller::fillPrivaciesButtons( const auto isPublic = _peer->isChannel() && _peer->asChannel()->hasUsername(); _controls.privacy = std::make_shared>( - savedValue); + savedValue.value_or( + isPublic ? Privacy::HasUsername : Privacy::NoUsername)); addRoundButton( container, @@ -546,9 +558,11 @@ object_ptr Controller::createInviteLinkBlock() { const auto container = result->entity(); using namespace Settings; - AddSkip(container); + if (_privacySavedValue) { + AddSkip(container); - AddSubsectionTitle(container, tr::lng_create_invite_link_title()); + AddSubsectionTitle(container, tr::lng_create_invite_link_title()); + } // tr::lng_create_permanent_link_title()); // #TODO links AddPermanentLinkBlock(container, _peer); @@ -585,7 +599,7 @@ EditPeerTypeBox::EditPeerTypeBox( not_null peer, bool useLocationPhrases, std::optional> savedCallback, - Privacy privacySaved, + std::optional privacySaved, std::optional usernameSaved, std::optional> usernameError) : _peer(peer) @@ -596,6 +610,12 @@ EditPeerTypeBox::EditPeerTypeBox( , _usernameError(usernameError) { } +EditPeerTypeBox::EditPeerTypeBox( + QWidget*, + not_null peer) +: EditPeerTypeBox(nullptr, peer, {}, {}, {}, {}, {}) { +} + void EditPeerTypeBox::setInnerFocus() { _focusRequests.fire({}); } @@ -641,8 +661,10 @@ void EditPeerTypeBox::prepare() { : QString()); // We don't need username with private type. closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); + } else { + addButton(tr::lng_close(), [=] { closeBox(); }); } - addButton(tr::lng_cancel(), [=] { closeBox(); }); setDimensionsToContent(st::boxWideWidth, content.data()); setInnerWidget(std::move(content)); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.h index 8aae656e2c..0d4a828b1b 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.h @@ -37,10 +37,15 @@ public: not_null peer, bool useLocationPhrases, std::optional> savedCallback, - Privacy privacySaved, + std::optional privacySaved, std::optional usernameSaved, std::optional> usernameError = {}); + // For invite link only. + EditPeerTypeBox( + QWidget*, + not_null peer); + protected: void prepare() override; void setInnerFocus() override; @@ -50,7 +55,7 @@ private: bool _useLocationPhrases = false; std::optional> _savedCallback; - Privacy _privacySavedValue = Privacy(); + std::optional _privacySavedValue; std::optional _usernameSavedValue; std::optional> _usernameError;