mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-21 15:47:38 +00:00
Add convert to gigagroup button.
This commit is contained in:
parent
6511d0dfcf
commit
56b15b26bb
@ -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";
|
||||
|
@ -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<Ui::VerticalLayout*> container) {
|
||||
container->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_rights_gigagroup_title(),
|
||||
st::rightsHeaderLabel),
|
||||
st::rightsHeaderMargin);
|
||||
const auto channel = _peer->asChannel();
|
||||
const auto converting = std::make_shared<bool>();
|
||||
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<Ui::GenericBox*> box) {
|
||||
box->setTitle(tr::lng_gigagroup_warning_title());
|
||||
box->addRow(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
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<Ui::GenericBox*> box) {
|
||||
box->setTitle(tr::lng_gigagroup_convert_title());
|
||||
const auto addFeature = [&](rpl::producer<QString> text) {
|
||||
box->addRow(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
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<Ui::DividerLabel>(
|
||||
container,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_rights_gigagroup_about(),
|
||||
st::boxDividerLabel),
|
||||
st::proxyAboutPadding),
|
||||
style::margins(0, st::infoProfileSkip, 0, st::infoProfileSkip));
|
||||
}
|
||||
|
||||
void EditPeerPermissionsBox::addBannedButtons(
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
if (const auto chat = _peer->asChat()) {
|
||||
|
@ -39,6 +39,7 @@ protected:
|
||||
private:
|
||||
Fn<int()> addSlowmodeSlider(not_null<Ui::VerticalLayout*> container);
|
||||
void addSlowmodeLabels(not_null<Ui::VerticalLayout*> container);
|
||||
void addSuggestGigagroup(not_null<Ui::VerticalLayout*> container);
|
||||
void addBannedButtons(not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
const not_null<Window::SessionNavigation*> _navigation;
|
||||
|
Loading…
Reference in New Issue
Block a user