Removed Ui::show from AddParticipants and AddSpecial box controllers.

This commit is contained in:
23rd 2022-03-03 10:22:26 +03:00
parent 093d2ae99b
commit cacbc60302
2 changed files with 53 additions and 58 deletions

View file

@ -26,12 +26,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unixtime.h" #include "base/unixtime.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "mtproto/mtproto_config.h" #include "mtproto/mtproto_config.h"
#include "mainwidget.h"
#include "mainwindow.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "info/profile/info_profile_icon.h" #include "info/profile/info_profile_icon.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "facades.h" // Ui::showPeerHistory
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
namespace { namespace {
@ -100,15 +97,11 @@ void AddParticipantsBoxController::rowClicked(not_null<PeerListRow*> row) {
updateTitle(); updateTitle();
} else if (const auto channel = _peer ? _peer->asChannel() : nullptr) { } else if (const auto channel = _peer ? _peer->asChannel() : nullptr) {
if (!_peer->isMegagroup()) { if (!_peer->isMegagroup()) {
Ui::show( showBox(Box<MaxInviteBox>(_peer->asChannel()));
Box<MaxInviteBox>(_peer->asChannel()),
Ui::LayerOption::KeepOther);
} }
} else if (count >= serverConfig.chatSizeMax } else if (count >= serverConfig.chatSizeMax
&& count < serverConfig.megagroupSizeMax) { && count < serverConfig.megagroupSizeMax) {
Ui::show( showBox(Ui::MakeInformBox(tr::lng_profile_add_more_after_create()));
Ui::MakeInformBox(tr::lng_profile_add_more_after_create()),
Ui::LayerOption::KeepOther);
} }
} }
@ -188,6 +181,13 @@ bool AddParticipantsBoxController::needsInviteLinkButton() {
return _peer->asChat()->canHaveInviteLink(); return _peer->asChat()->canHaveInviteLink();
} }
QPointer<Ui::BoxContent> AddParticipantsBoxController::showBox(
object_ptr<Ui::BoxContent> box) const {
const auto weak = Ui::MakeWeak(box.data());
delegate()->peerListShowBox(std::move(box), Ui::LayerOption::KeepOther);
return weak;
}
void AddParticipantsBoxController::addInviteLinkButton() { void AddParticipantsBoxController::addInviteLinkButton() {
if (!needsInviteLinkButton()) { if (!needsInviteLinkButton()) {
return; return;
@ -204,7 +204,7 @@ void AddParticipantsBoxController::addInviteLinkButton() {
st::inviteViaLinkIcon, st::inviteViaLinkIcon,
st::inviteViaLinkIconPosition); st::inviteViaLinkIconPosition);
button->entity()->setClickedCallback([=] { button->entity()->setClickedCallback([=] {
Ui::show(Box<EditPeerTypeBox>(_peer), Ui::LayerOption::KeepOther); showBox(Box<EditPeerTypeBox>(_peer));
}); });
button->entity()->events( button->entity()->events(
) | rpl::filter([=](not_null<QEvent*> e) { ) | rpl::filter([=](not_null<QEvent*> e) {
@ -243,15 +243,16 @@ void AddParticipantsBoxController::Start(
auto initBox = [=](not_null<PeerListBox*> box) { auto initBox = [=](not_null<PeerListBox*> box) {
box->addButton(tr::lng_participant_invite(), [=] { box->addButton(tr::lng_participant_invite(), [=] {
if (weak->inviteSelectedUsers(box)) { if (weak->inviteSelectedUsers(box)) {
Ui::showPeerHistory(chat, ShowAtTheEndMsgId); navigation->parentController()->showPeerHistory(
chat,
Window::SectionShow::Way::ClearStack,
ShowAtTheEndMsgId);
} }
}); });
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
}; };
Ui::show( Window::Show(navigation).showBox(
Box<PeerListBox>( Box<PeerListBox>(std::move(controller), std::move(initBox)),
std::move(controller),
std::move(initBox)),
Ui::LayerOption::KeepOther); Ui::LayerOption::KeepOther);
} }
@ -268,7 +269,10 @@ void AddParticipantsBoxController::Start(
box->addButton(tr::lng_participant_invite(), [=] { box->addButton(tr::lng_participant_invite(), [=] {
if (weak->inviteSelectedUsers(box)) { if (weak->inviteSelectedUsers(box)) {
if (channel->isMegagroup()) { if (channel->isMegagroup()) {
Ui::showPeerHistory(channel, ShowAtTheEndMsgId); navigation->parentController()->showPeerHistory(
channel,
Window::SectionShow::Way::ClearStack,
ShowAtTheEndMsgId);
} else { } else {
box->closeBox(); box->closeBox();
} }
@ -288,10 +292,8 @@ void AddParticipantsBoxController::Start(
}, box->lifetime()); }, box->lifetime());
} }
}; };
Ui::show( Window::Show(navigation).showBox(
Box<PeerListBox>( Box<PeerListBox>(std::move(controller), std::move(initBox)),
std::move(controller),
std::move(initBox)),
Ui::LayerOption::KeepOther); Ui::LayerOption::KeepOther);
} }
@ -347,6 +349,13 @@ void AddSpecialBoxController::migrate(
_additional.migrate(chat, channel); _additional.migrate(chat, channel);
} }
QPointer<Ui::BoxContent> AddSpecialBoxController::showBox(
object_ptr<Ui::BoxContent> box) const {
const auto weak = Ui::MakeWeak(box.data());
delegate()->peerListShowBox(std::move(box), Ui::LayerOption::KeepOther);
return weak;
}
std::unique_ptr<PeerListRow> AddSpecialBoxController::createSearchRow( std::unique_ptr<PeerListRow> AddSpecialBoxController::createSearchRow(
not_null<PeerData*> peer) { not_null<PeerData*> peer) {
if (_excludeSelf && peer->isSelf()) { if (_excludeSelf && peer->isSelf()) {
@ -568,42 +577,35 @@ void AddSpecialBoxController::showAdmin(
if (canAddMembers) { if (canAddMembers) {
if (canBanMembers) { if (canBanMembers) {
if (!sure) { if (!sure) {
_editBox = Ui::show( _editBox = showBox(
Ui::MakeConfirmBox({ Ui::MakeConfirmBox({
tr::lng_sure_add_admin_unremove(), tr::lng_sure_add_admin_unremove(),
showAdminSure showAdminSure
}), }));
Ui::LayerOption::KeepOther);
return; return;
} }
} else { } else {
Ui::show( showBox(
Ui::MakeInformBox(tr::lng_error_cant_add_admin_unban()), Ui::MakeInformBox(tr::lng_error_cant_add_admin_unban()));
Ui::LayerOption::KeepOther);
return; return;
} }
} else { } else {
Ui::show( showBox(Ui::MakeInformBox(tr::lng_error_cant_add_admin_invite()));
Ui::MakeInformBox(tr::lng_error_cant_add_admin_invite()),
Ui::LayerOption::KeepOther);
return; return;
} }
} else if (_additional.restrictedRights(user).has_value()) { } else if (_additional.restrictedRights(user).has_value()) {
// The user is restricted. // The user is restricted.
if (canBanMembers) { if (canBanMembers) {
if (!sure) { if (!sure) {
_editBox = Ui::show( _editBox = showBox(
Ui::MakeConfirmBox({ Ui::MakeConfirmBox({
tr::lng_sure_add_admin_unremove(), tr::lng_sure_add_admin_unremove(),
showAdminSure showAdminSure
}), }));
Ui::LayerOption::KeepOther);
return; return;
} }
} else { } else {
Ui::show( showBox(Ui::MakeInformBox(tr::lng_error_cant_add_admin_unban()));
Ui::MakeInformBox(tr::lng_error_cant_add_admin_unban()),
Ui::LayerOption::KeepOther);
return; return;
} }
} else if (_additional.isExternal(user)) { } else if (_additional.isExternal(user)) {
@ -613,18 +615,15 @@ void AddSpecialBoxController::showAdmin(
auto text = ((_peer->isChat() || _peer->isMegagroup()) auto text = ((_peer->isChat() || _peer->isMegagroup())
? tr::lng_sure_add_admin_invite ? tr::lng_sure_add_admin_invite
: tr::lng_sure_add_admin_invite_channel)(); : tr::lng_sure_add_admin_invite_channel)();
_editBox = Ui::show( _editBox = showBox(
Ui::MakeConfirmBox({ Ui::MakeConfirmBox({
std::move(text), std::move(text),
showAdminSure showAdminSure
}), }));
Ui::LayerOption::KeepOther);
return; return;
} }
} else { } else {
Ui::show( showBox(Ui::MakeInformBox(tr::lng_error_cant_add_admin_invite()));
Ui::MakeInformBox(tr::lng_error_cant_add_admin_invite()),
Ui::LayerOption::KeepOther);
return; return;
} }
} }
@ -651,7 +650,7 @@ void AddSpecialBoxController::showAdmin(
}); });
box->setSaveCallback(SaveAdminCallback(_peer, user, done, fail)); box->setSaveCallback(SaveAdminCallback(_peer, user, done, fail));
} }
_editParticipantBox = Ui::show(std::move(box), Ui::LayerOption::KeepOther); _editParticipantBox = showBox(std::move(box));
} }
void AddSpecialBoxController::editAdminDone( void AddSpecialBoxController::editAdminDone(
@ -692,18 +691,15 @@ void AddSpecialBoxController::showRestricted(
// The user is an admin or creator. // The user is an admin or creator.
if (!_additional.isCreator(user) && _additional.canEditAdmin(user)) { if (!_additional.isCreator(user) && _additional.canEditAdmin(user)) {
if (!sure) { if (!sure) {
_editBox = Ui::show( _editBox = showBox(
Ui::MakeConfirmBox({ Ui::MakeConfirmBox({
tr::lng_sure_ban_admin(), tr::lng_sure_ban_admin(),
showRestrictedSure showRestrictedSure
}), }));
Ui::LayerOption::KeepOther);
return; return;
} }
} else { } else {
Ui::show( showBox(Ui::MakeInformBox(tr::lng_error_cant_ban_admin()));
Ui::MakeInformBox(tr::lng_error_cant_ban_admin()),
Ui::LayerOption::KeepOther);
return; return;
} }
} }
@ -730,7 +726,7 @@ void AddSpecialBoxController::showRestricted(
box->setSaveCallback( box->setSaveCallback(
SaveRestrictedCallback(_peer, user, done, fail)); SaveRestrictedCallback(_peer, user, done, fail));
} }
_editParticipantBox = Ui::show(std::move(box), Ui::LayerOption::KeepOther); _editParticipantBox = showBox(std::move(box));
} }
void AddSpecialBoxController::editRestrictedDone( void AddSpecialBoxController::editRestrictedDone(
@ -764,18 +760,15 @@ void AddSpecialBoxController::kickUser(
// The user is an admin or creator. // The user is an admin or creator.
if (!_additional.isCreator(user) && _additional.canEditAdmin(user)) { if (!_additional.isCreator(user) && _additional.canEditAdmin(user)) {
if (!sure) { if (!sure) {
_editBox = Ui::show( _editBox = showBox(
Ui::MakeConfirmBox({ Ui::MakeConfirmBox({
tr::lng_sure_ban_admin(), tr::lng_sure_ban_admin(),
kickUserSure kickUserSure
}), }));
Ui::LayerOption::KeepOther);
return; return;
} }
} else { } else {
Ui::show( showBox(Ui::MakeInformBox(tr::lng_error_cant_ban_admin()));
Ui::MakeInformBox(tr::lng_error_cant_ban_admin()),
Ui::LayerOption::KeepOther);
return; return;
} }
} }
@ -788,9 +781,7 @@ void AddSpecialBoxController::kickUser(
tr::now, tr::now,
lt_user, lt_user,
participant->name); participant->name);
_editBox = Ui::show( _editBox = showBox(Ui::MakeConfirmBox({ text, kickUserSure }));
Ui::MakeConfirmBox({ text, kickUserSure }),
Ui::LayerOption::KeepOther);
return; return;
} }

View file

@ -56,6 +56,8 @@ private:
base::flat_set<not_null<UserData*>> &&alreadyIn, base::flat_set<not_null<UserData*>> &&alreadyIn,
bool justCreated); bool justCreated);
QPointer<Ui::BoxContent> showBox(object_ptr<Ui::BoxContent> box) const;
void addInviteLinkButton(); void addInviteLinkButton();
bool inviteSelectedUsers(not_null<PeerListBox*> box) const; bool inviteSelectedUsers(not_null<PeerListBox*> box) const;
void subscribeToMigration(); void subscribeToMigration();
@ -126,6 +128,8 @@ private:
void subscribeToMigration(); void subscribeToMigration();
void migrate(not_null<ChatData*> chat, not_null<ChannelData*> channel); void migrate(not_null<ChatData*> chat, not_null<ChannelData*> channel);
QPointer<Ui::BoxContent> showBox(object_ptr<Ui::BoxContent> box) const;
not_null<PeerData*> _peer; not_null<PeerData*> _peer;
MTP::Sender _api; MTP::Sender _api;
Role _role = Role::Admins; Role _role = Role::Admins;