From f21edd1d236c0c526fb0af6f67663e3001bf748f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 29 Jan 2023 15:36:30 +0300 Subject: [PATCH] Replaced EditPeerPermissionsBox with generic box. --- .../boxes/peers/edit_peer_info_box.cpp | 76 +- .../boxes/peers/edit_peer_permissions_box.cpp | 672 +++++++++--------- .../boxes/peers/edit_peer_permissions_box.h | 57 +- 3 files changed, 394 insertions(+), 411 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 2ffc8a5357..39c9963cd5 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -200,46 +200,46 @@ void SaveSlowmodeSeconds( void ShowEditPermissions( not_null navigation, not_null peer) { - auto content = Box(navigation, peer); - const auto box = QPointer(content.data()); - navigation->parentController()->show( - std::move(content), - Ui::LayerOption::KeepOther); - const auto saving = box->lifetime().make_state(0); - const auto save = [=]( - not_null peer, - EditPeerPermissionsBox::Result result) { - Expects(result.slowmodeSeconds == 0 || peer->isChannel()); + auto createBox = [=](not_null box) { + const auto saving = box->lifetime().make_state(0); + const auto save = [=]( + not_null peer, + EditPeerPermissionsBoxResult result) { + Expects(result.slowmodeSeconds == 0 || peer->isChannel()); - const auto close = crl::guard(box, [=] { box->closeBox(); }); - SaveDefaultRestrictions( - peer, - result.rights, - close); - if (const auto channel = peer->asChannel()) { - SaveSlowmodeSeconds(channel, result.slowmodeSeconds, close); - } + const auto close = crl::guard(box, [=] { box->closeBox(); }); + SaveDefaultRestrictions( + peer, + result.rights, + close); + if (const auto channel = peer->asChannel()) { + SaveSlowmodeSeconds(channel, result.slowmodeSeconds, close); + } + }; + auto done = [=](EditPeerPermissionsBoxResult result) { + if (*saving) { + return; + } + *saving = true; + + const auto saveFor = peer->migrateToOrMe(); + const auto chat = saveFor->asChat(); + if (!result.slowmodeSeconds || !chat) { + save(saveFor, result); + return; + } + const auto api = &peer->session().api(); + api->migrateChat(chat, [=](not_null channel) { + save(channel, result); + }, [=](const QString &) { + *saving = false; + }); + }; + ShowEditPeerPermissionsBox(box, navigation, peer, std::move(done)); }; - box->saveEvents( - ) | rpl::start_with_next([=](EditPeerPermissionsBox::Result result) { - if (*saving) { - return; - } - *saving = true; - - const auto saveFor = peer->migrateToOrMe(); - const auto chat = saveFor->asChat(); - if (!result.slowmodeSeconds || !chat) { - save(saveFor, result); - return; - } - const auto api = &peer->session().api(); - api->migrateChat(chat, [=](not_null channel) { - save(channel, result); - }, [=](const QString &) { - *saving = false; - }); - }, box->lifetime()); + navigation->parentController()->show( + Box(std::move(createBox)), + Ui::LayerOption::KeepOther); } } // namespace diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 28e3f043f6..992c5a233b 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -26,7 +26,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "window/window_controller.h" #include "main/main_session.h" -#include "mainwindow.h" #include "apiwrap.h" #include "settings/settings_common.h" #include "styles/style_layers.h" @@ -212,7 +211,7 @@ template < typename Flags, typename DisabledMessagePairs, typename FlagLabelPairs> -[[nodiscard]] EditFlagsControl CreateEditFlags( +[[nodiscard]] EditFlagsControl CreateEditFlags( QWidget *parent, rpl::producer header, Flags checked, @@ -305,73 +304,283 @@ template < }; } +void AddSlowmodeLabels( + not_null container) { + const auto labels = container->add( + object_ptr(container, st::normalFont->height), + st::slowmodeLabelsMargin); + for (auto i = 0; i != kSlowmodeValues; ++i) { + const auto seconds = SlowmodeDelayByIndex(i); + const auto label = Ui::CreateChild( + labels, + st::slowmodeLabel, + (!seconds + ? tr::lng_rights_slowmode_off(tr::now) + : (seconds < 60) + ? tr::lng_seconds_tiny(tr::now, lt_count, seconds) + : (seconds < 3600) + ? tr::lng_minutes_tiny(tr::now, lt_count, seconds / 60) + : tr::lng_hours_tiny(tr::now, lt_count,seconds / 3600))); + rpl::combine( + labels->widthValue(), + label->widthValue() + ) | rpl::start_with_next([=](int outer, int inner) { + const auto skip = st::localStorageLimitMargin; + const auto size = st::localStorageLimitSlider.seekSize; + const auto available = outer + - skip.left() + - skip.right() + - size.width(); + const auto shift = (i == 0) + ? -(size.width() / 2) + : (i + 1 == kSlowmodeValues) + ? (size.width() - (size.width() / 2) - inner) + : (-inner / 2); + const auto left = skip.left() + + (size.width() / 2) + + (i * available) / (kSlowmodeValues - 1) + + shift; + label->moveToLeft(left, 0, outer); + }, label->lifetime()); + } +} + +Fn AddSlowmodeSlider( + not_null container, + not_null peer) { + using namespace rpl::mappers; + + if (const auto chat = peer->asChat()) { + if (!chat->amCreator()) { + return [] { return 0; }; + } + } + const auto channel = peer->asChannel(); + auto &lifetime = container->lifetime(); + const auto secondsCount = lifetime.make_state>( + channel ? channel->slowmodeSeconds() : 0); + + container->add( + object_ptr(container), + { 0, st::infoProfileSkip, 0, st::infoProfileSkip }); + + container->add( + object_ptr( + container, + tr::lng_rights_slowmode_header(), + st::rightsHeaderLabel), + st::rightsHeaderMargin); + + AddSlowmodeLabels(container); + + const auto slider = container->add( + object_ptr(container, st::localStorageLimitSlider), + st::localStorageLimitMargin); + slider->resize(st::localStorageLimitSlider.seekSize); + slider->setPseudoDiscrete( + kSlowmodeValues, + SlowmodeDelayByIndex, + secondsCount->current(), + [=](int seconds) { + (*secondsCount) = seconds; + }); + + auto hasSlowMode = secondsCount->value( + ) | rpl::map( + _1 != 0 + ) | rpl::distinct_until_changed(); + + auto useSeconds = secondsCount->value( + ) | rpl::map( + _1 < 60 + ) | rpl::distinct_until_changed(); + + auto interval = rpl::combine( + std::move(useSeconds), + tr::lng_rights_slowmode_interval_seconds( + lt_count, + secondsCount->value() | tr::to_count()), + tr::lng_rights_slowmode_interval_minutes( + lt_count, + secondsCount->value() | rpl::map(_1 / 60.)) + ) | rpl::map([]( + bool use, + const QString &seconds, + const QString &minutes) { + return use ? seconds : minutes; + }); + + auto aboutText = rpl::combine( + std::move(hasSlowMode), + tr::lng_rights_slowmode_about(), + tr::lng_rights_slowmode_about_interval( + lt_interval, + std::move(interval)) + ) | rpl::map([]( + bool has, + const QString &about, + const QString &aboutInterval) { + return has ? aboutInterval : about; + }); + + container->add( + object_ptr( + container, + object_ptr( + container, + std::move(aboutText), + st::boxDividerLabel), + st::proxyAboutPadding), + style::margins(0, st::infoProfileSkip, 0, st::infoProfileSkip)); + + return [=] { return secondsCount->current(); }; +} + +void AddSuggestGigagroup( + not_null container, + Fn callback) { + container->add( + object_ptr( + container, + tr::lng_rights_gigagroup_title(), + st::rightsHeaderLabel), + st::rightsHeaderMargin); + container->add(EditPeerInfoBox::CreateButton( + container, + tr::lng_rights_gigagroup_convert(), + rpl::single(QString()), + std::move(callback), + st::peerPermissionsButton, + {})); + + container->add( + object_ptr( + container, + object_ptr( + container, + tr::lng_rights_gigagroup_about(), + st::boxDividerLabel), + st::proxyAboutPadding), + style::margins(0, st::infoProfileSkip, 0, st::infoProfileSkip)); +} + +void AddBannedButtons( + not_null container, + not_null navigation, + not_null peer) { + if (const auto chat = peer->asChat()) { + if (!chat->amCreator()) { + return; + } + } + const auto channel = peer->asChannel(); + container->add(EditPeerInfoBox::CreateButton( + container, + tr::lng_manage_peer_exceptions(), + (channel + ? Info::Profile::RestrictedCountValue(channel) + : rpl::single(0)) | ToPositiveNumberString(), + [=] { + ParticipantsBoxController::Start( + navigation, + peer, + ParticipantsBoxController::Role::Restricted); + }, + st::peerPermissionsButton, + {})); + if (channel) { + container->add(EditPeerInfoBox::CreateButton( + container, + tr::lng_manage_peer_removed_users(), + Info::Profile::KickedCountValue(channel) + | ToPositiveNumberString(), + [=] { + ParticipantsBoxController::Start( + navigation, + peer, + ParticipantsBoxController::Role::Kicked); + }, + st::peerPermissionsButton, + {})); + } +} + } // namespace -ChatAdminRights DisabledByDefaultRestrictions(not_null peer) { - using Flag = ChatAdminRight; - using Restriction = ChatRestriction; +void ShowEditPeerPermissionsBox( + not_null box, + not_null navigation, + not_null channelOrGroup, + Fn done) { + const auto peer = channelOrGroup->migrateToOrMe(); + box->setTitle(tr::lng_manage_peer_permissions()); + + const auto inner = box->verticalLayout(); + + using Flag = ChatRestriction; + using Flags = ChatRestrictions; + + const auto disabledByAdminRights = DisabledByAdminRights(peer); const auto restrictions = FixDependentRestrictions([&] { if (const auto chat = peer->asChat()) { - return chat->defaultRestrictions(); + return chat->defaultRestrictions() + | disabledByAdminRights; } else if (const auto channel = peer->asChannel()) { - return channel->defaultRestrictions(); + return channel->defaultRestrictions() + | (channel->isPublic() + ? (Flag::ChangeInfo | Flag::PinMessages) + : Flags(0)) + | disabledByAdminRights; } - Unexpected("User in DisabledByDefaultRestrictions."); + Unexpected("User in EditPeerPermissionsBox."); }()); - return Flag(0) - | ((restrictions & Restriction::PinMessages) - ? Flag(0) - : Flag::PinMessages) - // - // We allow to edit 'invite_users' admin right no matter what - // is chosen in default permissions for 'invite_users', because - // if everyone can 'invite_users' it handles invite link for admins. - // - //| ((restrictions & Restriction::AddParticipants) - // ? Flag(0) - // : Flag::InviteByLinkOrAdd) - // - | ((restrictions & Restriction::ChangeInfo) - ? Flag(0) - : Flag::ChangeInfo); -} - -ChatRestrictions FixDependentRestrictions(ChatRestrictions restrictions) { - const auto &dependencies = Dependencies(restrictions); - - // Fix iOS bug of saving send_inline like embed_links. - // We copy send_stickers to send_inline. - if (restrictions & ChatRestriction::SendStickers) { - restrictions |= ChatRestriction::SendInline; - } else { - restrictions &= ~ChatRestriction::SendInline; - } - - // Apply the strictest. - const auto fixOne = [&] { - for (const auto &[first, second] : dependencies) { - if ((restrictions & second) && !(restrictions & first)) { - restrictions |= first; - return true; + const auto disabledMessages = [&] { + auto result = std::map(); + result.emplace( + disabledByAdminRights, + tr::lng_rights_permission_cant_edit(tr::now)); + if (const auto channel = peer->asChannel()) { + if (channel->isPublic() + || (channel->isMegagroup() && channel->linkedChat())) { + result.emplace( + Flag::ChangeInfo | Flag::PinMessages, + tr::lng_rights_permission_unavailable(tr::now)); } } - return false; - }; - while (fixOne()) { - } - return restrictions; -} + return result; + }(); -ChatAdminRights AdminRightsForOwnershipTransfer( - Data::AdminRightsSetOptions options) { - auto result = ChatAdminRights(); - for (const auto &[flag, label] : AdminRightLabels(options)) { - if (!(flag & ChatAdminRight::Anonymous)) { - result |= flag; + auto [checkboxes, getRestrictions, changes] = CreateEditRestrictions( + inner, + tr::lng_rights_default_restrictions_header(), + restrictions, + disabledMessages, + { .isForum = peer->isForum() }); + + inner->add(std::move(checkboxes)); + + const auto getSlowmodeSeconds = AddSlowmodeSlider(inner, peer); + + if (const auto channel = peer->asChannel()) { + if (channel->amCreator() + && channel->membersCount() >= kSuggestGigagroupThreshold) { + AddSuggestGigagroup( + inner, + AboutGigagroupCallback( + peer->asChannel(), + navigation->parentController())); } } - return result; + + AddBannedButtons(inner, navigation, peer); + + box->addButton(tr::lng_settings_save(), [=, rights = getRestrictions] { + done({ rights(), getSlowmodeSeconds() }); + }); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); + + box->setWidth(st::boxWideWidth); } Fn AboutGigagroupCallback( @@ -447,286 +656,6 @@ Fn AboutGigagroupCallback( }; } -EditPeerPermissionsBox::EditPeerPermissionsBox( - QWidget*, - not_null navigation, - not_null peer) -: _navigation(navigation) -, _peer(peer->migrateToOrMe()) { -} - -auto EditPeerPermissionsBox::saveEvents() const -> rpl::producer { - Expects(_save != nullptr); - - return _save->clicks() | rpl::map(_value); -} - -void EditPeerPermissionsBox::prepare() { - setTitle(tr::lng_manage_peer_permissions()); - - const auto inner = setInnerWidget(object_ptr(this)); - - using Flag = ChatRestriction; - using Flags = ChatRestrictions; - - const auto disabledByAdminRights = DisabledByAdminRights(_peer); - const auto restrictions = FixDependentRestrictions([&] { - if (const auto chat = _peer->asChat()) { - return chat->defaultRestrictions() - | disabledByAdminRights; - } else if (const auto channel = _peer->asChannel()) { - return channel->defaultRestrictions() - | (channel->isPublic() - ? (Flag::ChangeInfo | Flag::PinMessages) - : Flags(0)) - | disabledByAdminRights; - } - Unexpected("User in EditPeerPermissionsBox."); - }()); - const auto disabledMessages = [&] { - auto result = std::map(); - result.emplace( - disabledByAdminRights, - tr::lng_rights_permission_cant_edit(tr::now)); - if (const auto channel = _peer->asChannel()) { - if (channel->isPublic() - || (channel->isMegagroup() && channel->linkedChat())) { - result.emplace( - Flag::ChangeInfo | Flag::PinMessages, - tr::lng_rights_permission_unavailable(tr::now)); - } - } - return result; - }(); - - auto [checkboxes, getRestrictions, changes] = CreateEditRestrictions( - this, - tr::lng_rights_default_restrictions_header(), - restrictions, - disabledMessages, - { .isForum = _peer->isForum() }); - - inner->add(std::move(checkboxes)); - - const auto getSlowmodeSeconds = addSlowmodeSlider(inner); - - if (const auto channel = _peer->asChannel()) { - if (channel->amCreator() - && channel->membersCount() >= kSuggestGigagroupThreshold) { - addSuggestGigagroup(inner); - } - } - - addBannedButtons(inner); - - _value = [=, rights = getRestrictions]() -> Result { - return { rights(), getSlowmodeSeconds() }; - }; - _save = addButton(tr::lng_settings_save()); - addButton(tr::lng_cancel(), [=] { closeBox(); }); - - setDimensionsToContent(st::boxWidth, inner); -} - -Fn EditPeerPermissionsBox::addSlowmodeSlider( - not_null container) { - using namespace rpl::mappers; - - if (const auto chat = _peer->asChat()) { - if (!chat->amCreator()) { - return [] { return 0; }; - } - } - const auto channel = _peer->asChannel(); - auto &lifetime = container->lifetime(); - const auto secondsCount = lifetime.make_state>( - channel ? channel->slowmodeSeconds() : 0); - - container->add( - object_ptr(container), - { 0, st::infoProfileSkip, 0, st::infoProfileSkip }); - - container->add( - object_ptr( - container, - tr::lng_rights_slowmode_header(), - st::rightsHeaderLabel), - st::rightsHeaderMargin); - - addSlowmodeLabels(container); - - const auto slider = container->add( - object_ptr(container, st::localStorageLimitSlider), - st::localStorageLimitMargin); - slider->resize(st::localStorageLimitSlider.seekSize); - slider->setPseudoDiscrete( - kSlowmodeValues, - SlowmodeDelayByIndex, - secondsCount->current(), - [=](int seconds) { - (*secondsCount) = seconds; - }); - - auto hasSlowMode = secondsCount->value( - ) | rpl::map( - _1 != 0 - ) | rpl::distinct_until_changed(); - - auto useSeconds = secondsCount->value( - ) | rpl::map( - _1 < 60 - ) | rpl::distinct_until_changed(); - - auto interval = rpl::combine( - std::move(useSeconds), - tr::lng_rights_slowmode_interval_seconds( - lt_count, - secondsCount->value() | tr::to_count()), - tr::lng_rights_slowmode_interval_minutes( - lt_count, - secondsCount->value() | rpl::map(_1 / 60.)) - ) | rpl::map([]( - bool use, - const QString &seconds, - const QString &minutes) { - return use ? seconds : minutes; - }); - - auto aboutText = rpl::combine( - std::move(hasSlowMode), - tr::lng_rights_slowmode_about(), - tr::lng_rights_slowmode_about_interval( - lt_interval, - std::move(interval)) - ) | rpl::map([]( - bool has, - const QString &about, - const QString &aboutInterval) { - return has ? aboutInterval : about; - }); - - container->add( - object_ptr( - container, - object_ptr( - container, - std::move(aboutText), - st::boxDividerLabel), - st::proxyAboutPadding), - style::margins(0, st::infoProfileSkip, 0, st::infoProfileSkip)); - - return [=] { return secondsCount->current(); }; -} - -void EditPeerPermissionsBox::addSlowmodeLabels( - not_null container) { - const auto labels = container->add( - object_ptr(container, st::normalFont->height), - st::slowmodeLabelsMargin); - for (auto i = 0; i != kSlowmodeValues; ++i) { - const auto seconds = SlowmodeDelayByIndex(i); - const auto label = Ui::CreateChild( - labels, - st::slowmodeLabel, - (!seconds - ? tr::lng_rights_slowmode_off(tr::now) - : (seconds < 60) - ? tr::lng_seconds_tiny(tr::now, lt_count, seconds) - : (seconds < 3600) - ? tr::lng_minutes_tiny(tr::now, lt_count, seconds / 60) - : tr::lng_hours_tiny(tr::now, lt_count,seconds / 3600))); - rpl::combine( - labels->widthValue(), - label->widthValue() - ) | rpl::start_with_next([=](int outer, int inner) { - const auto skip = st::localStorageLimitMargin; - const auto size = st::localStorageLimitSlider.seekSize; - const auto available = outer - - skip.left() - - skip.right() - - size.width(); - const auto shift = (i == 0) - ? -(size.width() / 2) - : (i + 1 == kSlowmodeValues) - ? (size.width() - (size.width() / 2) - inner) - : (-inner / 2); - const auto left = skip.left() - + (size.width() / 2) - + (i * available) / (kSlowmodeValues - 1) - + shift; - label->moveToLeft(left, 0, outer); - }, label->lifetime()); - } -} - -void EditPeerPermissionsBox::addSuggestGigagroup( - not_null container) { - container->add( - object_ptr( - container, - tr::lng_rights_gigagroup_title(), - st::rightsHeaderLabel), - st::rightsHeaderMargin); - container->add(EditPeerInfoBox::CreateButton( - container, - tr::lng_rights_gigagroup_convert(), - rpl::single(QString()), - AboutGigagroupCallback( - _peer->asChannel(), - _navigation->parentController()), - st::peerPermissionsButton, - {})); - - container->add( - object_ptr( - container, - object_ptr( - container, - tr::lng_rights_gigagroup_about(), - st::boxDividerLabel), - st::proxyAboutPadding), - style::margins(0, st::infoProfileSkip, 0, st::infoProfileSkip)); -} - -void EditPeerPermissionsBox::addBannedButtons( - not_null container) { - if (const auto chat = _peer->asChat()) { - if (!chat->amCreator()) { - return; - } - } - const auto channel = _peer->asChannel(); - container->add(EditPeerInfoBox::CreateButton( - container, - tr::lng_manage_peer_exceptions(), - (channel - ? Info::Profile::RestrictedCountValue(channel) - : rpl::single(0)) | ToPositiveNumberString(), - [=] { - ParticipantsBoxController::Start( - _navigation, - _peer, - ParticipantsBoxController::Role::Restricted); - }, - st::peerPermissionsButton, - {})); - if (channel) { - container->add(EditPeerInfoBox::CreateButton( - container, - tr::lng_manage_peer_removed_users(), - Info::Profile::KickedCountValue(channel) - | ToPositiveNumberString(), - [=] { - ParticipantsBoxController::Start( - _navigation, - _peer, - ParticipantsBoxController::Role::Kicked); - }, - st::peerPermissionsButton, - {})); - } -} - std::vector RestrictionLabels( Data::RestrictionsSetOptions options) { using Flag = ChatRestriction; @@ -802,7 +731,7 @@ std::vector AdminRightLabels( } } -EditFlagsControl CreateEditRestrictions( +EditFlagsControl CreateEditRestrictions( QWidget *parent, rpl::producer header, ChatRestrictions restrictions, @@ -824,7 +753,7 @@ EditFlagsControl CreateEditRestrictions( return result; } -EditFlagsControl CreateEditAdminRights( +EditFlagsControl CreateEditAdminRights( QWidget *parent, rpl::producer header, ChatAdminRights rights, @@ -837,3 +766,70 @@ EditFlagsControl CreateEditAdminRights( disabledMessages, AdminRightLabels(options)); } + +ChatAdminRights DisabledByDefaultRestrictions(not_null peer) { + using Flag = ChatAdminRight; + using Restriction = ChatRestriction; + + const auto restrictions = FixDependentRestrictions([&] { + if (const auto chat = peer->asChat()) { + return chat->defaultRestrictions(); + } else if (const auto channel = peer->asChannel()) { + return channel->defaultRestrictions(); + } + Unexpected("User in DisabledByDefaultRestrictions."); + }()); + return Flag(0) + | ((restrictions & Restriction::PinMessages) + ? Flag(0) + : Flag::PinMessages) + // + // We allow to edit 'invite_users' admin right no matter what + // is chosen in default permissions for 'invite_users', because + // if everyone can 'invite_users' it handles invite link for admins. + // + //| ((restrictions & Restriction::AddParticipants) + // ? Flag(0) + // : Flag::InviteByLinkOrAdd) + // + | ((restrictions & Restriction::ChangeInfo) + ? Flag(0) + : Flag::ChangeInfo); +} + +ChatRestrictions FixDependentRestrictions(ChatRestrictions restrictions) { + const auto &dependencies = Dependencies(restrictions); + + // Fix iOS bug of saving send_inline like embed_links. + // We copy send_stickers to send_inline. + if (restrictions & ChatRestriction::SendStickers) { + restrictions |= ChatRestriction::SendInline; + } else { + restrictions &= ~ChatRestriction::SendInline; + } + + // Apply the strictest. + const auto fixOne = [&] { + for (const auto &[first, second] : dependencies) { + if ((restrictions & second) && !(restrictions & first)) { + restrictions |= first; + return true; + } + } + return false; + }; + while (fixOne()) { + } + return restrictions; +} + +ChatAdminRights AdminRightsForOwnershipTransfer( + Data::AdminRightsSetOptions options) { + auto result = ChatAdminRights(); + for (const auto &[flag, label] : AdminRightLabels(options)) { + if (!(flag & ChatAdminRight::Anonymous)) { + result |= flag; + } + } + return result; +} diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h index 0994a34976..f28f5b472d 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h @@ -7,49 +7,34 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "boxes/abstract_box.h" #include "data/data_chat_participant_status.h" namespace Ui { +class GenericBox; class RoundButton; +class RpWidget; class VerticalLayout; } // namespace Ui +template +class object_ptr; + namespace Window { class SessionController; class SessionNavigation; } // namespace Window -class EditPeerPermissionsBox : public Ui::BoxContent { -public: - EditPeerPermissionsBox( - QWidget*, - not_null navigation, - not_null peer); - - struct Result { - ChatRestrictions rights; - int slowmodeSeconds = 0; - }; - - rpl::producer saveEvents() const; - -protected: - void prepare() override; - -private: - Fn addSlowmodeSlider(not_null container); - void addSlowmodeLabels(not_null container); - void addSuggestGigagroup(not_null container); - void addBannedButtons(not_null container); - - const not_null _navigation; - const not_null _peer; - Ui::RoundButton *_save = nullptr; - Fn _value; - +struct EditPeerPermissionsBoxResult final { + ChatRestrictions rights; + int slowmodeSeconds = 0; }; +void ShowEditPeerPermissionsBox( + not_null box, + not_null navigation, + not_null channelOrGroup, + Fn done); + [[nodiscard]] Fn AboutGigagroupCallback( not_null channel, not_null controller); @@ -68,26 +53,28 @@ struct AdminRightLabel { [[nodiscard]] std::vector AdminRightLabels( Data::AdminRightsSetOptions options); -template +template struct EditFlagsControl { - object_ptr widget; + object_ptr widget; Fn value; rpl::producer changes; }; -[[nodiscard]] EditFlagsControl CreateEditRestrictions( +[[nodiscard]] auto CreateEditRestrictions( QWidget *parent, rpl::producer header, ChatRestrictions restrictions, std::map disabledMessages, - Data::RestrictionsSetOptions options); + Data::RestrictionsSetOptions options) +-> EditFlagsControl; -[[nodiscard]] EditFlagsControl CreateEditAdminRights( +[[nodiscard]] auto CreateEditAdminRights( QWidget *parent, rpl::producer header, ChatAdminRights rights, std::map disabledMessages, - Data::AdminRightsSetOptions options); + Data::AdminRightsSetOptions options) +-> EditFlagsControl; [[nodiscard]] ChatAdminRights DisabledByDefaultRestrictions( not_null peer);