From 88872725775f2b80da30d828783532ac4157e191 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 17 Mar 2019 13:06:00 +0300 Subject: [PATCH] Refactored code. Removed unused code. - Deleted manage_peer_box from sources. --- .../boxes/peers/edit_peer_info_box.cpp | 214 +++++++----- .../boxes/peers/edit_peer_info_box.h | 26 +- .../boxes/peers/edit_peer_permissions_box.cpp | 6 +- ...up_type_box.cpp => edit_peer_type_box.cpp} | 10 +- ..._group_type_box.h => edit_peer_type_box.h} | 4 +- .../boxes/peers/manage_peer_box.cpp | 322 ------------------ .../SourceFiles/boxes/peers/manage_peer_box.h | 48 --- .../SourceFiles/window/window_peer_menu.cpp | 6 +- Telegram/gyp/telegram_sources.txt | 6 +- 9 files changed, 163 insertions(+), 479 deletions(-) rename Telegram/SourceFiles/boxes/peers/{edit_peer_group_type_box.cpp => edit_peer_type_box.cpp} (98%) rename Telegram/SourceFiles/boxes/peers/{edit_peer_group_type_box.h => edit_peer_type_box.h} (93%) delete mode 100644 Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp delete mode 100644 Telegram/SourceFiles/boxes/peers/manage_peer_box.h diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index b6a3773ac..a16b665da 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "boxes/peer_list_controllers.h" #include "boxes/peers/edit_participants_box.h" -#include "boxes/peers/edit_peer_group_type_box.h" +#include "boxes/peers/edit_peer_type_box.h" #include "boxes/peers/edit_peer_history_visibility_box.h" #include "boxes/peers/edit_peer_permissions_box.h" #include "boxes/stickers_box.h" @@ -43,6 +43,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_controller.h" #include #include +#include "info/profile/info_profile_icon.h" namespace { @@ -73,27 +74,13 @@ void AddSkip(not_null container) { container->add(object_ptr(container)); } -Info::Profile::Button *AddButton( - not_null parent, - rpl::producer &&text, - Fn callback, - const style::icon &icon) { - return ManagePeerBox::CreateButton( - parent, - std::move(text), - rpl::single(QString()), - std::move(callback), - st::manageGroupButton, - &icon); -} - void AddButtonWithCount( not_null parent, rpl::producer &&text, rpl::producer &&count, Fn callback, const style::icon &icon) { - ManagePeerBox::CreateButton( + EditPeerInfoBox::CreateButton( parent, std::move(text), std::move(count), @@ -107,7 +94,7 @@ Info::Profile::Button *AddButtonWithText( rpl::producer &&text, rpl::producer &&label, Fn callback) { - return ManagePeerBox::CreateButton( + return EditPeerInfoBox::CreateButton( parent, std::move(text), std::move(label), @@ -160,91 +147,79 @@ void ShowEditPermissions(not_null peer) { }, box->lifetime()); } -void FillManageChatBox( +void FillManageSection( not_null navigation, - not_null chat, + not_null peer, not_null content) { + const auto chat = peer->asChat(); + const auto channel = peer->asChannel(); + const auto isChannel = (!chat); + if (!chat && !channel) return; - if (chat->canEditPermissions()) { + const auto canEditPermissions = [=] { + return isChannel + ? channel->canEditPermissions() + : chat->canEditPermissions(); + }(); + const auto canViewAdmins = [=] { + return isChannel + ? channel->canViewAdmins() + : chat->amIn(); + }(); + const auto canViewMembers = [=] { + return isChannel + ? channel->canViewMembers() + : chat->amIn(); + }(); + const auto canViewKicked = [=] { + return isChannel + ? (!channel->isMegagroup()) + : false; + }(); + const auto hasRecentActions = [=] { + return isChannel + ? (channel->hasAdminRights() || channel->amCreator()) + : false; + }(); + + if (canEditPermissions) { AddButtonWithCount( content, Lang::Viewer(lng_manage_peer_permissions), - Info::Profile::RestrictionsCountValue(chat) + Info::Profile::RestrictionsCountValue(peer) | ToPositiveNumberStringRestrictions(), - [=] { ShowEditPermissions(chat); }, + [=] { ShowEditPermissions(peer); }, st::infoIconPermissions); } - if (chat->amIn()) { + if (canViewAdmins) { AddButtonWithCount( content, Lang::Viewer(lng_manage_peer_administrators), - Info::Profile::AdminsCountValue(chat) + Info::Profile::AdminsCountValue(peer) | ToPositiveNumberString(), [=] { ParticipantsBoxController::Start( navigation, - chat, - ParticipantsBoxController::Role::Admins); - }, - st::infoIconAdministrators); - AddButtonWithCount( - content, - Lang::Viewer(lng_manage_peer_members), - Info::Profile::MembersCountValue(chat) - | ToPositiveNumberString(), - [=] { - ParticipantsBoxController::Start( - navigation, - chat, - ParticipantsBoxController::Role::Members); - }, - st::infoIconMembers); - } -} - -void FillManageChannelBox( - not_null navigation, - not_null channel, - not_null content) { - auto isGroup = channel->isMegagroup(); - if (channel->canEditPermissions()) { - AddButtonWithCount( - content, - Lang::Viewer(lng_manage_peer_permissions), - Info::Profile::RestrictionsCountValue(channel) - | ToPositiveNumberStringRestrictions(), - [=] { ShowEditPermissions(channel); }, - st::infoIconPermissions); - } - if (channel->canViewAdmins()) { - AddButtonWithCount( - content, - Lang::Viewer(lng_manage_peer_administrators), - Info::Profile::AdminsCountValue(channel) - | ToPositiveNumberString(), - [=] { - ParticipantsBoxController::Start( - navigation, - channel, + peer, ParticipantsBoxController::Role::Admins); }, st::infoIconAdministrators); } - if (channel->canViewMembers()) { + if (canViewMembers) { AddButtonWithCount( content, Lang::Viewer(lng_manage_peer_members), - Info::Profile::MembersCountValue(channel) + Info::Profile::MembersCountValue(peer) | ToPositiveNumberString(), [=] { ParticipantsBoxController::Start( navigation, - channel, + peer, ParticipantsBoxController::Role::Members); }, st::infoIconMembers); } - if (!channel->isMegagroup()) { + if (canViewKicked) { AddButtonWithCount( content, Lang::Viewer(lng_manage_peer_removed_users), @@ -253,15 +228,16 @@ void FillManageChannelBox( [=] { ParticipantsBoxController::Start( navigation, - channel, + peer, ParticipantsBoxController::Role::Kicked); }, st::infoIconBlacklist); } - if (HasRecentActions(channel)) { - AddButton( + if (hasRecentActions) { + AddButtonWithCount( content, Lang::Viewer(lng_manage_peer_recent_actions), + rpl::single(QString()), //Empty count. [=] { ShowRecentActions(navigation, channel); }, st::infoIconRecentActions); } @@ -341,8 +317,6 @@ private: void deleteWithConfirmation(); void deleteChannel(); - void refreshHistoryVisibility(bool instant = false); - std::optional validate() const; bool validateUsername(Saving &to) const; bool validateTitle(Saving &to) const; @@ -573,6 +547,15 @@ object_ptr Controller::createPrivaciesButtons() { return nullptr; } + const auto refreshHistoryVisibility = [=](bool instant = false) { + if (!_controls.historyVisibilityWrap) { + return; + } + _controls.historyVisibilityWrap->toggle( + _controls.privacySavedValue == Privacy::Private, + instant ? anim::type::instant : anim::type::normal); + }; + const auto channel = _peer->asChannel(); auto isRealChannel = !(!channel || !channel->canEditSignatures() || channel->isMegagroup()); @@ -597,7 +580,7 @@ object_ptr Controller::createPrivaciesButtons() { refreshHistoryVisibility(); }; const auto buttonCallback = [=]{ - Ui::show(Box( + Ui::show(Box( _peer, boxCallback, _controls.privacySavedValue, @@ -696,25 +679,12 @@ object_ptr Controller::createManageGroupButtons() { st::editPeerBottomButtonsLayoutMargins); auto container = result->entity(); - if (const auto chat = _peer->asChat()) { - FillManageChatBox(App::wnd()->controller(), chat, container); - } else if (const auto channel = _peer->asChannel()) { - FillManageChannelBox(App::wnd()->controller(), channel, container); - } + FillManageSection(App::wnd()->controller(), _peer, container); // setDimensionsToContent(st::boxWidth, content); return std::move(result); } -void Controller::refreshHistoryVisibility(bool instant) { - if (!_controls.historyVisibilityWrap) { - return; - } - _controls.historyVisibilityWrap->toggle( - _controls.privacySavedValue == Privacy::Private, - instant ? anim::type::instant : anim::type::normal); -} - object_ptr Controller::createStickersEdit() { Expects(_wrap != nullptr); @@ -1160,3 +1130,65 @@ void EditPeerInfoBox::prepare() { this, std::move(content))); } + +Info::Profile::Button *EditPeerInfoBox::CreateButton( + not_null parent, + rpl::producer &&text, + rpl::producer &&count, + Fn callback, + const style::InfoProfileCountButton &st, + const style::icon *icon) { + const auto button = parent->add( + object_ptr( + parent, + std::move(text), + st.button)); + button->addClickHandler(callback); + if (icon) { + Ui::CreateChild( + button, + *icon, + st.iconPosition); + } + const auto label = Ui::CreateChild( + button, + std::move(count), + st.label); + label->setAttribute(Qt::WA_TransparentForMouseEvents); + + rpl::combine( + button->widthValue(), + label->widthValue() + ) | rpl::start_with_next([=, &st](int outerWidth, int width) { + label->moveToRight( + st.labelPosition.x(), + st.labelPosition.y(), + outerWidth); + }, label->lifetime()); + + return button; +} + +bool EditPeerInfoBox::Available(not_null peer) { + if (const auto chat = peer->asChat()) { + return false + || chat->canEditInformation() + || chat->canEditPermissions(); + } else if (const auto channel = peer->asChannel()) { + // canViewMembers() is removed, because in supergroups you + // see them in profile and in channels only admins can see them. + + // canViewAdmins() is removed, because in supergroups it is + // always true and in channels it is equal to canViewBanned(). + + return false + //|| channel->canViewMembers() + //|| channel->canViewAdmins() + || channel->canViewBanned() + || channel->canEditInformation() + || channel->canEditPermissions() + || HasRecentActions(channel); + } else { + return false; + } +} \ No newline at end of file diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h index 9dbf18a60..5f4aba60e 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.h @@ -8,7 +8,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include -#include "boxes/peers/manage_peer_box.h" +#include "boxes/abstract_box.h" + +namespace style { +struct InfoProfileCountButton; +} // namespace style + +namespace Ui { +class VerticalLayout; +} // namespace Ui + +namespace Info { +namespace Profile { +class Button; +} // namespace Profile +} // namespace Info class EditPeerInfoBox : public BoxContent { public: @@ -18,6 +32,16 @@ public: _focusRequests.fire({}); } + static bool Available(not_null peer); + + static Info::Profile::Button *CreateButton( + not_null parent, + rpl::producer &&text, + rpl::producer &&count, + Fn callback, + const style::InfoProfileCountButton &st, + const style::icon *icon = nullptr); + protected: void prepare() override; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index a17caa59f..0242b1b03 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_icon.h" #include "info/profile/info_profile_values.h" #include "boxes/peers/edit_participants_box.h" -#include "boxes/peers/manage_peer_box.h" +#include "boxes/peers/edit_peer_info_box.h" #include "window/window_controller.h" #include "mainwindow.h" #include "styles/style_boxes.h" @@ -357,7 +357,7 @@ void EditPeerPermissionsBox::addBannedButtons( { 0, st::infoProfileSkip, 0, st::infoProfileSkip }); const auto navigation = App::wnd()->controller(); - ManagePeerBox::CreateButton( + EditPeerInfoBox::CreateButton( container, Lang::Viewer(lng_manage_peer_exceptions), (channel @@ -371,7 +371,7 @@ void EditPeerPermissionsBox::addBannedButtons( }, st::peerPermissionsButton); if (channel) { - ManagePeerBox::CreateButton( + EditPeerInfoBox::CreateButton( container, Lang::Viewer(lng_manage_peer_removed_users), Info::Profile::KickedCountValue(channel) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_group_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp similarity index 98% rename from Telegram/SourceFiles/boxes/peers/edit_peer_group_type_box.cpp rename to Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index f8352ec38..a38b2aed8 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_group_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -5,7 +5,7 @@ the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ -#include "boxes/peers/edit_peer_group_type_box.h" +#include "boxes/peers/edit_peer_type_box.h" #include "apiwrap.h" #include "apiwrap.h" @@ -22,7 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/edit_participants_box.h" #include "boxes/peers/edit_participants_box.h" #include "boxes/peers/edit_participants_box.h" -#include "boxes/peers/edit_peer_group_type_box.h" +#include "boxes/peers/edit_peer_type_box.h" #include "boxes/peers/edit_peer_history_visibility_box.h" #include "boxes/peers/edit_peer_info_box.h" #include "boxes/peers/edit_peer_permissions_box.h" @@ -754,7 +754,7 @@ void Controller::refreshCreateInviteLink() { } // namespace -EditPeerGroupTypeBox::EditPeerGroupTypeBox( +EditPeerTypeBox::EditPeerTypeBox( QWidget*, not_null p, FnMut savedCallback, @@ -768,7 +768,7 @@ EditPeerGroupTypeBox::EditPeerGroupTypeBox( allowSave = !usernameSaved->isEmpty() && usernameSaved.has_value(); } -void EditPeerGroupTypeBox::prepare() { +void EditPeerTypeBox::prepare() { _peer->updateFull(); setTitle(langFactory((peer->isChat() || peer->isMegagroup()) @@ -794,7 +794,7 @@ void EditPeerGroupTypeBox::prepare() { setupContent(); } -void EditPeerGroupTypeBox::setupContent() { +void EditPeerTypeBox::setupContent() { isGroup = (_peer->isChat() || _peer->isMegagroup()); const auto content = Ui::CreateChild(this); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_group_type_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.h similarity index 93% rename from Telegram/SourceFiles/boxes/peers/edit_peer_group_type_box.h rename to Telegram/SourceFiles/boxes/peers/edit_peer_type_box.h index 989c6abce..23daf90e9 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_group_type_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.h @@ -35,10 +35,10 @@ enum class UsernameState { NotAvailable, }; -class EditPeerGroupTypeBox : public BoxContent { +class EditPeerTypeBox : public BoxContent { public: - EditPeerGroupTypeBox( + EditPeerTypeBox( QWidget*, not_null p, FnMut savedCallback, diff --git a/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp b/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp deleted file mode 100644 index ee4daf6dc..000000000 --- a/Telegram/SourceFiles/boxes/peers/manage_peer_box.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "boxes/peers/manage_peer_box.h" - -#include -#include "lang/lang_keys.h" -#include "boxes/peers/edit_peer_info_box.h" -#include "boxes/peers/edit_peer_permissions_box.h" -#include "boxes/peers/edit_participants_box.h" -#include "ui/wrap/vertical_layout.h" -#include "ui/widgets/labels.h" -#include "history/admin_log/history_admin_log_section.h" -#include "window/window_controller.h" -#include "info/profile/info_profile_button.h" -#include "info/profile/info_profile_icon.h" -#include "info/profile/info_profile_values.h" -#include "data/data_channel.h" -#include "data/data_chat.h" -#include "mainwindow.h" -#include "auth_session.h" -#include "apiwrap.h" -#include "styles/style_boxes.h" -#include "styles/style_info.h" - -namespace { - -Fn ManagePeerTitle(not_null peer) { - return langFactory((peer->isChat() || peer->isMegagroup()) - ? lng_manage_group_title - : lng_manage_channel_title); -} - -auto ToPositiveNumberString() { - return rpl::map([](int count) { - return count ? QString::number(count) : QString(); - }); -} - -Info::Profile::Button *AddButton( - not_null parent, - rpl::producer &&text, - Fn callback, - const style::icon &icon) { - return ManagePeerBox::CreateButton( - parent, - std::move(text), - rpl::single(QString()), - std::move(callback), - st::managePeerButton, - &icon); -} - -void AddButtonWithCount( - not_null parent, - rpl::producer &&text, - rpl::producer &&count, - Fn callback, - const style::icon &icon) { - ManagePeerBox::CreateButton( - parent, - std::move(text), - std::move(count), - std::move(callback), - st::managePeerButton, - &icon); -} - -bool HasRecentActions(not_null channel) { - return channel->hasAdminRights() || channel->amCreator(); -} - -void ShowRecentActions( - not_null navigation, - not_null channel) { - navigation->showSection(AdminLog::SectionMemento(channel)); -} - -bool HasEditInfoBox(not_null peer) { - if (const auto chat = peer->asChat()) { - if (chat->canEditInformation()) { - return true; - } - } else if (const auto channel = peer->asChannel()) { - if (channel->canEditInformation()) { - return true; - } else if (!channel->isPublic() && channel->canAddMembers()) { - // Edit invite link. - return true; - } - } - return false; -} - -void ShowEditPermissions(not_null peer) { - const auto box = Ui::show( - Box(peer), - LayerOption::KeepOther); - box->saveEvents( - ) | rpl::start_with_next([=](MTPDchatBannedRights::Flags restrictions) { - const auto callback = crl::guard(box, [=](bool success) { - if (success) { - box->closeBox(); - } - }); - peer->session().api().saveDefaultRestrictions( - peer->migrateToOrMe(), - MTP_chatBannedRights(MTP_flags(restrictions), MTP_int(0)), - callback); - }, box->lifetime()); -} - -void FillManageChatBox( - not_null navigation, - not_null chat, - not_null content) { - if (HasEditInfoBox(chat)) { - AddButton( - content, - Lang::Viewer(lng_manage_group_info), - [=] { Ui::show(Box(chat)); }, - st::infoIconInformation); - } - if (chat->canEditPermissions()) { - AddButton( - content, - Lang::Viewer(lng_manage_peer_permissions), - [=] { ShowEditPermissions(chat); }, - st::infoIconPermissions); - } - if (chat->amIn()) { - AddButtonWithCount( - content, - Lang::Viewer(lng_manage_peer_administrators), - Info::Profile::AdminsCountValue(chat) - | ToPositiveNumberString(), - [=] { - ParticipantsBoxController::Start( - navigation, - chat, - ParticipantsBoxController::Role::Admins); - }, - st::infoIconAdministrators); - AddButtonWithCount( - content, - Lang::Viewer(lng_manage_peer_members), - Info::Profile::MembersCountValue(chat) - | ToPositiveNumberString(), - [=] { - ParticipantsBoxController::Start( - navigation, - chat, - ParticipantsBoxController::Role::Members); - }, - st::infoIconMembers); - } -} - -void FillManageChannelBox( - not_null navigation, - not_null channel, - not_null content) { - auto isGroup = channel->isMegagroup(); - if (HasEditInfoBox(channel)) { - AddButton( - content, - Lang::Viewer(isGroup - ? lng_manage_group_info - : lng_manage_channel_info), - [=] { Ui::show(Box(channel)); }, - st::infoIconInformation); - } - if (HasRecentActions(channel)) { - AddButton( - content, - Lang::Viewer(lng_manage_peer_recent_actions), - [=] { ShowRecentActions(navigation, channel); }, - st::infoIconRecentActions); - } - if (channel->canEditPermissions()) { - AddButton( - content, - Lang::Viewer(lng_manage_peer_permissions), - [=] { ShowEditPermissions(channel); }, - st::infoIconPermissions); - } - if (channel->canViewAdmins()) { - AddButtonWithCount( - content, - Lang::Viewer(lng_manage_peer_administrators), - Info::Profile::AdminsCountValue(channel) - | ToPositiveNumberString(), - [=] { - ParticipantsBoxController::Start( - navigation, - channel, - ParticipantsBoxController::Role::Admins); - }, - st::infoIconAdministrators); - } - if (channel->canViewMembers()) { - AddButtonWithCount( - content, - Lang::Viewer(lng_manage_peer_members), - Info::Profile::MembersCountValue(channel) - | ToPositiveNumberString(), - [=] { - ParticipantsBoxController::Start( - navigation, - channel, - ParticipantsBoxController::Role::Members); - }, - st::infoIconMembers); - } - if (!channel->isMegagroup()) { - AddButtonWithCount( - content, - Lang::Viewer(lng_manage_peer_removed_users), - Info::Profile::KickedCountValue(channel) - | ToPositiveNumberString(), - [=] { - ParticipantsBoxController::Start( - navigation, - channel, - ParticipantsBoxController::Role::Kicked); - }, - st::infoIconBlacklist); - } -} - -} // namespace - -ManagePeerBox::ManagePeerBox( - QWidget*, - not_null peer) -: _peer(peer) { -} - -bool ManagePeerBox::Available(not_null peer) { - if (const auto chat = peer->asChat()) { - return false - || chat->canEditInformation() - || chat->canEditPermissions(); - } else if (const auto channel = peer->asChannel()) { - // canViewMembers() is removed, because in supergroups you - // see them in profile and in channels only admins can see them. - - // canViewAdmins() is removed, because in supergroups it is - // always true and in channels it is equal to canViewBanned(). - - return false - //|| channel->canViewMembers() - //|| channel->canViewAdmins() - || channel->canViewBanned() - || channel->canEditInformation() - || channel->canEditPermissions() - || HasRecentActions(channel); - } else { - return false; - } -} - -Info::Profile::Button *ManagePeerBox::CreateButton( - not_null parent, - rpl::producer &&text, - rpl::producer &&count, - Fn callback, - const style::InfoProfileCountButton &st, - const style::icon *icon) { - const auto button = parent->add( - object_ptr( - parent, - std::move(text), - st.button)); - button->addClickHandler(callback); - if (icon) { - Ui::CreateChild( - button, - *icon, - st.iconPosition); - } - const auto label = Ui::CreateChild( - button, - std::move(count), - st.label); - label->setAttribute(Qt::WA_TransparentForMouseEvents); - - rpl::combine( - button->widthValue(), - label->widthValue() - ) | rpl::start_with_next([=, &st](int outerWidth, int width) { - label->moveToRight( - st.labelPosition.x(), - st.labelPosition.y(), - outerWidth); - }, label->lifetime()); - - return button; -} - -void ManagePeerBox::prepare() { - _peer->updateFull(); - - setTitle(ManagePeerTitle(_peer)); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); - - setupContent(); -} - -void ManagePeerBox::setupContent() { - const auto content = Ui::CreateChild(this); - if (const auto chat = _peer->asChat()) { - FillManageChatBox(App::wnd()->controller(), chat, content); - } else if (const auto channel = _peer->asChannel()) { - FillManageChannelBox(App::wnd()->controller(), channel, content); - } - setDimensionsToContent(st::boxWidth, content); -} diff --git a/Telegram/SourceFiles/boxes/peers/manage_peer_box.h b/Telegram/SourceFiles/boxes/peers/manage_peer_box.h deleted file mode 100644 index 631ecbdea..000000000 --- a/Telegram/SourceFiles/boxes/peers/manage_peer_box.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include "boxes/abstract_box.h" - -namespace style { -struct InfoProfileCountButton; -} // namespace style - -namespace Ui { -class VerticalLayout; -} // namespace Ui - -namespace Info { -namespace Profile { -class Button; -} // namespace Profile -} // namespace Info - -class ManagePeerBox : public BoxContent { -public: - ManagePeerBox(QWidget*, not_null peer); - - static bool Available(not_null peer); - - static Info::Profile::Button *CreateButton( - not_null parent, - rpl::producer &&text, - rpl::producer &&count, - Fn callback, - const style::InfoProfileCountButton &st, - const style::icon *icon = nullptr); - -protected: - void prepare() override; - -private: - void setupContent(); - - not_null _peer; - -}; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 917ecb7c3..e7dea0a9c 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/report_box.h" #include "boxes/create_poll_box.h" #include "boxes/peers/add_participants_box.h" -#include "boxes/peers/manage_peer_box.h" #include "ui/toast/toast.h" #include "auth_session.h" #include "apiwrap.h" @@ -37,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_drafts.h" #include "data/data_user.h" #include "dialogs/dialogs_key.h" +#include "boxes/peers/edit_peer_info_box.h" namespace Window { namespace { @@ -354,7 +354,7 @@ void Filler::addUserActions(not_null user) { void Filler::addChatActions(not_null chat) { if (_source != PeerMenuSource::ChatsList) { - if (ManagePeerBox::Available(chat)) { + if (EditPeerInfoBox::Available(chat)) { const auto text = lang(lng_manage_group_title); _addAction(text, [=] { App::wnd()->controller()->showEditPeerBox(chat); @@ -396,7 +396,7 @@ void Filler::addChannelActions(not_null channel) { } } if (_source != PeerMenuSource::ChatsList) { - if (ManagePeerBox::Available(channel)) { + if (EditPeerInfoBox::Available(channel)) { const auto text = lang(isGroup ? lng_manage_group_title : lng_manage_channel_title); diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index 5795eab8d..1632a0c49 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -6,14 +6,12 @@ <(src_loc)/boxes/peers/edit_participants_box.h <(src_loc)/boxes/peers/edit_peer_info_box.cpp <(src_loc)/boxes/peers/edit_peer_info_box.h -<(src_loc)/boxes/peers/edit_peer_group_type_box.cpp -<(src_loc)/boxes/peers/edit_peer_group_type_box.h +<(src_loc)/boxes/peers/edit_peer_type_box.cpp +<(src_loc)/boxes/peers/edit_peer_type_box.h <(src_loc)/boxes/peers/edit_peer_history_visibility_box.cpp <(src_loc)/boxes/peers/edit_peer_history_visibility_box.h <(src_loc)/boxes/peers/edit_peer_permissions_box.cpp <(src_loc)/boxes/peers/edit_peer_permissions_box.h -<(src_loc)/boxes/peers/manage_peer_box.cpp -<(src_loc)/boxes/peers/manage_peer_box.h <(src_loc)/boxes/about_box.cpp <(src_loc)/boxes/about_box.h <(src_loc)/boxes/abstract_box.cpp