diff --git a/Telegram/SourceFiles/api/api_chat_participants.cpp b/Telegram/SourceFiles/api/api_chat_participants.cpp index 7195ee990..0c2fb2030 100644 --- a/Telegram/SourceFiles/api/api_chat_participants.cpp +++ b/Telegram/SourceFiles/api/api_chat_participants.cpp @@ -487,9 +487,9 @@ void ChatParticipants::requestCountDelayed( } void ChatParticipants::add( + std::shared_ptr show, not_null peer, const std::vector> &users, - std::shared_ptr show, bool passGroupHistory, Fn done) { if (const auto chat = peer->asChat()) { @@ -504,14 +504,14 @@ void ChatParticipants::add( if (done) done(true); }).fail([=](const MTP::Error &error) { const auto type = error.type(); - ShowAddParticipantsError(type, peer, { 1, user }, show); + ShowAddParticipantsError(show, type, peer, { 1, user }); if (done) done(false); }).afterDelay(kSmallDelayMs).send(); } } else if (const auto channel = peer->asChannel()) { const auto hasBot = ranges::any_of(users, &UserData::isBot); if (!peer->isMegagroup() && hasBot) { - ShowAddParticipantsError("USER_BOT", peer, users, show); + ShowAddParticipantsError(show, "USER_BOT", peer, users); return; } auto list = QVector(); @@ -531,7 +531,7 @@ void ChatParticipants::add( channel, CollectForbiddenUsers(&channel->session(), result)); }).fail([=](const MTP::Error &error) { - ShowAddParticipantsError(error.type(), peer, users, show); + ShowAddParticipantsError(show, error.type(), peer, users); if (callback) callback(false); }).afterDelay(kSmallDelayMs).send(); }; diff --git a/Telegram/SourceFiles/api/api_chat_participants.h b/Telegram/SourceFiles/api/api_chat_participants.h index 816cc6526..b8fc9fc67 100644 --- a/Telegram/SourceFiles/api/api_chat_participants.h +++ b/Telegram/SourceFiles/api/api_chat_participants.h @@ -97,9 +97,9 @@ public: not_null channel, const TLMembers &data); void add( + std::shared_ptr show, not_null peer, const std::vector> &users, - std::shared_ptr show = nullptr, bool passGroupHistory = true, Fn done = nullptr); diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index ef3b0f01f..09a307700 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3855,13 +3855,14 @@ void ApiWrap::sendMessage(MessageToSend &&message) { } void ApiWrap::sendBotStart( + std::shared_ptr show, not_null bot, PeerData *chat, const QString &startTokenForChat) { Expects(bot->isBot()); if (chat && chat->isChannel() && !chat->isMegagroup()) { - ShowAddParticipantsError("USER_BOT", chat, { 1, bot }); + ShowAddParticipantsError(show, "USER_BOT", chat, { 1, bot }); return; } @@ -3893,7 +3894,7 @@ void ApiWrap::sendBotStart( }).fail([=](const MTP::Error &error) { if (chat) { const auto type = error.type(); - ShowAddParticipantsError(type, chat, { 1, bot }); + ShowAddParticipantsError(show, type, chat, { 1, bot }); } }).send(); } diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 0d31126d3..b1c844702 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -53,6 +53,7 @@ class Key; namespace Ui { struct PreparedList; +class Show; } // namespace Ui namespace Api { @@ -343,6 +344,7 @@ public: BusinessShortcutId id); void sendMessage(MessageToSend &&message); void sendBotStart( + std::shared_ptr show, not_null bot, PeerData *chat = nullptr, const QString &startTokenForChat = QString()); diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index fc4c29a91..56e4f68a9 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -169,10 +169,10 @@ TextWithEntities PeerFloodErrorText( } void ShowAddParticipantsError( + std::shared_ptr show, const QString &error, not_null chat, - const std::vector> &users, - std::shared_ptr show) { + const std::vector> &users) { if (error == u"USER_BOT"_q) { const auto channel = chat->asChannel(); if ((users.size() == 1) @@ -189,6 +189,7 @@ void ShowAddParticipantsError( } }; const auto saveCallback = SaveAdminCallback( + show, channel, user, close, @@ -199,9 +200,10 @@ void ShowAddParticipantsError( ChatAdminRightsInfo(), QString()); box->setSaveCallback(saveCallback); - *weak = Ui::show(std::move(box)); + *weak = box.data(); + show->showBox(std::move(box)); }; - Ui::show( + show->showBox( Ui::MakeConfirmBox({ .text = tr::lng_cant_invite_offer_admin(), .confirmed = makeAdmin, @@ -219,7 +221,7 @@ void ShowAddParticipantsError( const auto text = PeerFloodErrorText(&chat->session(), type); Ui::show(Ui::MakeInformBox(text), Ui::LayerOption::KeepOther); return; - } else if (error == u"USER_PRIVACY_RESTRICTED"_q && show) { + } else if (error == u"USER_PRIVACY_RESTRICTED"_q) { ChatInviteForbidden(show, chat, users); return; } @@ -231,8 +233,6 @@ void ShowAddParticipantsError( } else if (error == u"USER_KICKED"_q) { // Trying to return a user who was kicked by admin. return tr::lng_cant_invite_banned(tr::now); - } else if (error == u"USER_PRIVACY_RESTRICTED"_q) { - return tr::lng_cant_invite_privacy(tr::now); } else if (error == u"USER_NOT_MUTUAL_CONTACT"_q) { // Trying to return user who does not have me in contacts. return tr::lng_failed_add_not_mutual(tr::now); @@ -247,7 +247,7 @@ void ShowAddParticipantsError( } return tr::lng_failed_add_participant(tr::now); }(); - Ui::show(Ui::MakeInformBox(text), Ui::LayerOption::KeepOther); + show->show(Ui::MakeInformBox(text), Ui::LayerOption::KeepOther); } AddContactBox::AddContactBox( diff --git a/Telegram/SourceFiles/boxes/add_contact_box.h b/Telegram/SourceFiles/boxes/add_contact_box.h index 6d19a2d7f..ed6adc655 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.h +++ b/Telegram/SourceFiles/boxes/add_contact_box.h @@ -34,6 +34,7 @@ template class Radioenum; class LinkButton; class UserpicButton; +class Show; } // namespace Ui enum class PeerFloodType { @@ -46,10 +47,10 @@ enum class PeerFloodType { not_null session, PeerFloodType type); void ShowAddParticipantsError( + std::shared_ptr show, const QString &error, not_null chat, - const std::vector> &users, - std::shared_ptr show = nullptr); + const std::vector> &users); class AddContactBox : public Ui::BoxContent { public: 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 1bffcb2ee..e5b659433 100644 --- a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp @@ -217,6 +217,7 @@ void AddBotToGroupBoxController::addBotToGroup(not_null chat) { ? bot->botInfo->groupAdminRights : ChatAdminRights(); const auto addingAdmin = requestedAddAdmin || (rights != 0); + const auto show = controller->uiShow(); if (addingAdmin) { const auto scope = _scope; const auto token = _token; @@ -224,11 +225,12 @@ void AddBotToGroupBoxController::addBotToGroup(not_null chat) { ChatAdminRightsInfo newRights, const QString &rank) { if (scope == Scope::GroupAdmin) { - chat->session().api().sendBotStart(bot, chat, token); + chat->session().api().sendBotStart(show, bot, chat, token); } close(); }; const auto saveCallback = SaveAdminCallback( + show, chat, bot, done, @@ -245,7 +247,7 @@ void AddBotToGroupBoxController::addBotToGroup(not_null chat) { controller->show(std::move(box)); } else { auto callback = crl::guard(this, [=] { - AddBotToGroup(bot, chat, _token); + AddBotToGroup(show, bot, chat, _token); controller->hideLayer(); }); controller->show(Ui::MakeConfirmBox({ @@ -394,13 +396,14 @@ void AddBotToGroupBoxController::prepareViewHook() { } void AddBotToGroup( + std::shared_ptr show, not_null bot, not_null chat, const QString &startToken) { if (!startToken.isEmpty()) { - chat->session().api().sendBotStart(bot, chat, startToken); + chat->session().api().sendBotStart(show, bot, chat, startToken); } else { - chat->session().api().chatParticipants().add(chat, { 1, bot }); + chat->session().api().chatParticipants().add(show, chat, { 1, bot }); } if (const auto window = chat->session().tryResolveWindow()) { window->showPeerHistory(chat); 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 1a129a4d8..350259a27 100644 --- a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.h +++ b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.h @@ -76,6 +76,7 @@ private: }; void AddBotToGroup( + std::shared_ptr show, not_null bot, not_null chat, const QString &startToken); diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 578bc77bc..1815c0db4 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -433,9 +433,9 @@ void AddParticipantsBoxController::inviteSelectedUsers( const auto show = box->uiShow(); const auto request = [=](bool checked) { _peer->session().api().chatParticipants().add( + show, _peer, users, - show, checked); }; if (_peer->isChannel()) { @@ -945,6 +945,7 @@ void AddSpecialBoxController::showAdmin( user, currentRights, _additional.adminRank(user)); + const auto show = delegate()->peerListUiShow(); if (_additional.canAddOrEditAdmin(user)) { const auto done = crl::guard(this, [=]( ChatAdminRightsInfo newRights, @@ -956,7 +957,8 @@ void AddSpecialBoxController::showAdmin( _editParticipantBox->closeBox(); } }); - box->setSaveCallback(SaveAdminCallback(_peer, user, done, fail)); + box->setSaveCallback( + SaveAdminCallback(show, _peer, user, done, fail)); } _editParticipantBox = showBox(std::move(box)); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index e5f4b4d1b..c1c086ad1 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -387,11 +387,12 @@ void EditAdminBox::prepare() { _rank ? _rank->getLastText().trimmed() : QString()); }; _save = [=] { + const auto show = uiShow(); if (!_saveCallback) { return; } else if (_addAsAdmin && !_addAsAdmin->checked()) { const auto weak = Ui::MakeWeak(this); - AddBotToGroup(user(), peer(), _addingBot->token); + AddBotToGroup(show, user(), peer(), _addingBot->token); if (const auto strong = weak.data()) { strong->closeBox(); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index a3faa5711..e627306a6 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -72,6 +72,7 @@ void RemoveAdmin( } void AddChatParticipant( + std::shared_ptr show, not_null chat, not_null user, Fn onDone, @@ -87,7 +88,7 @@ void AddChatParticipant( onDone(); } }).fail([=](const MTP::Error &error) { - ShowAddParticipantsError(error.type(), chat, { 1, user }); + ShowAddParticipantsError(show, error.type(), chat, { 1, user }); if (onFail) { onFail(); } @@ -95,6 +96,7 @@ void AddChatParticipant( } void SaveChatAdmin( + std::shared_ptr show, not_null chat, not_null user, bool isAdmin, @@ -115,8 +117,15 @@ void SaveChatAdmin( if (retryOnNotParticipant && isAdmin && (type == u"USER_NOT_PARTICIPANT"_q)) { - AddChatParticipant(chat, user, [=] { - SaveChatAdmin(chat, user, isAdmin, onDone, onFail, false); + AddChatParticipant(show, chat, user, [=] { + SaveChatAdmin( + show, + chat, + user, + isAdmin, + onDone, + onFail, + false); }, onFail); } else if (onFail) { onFail(); @@ -125,6 +134,7 @@ void SaveChatAdmin( } void SaveChannelAdmin( + std::shared_ptr show, not_null channel, not_null user, ChatAdminRightsInfo oldRights, @@ -145,7 +155,7 @@ void SaveChannelAdmin( onDone(); } }).fail([=](const MTP::Error &error) { - ShowAddParticipantsError(error.type(), channel, { 1, user }); + ShowAddParticipantsError(show, error.type(), channel, { 1, user }); if (onFail) { onFail(); } @@ -206,6 +216,7 @@ Fn SaveAdminCallback( + std::shared_ptr show, not_null peer, not_null user, Fn channel) { SaveChannelAdmin( + show, channel, user, oldRights, @@ -229,7 +241,7 @@ FnasChatNotMigrated()) { const auto saveChatAdmin = [&](bool isAdmin) { - SaveChatAdmin(chat, user, isAdmin, done, onFail); + SaveChatAdmin(show, chat, user, isAdmin, done, onFail); }; if (newRights.flags == chat->defaultAdminRights(user).flags && rank.isEmpty()) { @@ -1743,7 +1755,9 @@ void ParticipantsBoxController::showAdmin(not_null user) { _editParticipantBox->closeBox(); } }); - box->setSaveCallback(SaveAdminCallback(_peer, user, done, fail)); + const auto show = delegate()->peerListUiShow(); + box->setSaveCallback( + SaveAdminCallback(show, _peer, user, done, fail)); } _editParticipantBox = showBox(std::move(box)); } @@ -1863,7 +1877,8 @@ void ParticipantsBoxController::unkickParticipant(not_null user) { delegate()->peerListRemoveRow(row); refreshRows(); } - _peer->session().api().chatParticipants().add(_peer, { 1, user }); + const auto show = delegate()->peerListUiShow(); + _peer->session().api().chatParticipants().add(show, _peer, { 1, user }); } void ParticipantsBoxController::kickParticipantSure( @@ -1906,7 +1921,8 @@ void ParticipantsBoxController::removeAdminSure(not_null user) { _editBox = nullptr; if (const auto chat = _peer->asChat()) { - SaveChatAdmin(chat, user, false, crl::guard(this, [=] { + const auto show = delegate()->peerListUiShow(); + SaveChatAdmin(show, chat, user, false, crl::guard(this, [=] { editAdminDone( user, ChatAdminRightsInfo(), diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h index d43d99e27..c9550232d 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h @@ -17,6 +17,10 @@ class PeerListStories; struct ChatAdminRightsInfo; struct ChatRestrictionsInfo; +namespace Ui { +class Show; +} // namespace Ui + namespace Window { class SessionNavigation; } // namespace Window @@ -29,6 +33,7 @@ Fn SaveAdminCallback( + std::shared_ptr show, not_null peer, not_null user, Fnowner().peerLoaded( peerFromMTP(result.data().vpeer())); if (const auto bot = botPeer ? botPeer->asUser() : nullptr) { - _peer->session().api().sendBotStart(bot, bot, command); + const auto show = controller->uiShow(); + _peer->session().api().sendBotStart(show, bot, bot, command); controller->showPeerHistory(bot); } }).send(); diff --git a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp index 6259bcd94..bb8c90855 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp @@ -225,9 +225,9 @@ object_ptr PrepareInviteBox( const std::vector> &nonMembers, Fn finish) { peer->session().api().chatParticipants().add( + show, peer, nonMembers, - show, true, [=](bool) { invite(users); finish(); }); }; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index cec389eb8..79994f61f 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -4224,7 +4224,8 @@ SendMenu::Type HistoryWidget::sendButtonMenuType() const { void HistoryWidget::unblockUser() { if (const auto user = _peer ? _peer->asUser() : nullptr) { - Window::PeerMenuUnblockUserWithBotRestart(user); + const auto show = controller()->uiShow(); + Window::PeerMenuUnblockUserWithBotRestart(show, user); } else { updateControlsVisibility(); } @@ -4238,7 +4239,7 @@ void HistoryWidget::sendBotStartCommand() { updateControlsVisibility(); return; } - session().api().sendBotStart(_peer->asUser()); + session().api().sendBotStart(controller()->uiShow(), _peer->asUser()); updateControlsVisibility(); updateControlsGeometry(); } diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 37863f5a5..adba93d89 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -1688,7 +1688,8 @@ void ActionsFiller::addBlockAction(not_null user) { }); auto callback = [=] { if (user->isBlocked()) { - Window::PeerMenuUnblockUserWithBotRestart(user); + const auto show = controller->uiShow(); + Window::PeerMenuUnblockUserWithBotRestart(show, user); if (user->isBot()) { controller->showPeerHistory(user); } diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 924f0de8b..d625b739b 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -781,8 +781,9 @@ void Filler::addBlockUser() { : tr::lng_profile_block_user(tr::now)); }; const auto blockAction = _addAction(blockText(user), [=] { + const auto show = window->uiShow(); if (user->isBlocked()) { - PeerMenuUnblockUserWithBotRestart(user); + PeerMenuUnblockUserWithBotRestart(show, user); } else if (user->isBot()) { user->session().api().blockedPeers().block(user); } else { @@ -1700,10 +1701,12 @@ void PeerMenuBlockUserBox( }); } -void PeerMenuUnblockUserWithBotRestart(not_null user) { +void PeerMenuUnblockUserWithBotRestart( + std::shared_ptr show, + not_null user) { user->session().api().blockedPeers().unblock(user, [=](bool success) { if (success && user->isBot() && !user->isSupport()) { - user->session().api().sendBotStart(user); + user->session().api().sendBotStart(show, user); } }); } diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index 44503042b..cc4f56178 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -18,6 +18,7 @@ namespace Ui { class RpWidget; class BoxContent; class GenericBox; +class Show; } // namespace Ui namespace Data { @@ -109,7 +110,9 @@ void PeerMenuBlockUserBox( not_null peer, std::variant suggestReport, std::variant suggestClear); -void PeerMenuUnblockUserWithBotRestart(not_null user); +void PeerMenuUnblockUserWithBotRestart( + std::shared_ptr show, + not_null user); void BlockSenderFromRepliesBox( not_null box,