diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index e1c0d72d21..626b3652af 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2014,6 +2014,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_slowmode_no_many" = "Slow mode is enabled. You can't send more than one message at a time."; "lng_slowmode_too_long" = "Sorry, this text is too long to send as one message.\n\nSlow mode is enabled. You can't send more than one message at a time."; +"lng_rights_gigagroup_title" = "Broadcast group"; +"lng_rights_gigagroup_convert" = "Convert to Broadcast Group"; +"lng_rights_gigagroup_about" = "Broadcast groups can have over 200,000 members, but only admins can send messages in them."; +"lng_gigagroup_convert_title" = "Broadcast Groups"; +"lng_gigagroup_convert_feature1" = "No limit on the number of members."; +"lng_gigagroup_convert_feature2" = "Only admins can send messages."; +"lng_gigagroup_convert_feature3" = "Can't be turned back into a regular group."; +"lng_gigagroup_convert_sure" = "Convert"; +"lng_gigagroup_warning_title" = "Are you sure?"; +"lng_gigagroup_warning" = "Regular members of the group (non-admins) will **irrevocably** lose their right to post messages in the group.\n\nThis action **can't** be undone."; + "lng_rights_channel_info" = "Change channel info"; "lng_rights_channel_post" = "Post messages"; "lng_rights_channel_edit" = "Edit messages of others"; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 6684a390fe..5a4bbacdc0 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "data/data_chat.h" #include "ui/wrap/vertical_layout.h" +#include "ui/layers/generic_box.h" #include "ui/widgets/labels.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" @@ -22,7 +23,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/edit_participants_box.h" #include "boxes/peers/edit_peer_info_box.h" #include "window/window_session_controller.h" +#include "main/main_session.h" #include "mainwindow.h" +#include "apiwrap.h" #include "app.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -31,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { constexpr auto kSlowmodeValues = 7; +constexpr auto kSuggestGigagroupThreshold = 199000; int SlowmodeDelayByIndex(int index) { Expects(index >= 0 && index < kSlowmodeValues); @@ -369,6 +373,14 @@ void EditPeerPermissionsBox::prepare() { 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 { @@ -520,6 +532,93 @@ void EditPeerPermissionsBox::addSlowmodeLabels( } } +void EditPeerPermissionsBox::addSuggestGigagroup( + not_null container) { + container->add( + object_ptr( + container, + tr::lng_rights_gigagroup_title(), + st::rightsHeaderLabel), + st::rightsHeaderMargin); + const auto channel = _peer->asChannel(); + const auto converting = std::make_shared(); + const auto convertSure = [=] { + if (*converting) { + return; + } + *converting = true; + channel->session().api().request(MTPchannels_ConvertToGigagroup( + channel->inputChannel + )).done([=](const MTPUpdates &result) { + channel->session().api().applyUpdates(result); + Ui::hideLayer(); + }).fail([=](const RPCError &error) { + *converting = false; + }).send(); + }; + const auto convertWarn = [=] { + if (*converting) { + return; + } + getDelegate()->show(Box([=](not_null box) { + box->setTitle(tr::lng_gigagroup_warning_title()); + box->addRow( + object_ptr( + box, + tr::lng_gigagroup_warning(), + st::defaultFlatLabel), + style::margins( + st::boxRowPadding.left(), + st::boxLittleSkip, + st::boxRowPadding.right(), + st::boxLittleSkip)); + box->addButton(tr::lng_gigagroup_convert_sure(), convertSure); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); + })); + }; + const auto convert = [=] { + if (*converting) { + return; + } + getDelegate()->show(Box([=](not_null box) { + box->setTitle(tr::lng_gigagroup_convert_title()); + const auto addFeature = [&](rpl::producer text) { + box->addRow( + object_ptr( + box, + std::move(text), + st::defaultFlatLabel), + style::margins( + st::boxRowPadding.left(), + st::boxLittleSkip, + st::boxRowPadding.right(), + st::boxLittleSkip)); + }; + addFeature(tr::lng_gigagroup_convert_feature1()); + addFeature(tr::lng_gigagroup_convert_feature2()); + addFeature(tr::lng_gigagroup_convert_feature3()); + box->addButton(tr::lng_gigagroup_convert_sure(), convertWarn); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); + })); + }; + container->add(EditPeerInfoBox::CreateButton( + container, + tr::lng_rights_gigagroup_convert(), + rpl::single(QString()), + convert, + 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()) { diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h index b7dfd4ed07..a817ac3da7 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.h @@ -39,6 +39,7 @@ protected: 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;