From bfe873e91ce5e1de8fc74564d16bade513b16fcf Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 9 Jun 2022 08:19:11 +0300 Subject: [PATCH] Provided session controller to AddBotToGroupBoxController. --- .../boxes/peers/add_bot_to_chat_box.cpp | 39 +++++++++++++------ .../boxes/peers/add_bot_to_chat_box.h | 3 ++ .../boxes/peers/edit_participant_box.cpp | 1 + .../info/profile/info_profile_actions.cpp | 3 +- .../SourceFiles/window/window_peer_menu.cpp | 3 +- .../window/window_session_controller.cpp | 1 + 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp index 6509064f8..014c10036 100644 --- a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/random.h" #include "base/weak_ptr.h" #include "api/api_chat_participants.h" +#include "window/window_session_controller.h" #include "apiwrap.h" #include "facades.h" #include "styles/style_boxes.h" @@ -91,8 +92,6 @@ void ShareBotGame( ).send(); return history->sendRequestId; }); - Ui::hideLayer(); - Ui::showPeerHistory(chat, ShowAtUnreadMsgId); } Controller::Controller( @@ -144,6 +143,7 @@ void Controller::addRow(not_null peer) { } // namespace void AddBotToGroupBoxController::Start( + not_null controller, not_null bot, Scope scope, const QString &token, @@ -151,8 +151,9 @@ void AddBotToGroupBoxController::Start( auto initBox = [=](not_null box) { box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); }; - Ui::show(Box( + controller->show(Box( std::make_unique( + controller, bot, scope, token, @@ -161,6 +162,7 @@ void AddBotToGroupBoxController::Start( } AddBotToGroupBoxController::AddBotToGroupBoxController( + not_null controller, not_null bot, Scope scope, const QString &token, @@ -168,6 +170,7 @@ AddBotToGroupBoxController::AddBotToGroupBoxController( : ChatsListBoxController((scope == Scope::ShareGame) ? std::make_unique(&bot->session()) : nullptr) +, _controller(controller) , _bot(bot) , _scope(scope) , _token(token) @@ -192,8 +195,15 @@ void AddBotToGroupBoxController::rowClicked(not_null row) { } void AddBotToGroupBoxController::shareBotGame(not_null chat) { - auto send = crl::guard(this, [bot = _bot, chat, token = _token] { + auto send = crl::guard(this, [ + bot = _bot, + controller = _controller, + chat, + token = _token] { ShareBotGame(bot, chat, token); + using Way = Window::SectionShow::Way; + controller->hideLayer(); + controller->showPeerHistory(chat, Way::ClearStack, ShowAtUnreadMsgId); }); auto confirmText = [chat] { if (chat->isUser()) { @@ -201,7 +211,7 @@ void AddBotToGroupBoxController::shareBotGame(not_null chat) { } return tr::lng_bot_sure_share_game_group(tr::now, lt_group, chat->name); }(); - Ui::show( + _controller->show( Ui::MakeConfirmBox({ .text = confirmText, .confirmed = std::move(send), @@ -240,7 +250,7 @@ void AddBotToGroupBoxController::requestExistingRights( void AddBotToGroupBoxController::addBotToGroup(not_null chat) { if (const auto megagroup = chat->asMegagroup()) { if (!megagroup->canAddMembers()) { - Ui::show( + _controller->show( Ui::MakeInformBox(tr::lng_error_cant_add_member()), Ui::LayerOption::KeepOther); return; @@ -261,9 +271,11 @@ void AddBotToGroupBoxController::addBotToGroup(not_null chat) { return; } const auto bot = _bot; + const auto controller = _controller; const auto close = [=](auto&&...) { - Ui::hideLayer(); - Ui::showPeerHistory(chat, ShowAtUnreadMsgId); + using Way = Window::SectionShow::Way; + controller->hideLayer(); + controller->showPeerHistory(chat, Way::ClearStack, ShowAtUnreadMsgId); }; const auto rights = requestedAddAdmin ? _requestedRights @@ -300,12 +312,16 @@ void AddBotToGroupBoxController::addBotToGroup(not_null chat) { _token, _existingRights.value_or(ChatAdminRights()) }); box->setSaveCallback(saveCallback); - Ui::show(std::move(box), Ui::LayerOption::KeepOther); + controller->show(std::move(box), Ui::LayerOption::KeepOther); } else { - Ui::show( + auto callback = crl::guard(this, [=] { + AddBotToGroup(bot, chat, _token); + controller->hideLayer(); + }); + controller->show( Ui::MakeConfirmBox({ tr::lng_bot_sure_invite(tr::now, lt_group, chat->name), - crl::guard(this, [=] { AddBotToGroup(bot, chat, _token); }), + std::move(callback), }), Ui::LayerOption::KeepOther); } @@ -469,6 +485,5 @@ void AddBotToGroup( } else { chat->session().api().chatParticipants().add(chat, { 1, bot }); } - Ui::hideLayer(); Ui::showPeerHistory(chat, ShowAtUnreadMsgId); } diff --git a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.h b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.h index 51f6cbbfe..f048ee0bd 100644 --- a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.h +++ b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.h @@ -22,12 +22,14 @@ public: All, }; static void Start( + not_null controller, not_null bot, Scope scope = Scope::All, const QString &token = QString(), ChatAdminRights requestedRights = {}); AddBotToGroupBoxController( + not_null controller, not_null bot, Scope scope, const QString &token, @@ -56,6 +58,7 @@ private: void addBotToGroup(not_null chat); void requestExistingRights(not_null channel); + const not_null _controller; const not_null _bot; const Scope _scope = Scope::None; const QString _token; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index 342433935..bcf9c0efe 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -384,6 +384,7 @@ void EditAdminBox::prepare() { return; } else if (_addAsAdmin && !_addAsAdmin->checked()) { AddBotToGroup(user(), peer(), _addingBot->token); + getDelegate()->hideLayer(); return; } else if (_addingBot && !_addingBot->existing) { const auto phrase = peer()->isBroadcast() diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 7142389ad..7c09d1c63 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -554,11 +554,12 @@ void ActionsFiller::addInviteToGroupAction( const auto notEmpty = [](const QString &value) { return !value.isEmpty(); }; + const auto controller = _controller->parentController(); AddActionButton( _wrap, InviteToChatButton(user) | rpl::filter(notEmpty), InviteToChatButton(user) | rpl::map(notEmpty), - [=] { AddBotToGroupBoxController::Start(user); }, + [=] { AddBotToGroupBoxController::Start(controller, user); }, &st::infoIconAddMember); const auto about = _wrap->add( object_ptr>( diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index d2559ea57..bf984a69d 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -684,9 +684,10 @@ void Filler::addBotToGroup() { user ) | rpl::take(1) | rpl::start_with_next([=](QString label) { if (!label.isEmpty()) { + const auto controller = _controller; _addAction( label, - [=] { AddBotToGroupBoxController::Start(user); }, + [=] { AddBotToGroupBoxController::Start(controller, user); }, &st::menuIconInvite); } }); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index a19773f68..a86ac7660 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -335,6 +335,7 @@ void SessionNavigation::showPeerByLinkResolved( Assert(scope != Scope::None); AddBotToGroupBoxController::Start( + parentController(), bot, scope, info.startToken,