Suggest converting to gigagroup.

This commit is contained in:
John Preston 2021-02-19 17:53:20 +04:00
parent 47d2ecf629
commit 221b896117
9 changed files with 134 additions and 63 deletions

View File

@ -2031,6 +2031,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"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_gigagroup_done" = "Your group can now have more than 200,000 members.";
"lng_gigagroup_suggest_title" = "Limit reached";
"lng_gigagroup_suggest_text" = "Your group has reached a limit of **200,000** members.\n\nYou can increase this limit by converting the group to a **broadcast group** where only admins can post. Interested?";
"lng_gigagroup_suggest_more" = "Learn more";
"lng_rights_channel_info" = "Change channel info";
"lng_rights_channel_post" = "Post messages";

View File

@ -314,6 +314,68 @@ ChatAdminRights AdminRightsForOwnershipTransfer(bool isGroup) {
return result;
}
Fn<void()> AboutGigagroupCallback(not_null<ChannelData*> channel) {
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::hideSettingsAndLayer();
Ui::Toast::Show(tr::lng_gigagroup_done(tr::now));
}).fail([=](const RPCError &error) {
*converting = false;
}).send();
};
const auto convertWarn = [=] {
if (*converting) {
return;
}
Ui::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(
) | Ui::Text::ToRichLangValue(),
st::infoAboutGigagroup));
box->addButton(tr::lng_gigagroup_convert_sure(), convertSure);
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
}), Ui::LayerOption::KeepOther);
};
return [=] {
if (*converting) {
return;
}
Ui::show(Box([=](not_null<Ui::GenericBox*> box) {
box->setTitle(tr::lng_gigagroup_convert_title());
const auto addFeature = [&](rpl::producer<QString> text) {
using namespace rpl::mappers;
const auto prefix = QString::fromUtf8("\xE2\x80\xA2 ");
box->addRow(
object_ptr<Ui::FlatLabel>(
box,
std::move(text) | rpl::map(prefix + _1),
st::infoAboutGigagroup),
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(); });
}), Ui::LayerOption::KeepOther);
};
}
EditPeerPermissionsBox::EditPeerPermissionsBox(
QWidget*,
not_null<Window::SessionNavigation*> navigation,
@ -541,71 +603,11 @@ void EditPeerPermissionsBox::addSuggestGigagroup(
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::hideSettingsAndLayer();
Ui::Toast::Show(tr::lng_gigagroup_done(tr::now));
}).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(
) | Ui::Text::ToRichLangValue(),
st::infoAboutGigagroup));
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) {
using namespace rpl::mappers;
const auto prefix = QString::fromUtf8("\xE2\x80\xA2 ");
box->addRow(
object_ptr<Ui::FlatLabel>(
box,
std::move(text) | rpl::map(prefix + _1),
st::infoAboutGigagroup),
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,
AboutGigagroupCallback(_peer->asChannel()),
st::peerPermissionsButton));
container->add(

View File

@ -49,6 +49,9 @@ private:
};
[[nodiscard]] Fn<void()> AboutGigagroupCallback(
not_null<ChannelData*> channel);
template <typename Flags>
struct EditFlagsControl {
object_ptr<Ui::RpWidget> widget;

View File

@ -739,6 +739,16 @@ void ApplyChannelUpdate(
const MTPDchannelFull &update) {
const auto session = &channel->session();
if (channel->isMegagroup()) {
const auto suggestions = update.vpending_suggestions().value_or_empty();
channel->owner().setSuggestToGigagroup(
channel,
ranges::contains(
suggestions,
"convert_to_gigagroup"_q,
&MTPstring::v));
}
channel->setAvailableMinId(update.vavailable_min_id().value_or_empty());
auto canViewAdmins = channel->canViewAdmins();
auto canViewMembers = channel->canViewMembers();

View File

@ -65,8 +65,8 @@ void Groups::unregisterMessage(not_null<const HistoryItem*> item) {
}
void Groups::refreshMessage(
not_null<HistoryItem*> item,
bool justRefreshViews) {
not_null<HistoryItem*> item,
bool justRefreshViews) {
if (!isGrouped(item)) {
unregisterMessage(item);
return;

View File

@ -2049,6 +2049,20 @@ MsgId Session::nextLocalMessageId() {
return _localMessageIdCounter++;
}
void Session::setSuggestToGigagroup(
not_null<ChannelData*> group,
bool suggest) {
if (suggest) {
_suggestToGigagroup.emplace(group);
} else {
_suggestToGigagroup.remove(group);
}
}
bool Session::suggestToGigagroup(not_null<ChannelData*> group) const {
return _suggestToGigagroup.contains(group);
}
HistoryItem *Session::message(ChannelId channelId, MsgId itemId) const {
if (!itemId) {
return nullptr;

View File

@ -327,6 +327,10 @@ public:
const Dialogs::Key &key1,
const Dialogs::Key &key2);
void setSuggestToGigagroup(not_null<ChannelData*> group, bool suggest);
[[nodiscard]] bool suggestToGigagroup(
not_null<ChannelData*> group) const;
void registerMessage(not_null<HistoryItem*> item);
void unregisterMessage(not_null<HistoryItem*> item);
@ -930,6 +934,7 @@ private:
rpl::event_stream<not_null<WebPageData*>> _webpageUpdates;
rpl::event_stream<not_null<ChannelData*>> _channelDifferenceTooLong;
base::flat_set<not_null<ChannelData*>> _suggestToGigagroup;
base::flat_multi_map<TimeId, not_null<PollData*>> _pollsClosings;
base::Timer _pollsClosingTimer;

View File

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/send_files_box.h"
#include "boxes/share_box.h"
#include "boxes/edit_caption_box.h"
#include "boxes/peers/edit_peer_permissions_box.h" // ShowAboutGigagroup.
#include "core/file_utilities.h"
#include "ui/toast/toast.h"
#include "ui/toasts/common_toasts.h"
@ -3446,6 +3447,36 @@ void HistoryWidget::doneShow() {
checkHistoryActivation();
controller()->widget()->setInnerFocus();
_preserveScrollTop = false;
checkSuggestToGigagroup();
}
void HistoryWidget::checkSuggestToGigagroup() {
const auto group = _peer ? _peer->asMegagroup() : nullptr;
if (!group || !group->owner().suggestToGigagroup(group)) {
return;
}
InvokeQueued(_list, [=] {
if (!Ui::isLayerShown()) {
group->owner().setSuggestToGigagroup(group, false);
group->session().api().request(MTPhelp_DismissSuggestion(
group->input,
MTP_string("convert_to_gigagroup")
)).send();
Ui::show(Box([=](not_null<Ui::GenericBox*> box) {
box->setTitle(tr::lng_gigagroup_suggest_title());
box->addRow(
object_ptr<Ui::FlatLabel>(
box,
tr::lng_gigagroup_suggest_text(
) | Ui::Text::ToRichLangValue(),
st::infoAboutGigagroup));
box->addButton(
tr::lng_gigagroup_suggest_more(),
AboutGigagroupCallback(group));
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
}));
}
});
}
void HistoryWidget::finishAnimating() {
@ -6183,6 +6214,7 @@ void HistoryWidget::fullPeerUpdated(PeerData *peer) {
_list->updateBotInfo();
handlePeerUpdate();
checkSuggestToGigagroup();
}
if (updateCmdStartShown()) {
refresh = true;

View File

@ -330,6 +330,8 @@ private:
using TextUpdateEvents = base::flags<TextUpdateEvent>;
friend inline constexpr bool is_flag_type(TextUpdateEvent) { return true; };
void checkSuggestToGigagroup();
void initTabbedSelector();
void initVoiceRecordBar();
void refreshTabbedPanel();