From d7a67a6a1c2087fc74a9c4cd5d3eb5b0adaba204 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 25 Mar 2019 11:56:45 +0400 Subject: [PATCH] Fix two crashes in groups edit. --- .../boxes/peers/edit_peer_info_box.cpp | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 5b2ca0552f..38ed53ffd6 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -176,6 +176,7 @@ private: object_ptr createManageGroupButtons(); object_ptr createStickersEdit(); + bool canEditInformation() const; void refreshHistoryVisibility(bool instant); void showEditPeerTypeBox(std::optional error = std::nullopt); void fillPrivacyTypeButton(); @@ -283,15 +284,7 @@ void Controller::setFocus() { object_ptr Controller::createPhotoAndTitleEdit() { Expects(_wrap != nullptr); - const auto canEdit = [&] { - if (const auto channel = _peer->asChannel()) { - return channel->canEditInformation(); - } else if (const auto chat = _peer->asChat()) { - return chat->canEditInformation(); - } - return false; - }(); - if (!canEdit) { + if (!canEditInformation()) { return nullptr; } @@ -369,6 +362,10 @@ object_ptr Controller::createTitleEdit() { object_ptr Controller::createDescriptionEdit() { Expects(_wrap != nullptr); + if (!canEditInformation()) { + return nullptr; + } + auto result = object_ptr>( _wrap, object_ptr( @@ -447,6 +444,15 @@ object_ptr Controller::createStickersEdit() { return std::move(result); } +bool Controller::canEditInformation() const { + if (const auto channel = _peer->asChannel()) { + return channel->canEditInformation(); + } else if (const auto chat = _peer->asChat()) { + return chat->canEditInformation(); + } + return false; +} + void Controller::refreshHistoryVisibility(bool instant = false) { if (!_controls.historyVisibilityWrap) { return; @@ -795,7 +801,9 @@ std::optional Controller::validate() const { } bool Controller::validateUsername(Saving &to) const { - if (_privacySavedValue != Privacy::Public) { + if (!_privacySavedValue) { + return true; + } else if (_privacySavedValue != Privacy::Public) { to.username = QString(); return true; }