diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index df32f7241d..9cb0a8f54e 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -40,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL //#include "history/feed/history_feed_section.h" // #feed #include "storage/localstorage.h" #include "main/main_session.h" +#include "main/main_account.h" #include "boxes/confirm_box.h" #include "boxes/stickers_box.h" #include "boxes/sticker_set_box.h" @@ -222,7 +223,8 @@ bool ApiWrap::BlockedUsersSlice::operator!=(const BlockedUsersSlice &other) cons } ApiWrap::ApiWrap(not_null session) -: _session(session) +: MTP::Sender(session->account().mtp()) +, _session(session) , _messageDataResolveDelayed([=] { resolveMessageDatas(); }) , _webPagesTimer([=] { resolveWebPages(); }) , _draftsSaveTimer([=] { saveDraftsToCloud(); }) diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index ed831de5f8..06e10fc374 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -203,7 +203,7 @@ void ShowAddParticipantsError( Ui::show(Box(text), Ui::LayerOption::KeepOther); } -class RevokePublicLinkBox::Inner : public TWidget, private MTP::Sender { +class RevokePublicLinkBox::Inner : public TWidget { public: Inner( QWidget *parent, @@ -228,6 +228,7 @@ private: void updateSelected(); const not_null _session; + MTP::Sender _api; PeerData *_selected = nullptr; PeerData *_pressed = nullptr; @@ -450,6 +451,7 @@ GroupInfoBox::GroupInfoBox( const QString &title, Fn)> channelDone) : _navigation(navigation) +, _api(_navigation->session().api().instance()) , _type(type) , _initialTitle(title) , _channelDone(std::move(channelDone)) { @@ -569,7 +571,7 @@ void GroupInfoBox::createGroup( if (inputs.empty()) { return; } - _creationRequestId = request(MTPmessages_CreateChat( + _creationRequestId = _api.request(MTPmessages_CreateChat( MTP_vector(inputs), MTP_string(title) )).done([=](const MTPUpdates &result) { @@ -645,7 +647,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio const auto flags = (_type == Type::Megagroup) ? MTPchannels_CreateChannel::Flag::f_megagroup : MTPchannels_CreateChannel::Flag::f_broadcast; - _creationRequestId = request(MTPchannels_CreateChannel( + _creationRequestId = _api.request(MTPchannels_CreateChannel( MTP_flags(flags), MTP_string(title), MTP_string(description), @@ -682,7 +684,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio std::move(image)); } _createdChannel = channel; - _creationRequestId = request(MTPmessages_ExportChatInvite( + _creationRequestId = _api.request(MTPmessages_ExportChatInvite( _createdChannel->input )).done([=](const MTPExportedChatInvite &result) { _creationRequestId = 0; @@ -1287,6 +1289,7 @@ RevokePublicLinkBox::Inner::Inner( Fn revokeCallback) : TWidget(parent) , _session(session) +, _api(_session->api().instance()) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) , _revokeWidth(st::normalFont->width(tr::lng_channels_too_much_public_revoke(tr::now))) , _revokeCallback(std::move(revokeCallback)) { @@ -1294,7 +1297,7 @@ RevokePublicLinkBox::Inner::Inner( resize(width(), 5 * _rowHeight); - request(MTPchannels_GetAdminedPublicChannels( + _api.request(MTPchannels_GetAdminedPublicChannels( MTP_flags(0) )).done([=](const MTPmessages_Chats &result) { const auto &chats = result.match([](const auto &data) { @@ -1401,7 +1404,7 @@ void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) { auto confirmText = tr::lng_channels_too_much_public_revoke(tr::now); _weakRevokeConfirmBox = Ui::show(Box(text, confirmText, crl::guard(this, [this, pressed]() { if (_revokeRequestId) return; - _revokeRequestId = request(MTPchannels_UpdateUsername( + _revokeRequestId = _api.request(MTPchannels_UpdateUsername( pressed->asChannel()->inputChannel, MTP_string() )).done([=](const MTPBool &result) { diff --git a/Telegram/SourceFiles/boxes/add_contact_box.h b/Telegram/SourceFiles/boxes/add_contact_box.h index e97eff55e8..488893da82 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.h +++ b/Telegram/SourceFiles/boxes/add_contact_box.h @@ -94,7 +94,7 @@ private: }; -class GroupInfoBox : public Ui::BoxContent, private MTP::Sender { +class GroupInfoBox : public Ui::BoxContent { public: enum class Type { Group, @@ -124,6 +124,7 @@ private: void updateMaxHeight(); const not_null _navigation; + MTP::Sender _api; Type _type = Type::Group; QString _initialTitle; diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index 9d91c177af..f69aac5dba 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -53,10 +53,7 @@ QImage TakeMiddleSample(QImage original, QSize size) { } // namespace -class BackgroundBox::Inner - : public Ui::RpWidget - , private MTP::Sender - , private base::Subscriber { +class BackgroundBox::Inner : public Ui::RpWidget, private base::Subscriber { public: Inner( QWidget *parent, @@ -114,6 +111,7 @@ private: void validatePaperThumbnail(const Paper &paper) const; const not_null _session; + MTP::Sender _api; std::vector _papers; @@ -185,6 +183,7 @@ BackgroundBox::Inner::Inner( not_null session) : RpWidget(parent) , _session(session) +, _api(_session->api().instance()) , _check(std::make_unique(st::overviewCheck, [=] { update(); })) { _check->setChecked(true, Ui::RoundCheckbox::SetStyle::Fast); if (_session->data().wallpapers().empty()) { @@ -209,7 +208,7 @@ BackgroundBox::Inner::Inner( } void BackgroundBox::Inner::requestPapers() { - request(MTPaccount_GetWallPapers( + _api.request(MTPaccount_GetWallPapers( MTP_int(_session->data().wallpapersHash()) )).done([=](const MTPaccount_WallPapers &result) { if (_session->data().updateWallpapers(result)) { diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.h b/Telegram/SourceFiles/boxes/edit_privacy_box.h index 1060157fdc..4310d1b516 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.h +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.h @@ -100,7 +100,7 @@ private: }; -class EditPrivacyBox : public Ui::BoxContent, private MTP::Sender { +class EditPrivacyBox : public Ui::BoxContent { public: using Value = ApiWrap::Privacy; using Option = Value::Option; diff --git a/Telegram/SourceFiles/boxes/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index 26a073c508..96ce5c731e 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "boxes/confirm_phone_box.h" #include "mainwindow.h" +#include "apiwrap.h" #include "main/main_session.h" #include "storage/localstorage.h" #include "ui/widgets/buttons.h" @@ -47,6 +48,7 @@ PasscodeBox::PasscodeBox( not_null session, bool turningOff) : _session(session) +, _api(_session->api().instance()) , _turningOff(turningOff) , _about(st::boxWidth - st::boxPadding.left() * 1.5) , _oldPasscode(this, st::defaultInputField, tr::lng_passcode_enter_old()) @@ -62,6 +64,7 @@ PasscodeBox::PasscodeBox( not_null session, const CloudFields &fields) : _session(session) +, _api(_session->api().instance()) , _turningOff(fields.turningOff) , _cloudPwd(true) , _cloudFields(fields) @@ -357,7 +360,7 @@ void PasscodeBox::validateEmail( if (_setRequest) { return; } - _setRequest = request(MTPaccount_ConfirmPasswordEmail( + _setRequest = _api.request(MTPaccount_ConfirmPasswordEmail( MTP_string(code) )).done([=](const MTPBool &result) { *set = true; @@ -387,7 +390,7 @@ void PasscodeBox::validateEmail( if (_setRequest) { return; } - _setRequest = request(MTPaccount_ResendPasswordEmail( + _setRequest = _api.request(MTPaccount_ResendPasswordEmail( )).done([=](const MTPBool &result) { _setRequest = 0; resent->fire(tr::lng_cloud_password_resent(tr::now)); @@ -597,8 +600,8 @@ void PasscodeBox::requestPasswordData() { return serverError(); } - request(base::take(_setRequest)).cancel(); - _setRequest = request( + _api.request(base::take(_setRequest)).cancel(); + _setRequest = _api.request( MTPaccount_GetPassword() ).done([=](const MTPaccount_Password &result) { _setRequest = 0; @@ -636,7 +639,7 @@ void PasscodeBox::sendClearCloudPassword( | MTPDaccount_passwordInputSettings::Flag::f_new_password_hash | MTPDaccount_passwordInputSettings::Flag::f_hint | MTPDaccount_passwordInputSettings::Flag::f_email; - _setRequest = request(MTPaccount_UpdatePasswordSettings( + _setRequest = _api.request(MTPaccount_UpdatePasswordSettings( check.result, MTP_account_passwordInputSettings( MTP_flags(flags), @@ -667,7 +670,7 @@ void PasscodeBox::setNewCloudPassword(const QString &newPassword) { | MTPDaccount_passwordInputSettings::Flag::f_hint | MTPDaccount_passwordInputSettings::Flag::f_email; _checkPasswordCallback = nullptr; - _setRequest = request(MTPaccount_UpdatePasswordSettings( + _setRequest = _api.request(MTPaccount_UpdatePasswordSettings( MTP_inputCheckPasswordEmpty(), MTP_account_passwordInputSettings( MTP_flags(flags), @@ -695,7 +698,7 @@ void PasscodeBox::changeCloudPassword( const QString &oldPassword, const Core::CloudPasswordResult &check, const QString &newPassword) { - _setRequest = request(MTPaccount_GetPasswordSettings( + _setRequest = _api.request(MTPaccount_GetPasswordSettings( check.result )).done([=](const MTPaccount_PasswordSettings &result) { _setRequest = 0; @@ -760,7 +763,7 @@ void PasscodeBox::resetSecret( const QString &newPassword, Fn callback) { using Flag = MTPDaccount_passwordInputSettings::Flag; - _setRequest = request(MTPaccount_UpdatePasswordSettings( + _setRequest = _api.request(MTPaccount_UpdatePasswordSettings( check.result, MTP_account_passwordInputSettings( MTP_flags(Flag::f_new_secure_settings), @@ -814,7 +817,7 @@ void PasscodeBox::sendChangeCloudPassword( _cloudFields.newSecureSecretAlgo, bytes::make_span(newPasswordBytes))); } - _setRequest = request(MTPaccount_UpdatePasswordSettings( + _setRequest = _api.request(MTPaccount_UpdatePasswordSettings( check.result, MTP_account_passwordInputSettings( MTP_flags(flags), @@ -873,7 +876,7 @@ void PasscodeBox::emailChanged() { void PasscodeBox::recoverByEmail() { if (_pattern.isEmpty()) { _pattern = "-"; - request(MTPauth_RequestPasswordRecovery( + _api.request(MTPauth_RequestPasswordRecovery( )).done([=](const MTPauth_PasswordRecovery &result) { recoverStarted(result); }).fail([=](const RPCError &error) { diff --git a/Telegram/SourceFiles/boxes/passcode_box.h b/Telegram/SourceFiles/boxes/passcode_box.h index a8ad5ea8c6..03ab68f873 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.h +++ b/Telegram/SourceFiles/boxes/passcode_box.h @@ -25,7 +25,7 @@ namespace Core { struct CloudPasswordState; } // namespace Core -class PasscodeBox : public Ui::BoxContent, private MTP::Sender { +class PasscodeBox : public Ui::BoxContent { public: PasscodeBox(QWidget*, not_null session, bool turningOff); @@ -130,6 +130,7 @@ private: void serverError(); const not_null _session; + MTP::Sender _api; QString _pattern; diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index 190c2f3723..606ecc4f49 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -142,7 +142,8 @@ void PeerListRowWithLink::paintAction( PeerListGlobalSearchController::PeerListGlobalSearchController( not_null navigation) -: _navigation(navigation) { +: _navigation(navigation) +, _api(_navigation->session().api().instance()) { _timer.setCallback([this] { searchOnServer(); }); } @@ -169,7 +170,7 @@ bool PeerListGlobalSearchController::searchInCache() { } void PeerListGlobalSearchController::searchOnServer() { - _requestId = request(MTPcontacts_Search( + _requestId = _api.request(MTPcontacts_Search( MTP_string(_query), MTP_int(SearchPeopleLimit) )).done([=](const MTPcontacts_Found &result, mtpRequestId requestId) { diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.h b/Telegram/SourceFiles/boxes/peer_list_controllers.h index ddc4ba4f8e..a1a52e7016 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.h +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.h @@ -59,9 +59,7 @@ private: }; -class PeerListGlobalSearchController - : public PeerListSearchController - , private MTP::Sender { +class PeerListGlobalSearchController : public PeerListSearchController { public: PeerListGlobalSearchController( not_null navigation); @@ -78,6 +76,7 @@ private: void searchDone(const MTPcontacts_Found &result, mtpRequestId requestId); const not_null _navigation; + MTP::Sender _api; base::Timer _timer; QString _query; mtpRequestId _requestId = 0; diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 08c95bc723..ff7d2c3d19 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -276,6 +276,7 @@ AddSpecialBoxController::AddSpecialBoxController( peer, &_additional)) , _peer(peer) +, _api(_peer->session().api().instance()) , _role(role) , _additional(peer, Role::Members) , _adminDoneCallback(std::move(adminDoneCallback)) @@ -408,7 +409,7 @@ void AddSpecialBoxController::loadMoreRows() { const auto participantsHash = 0; const auto channel = _peer->asChannel(); - _loadRequestId = request(MTPchannels_GetParticipants( + _loadRequestId = _api.request(MTPchannels_GetParticipants( channel->inputChannel, MTP_channelParticipantsRecent(), MTP_int(_offset), @@ -464,7 +465,7 @@ bool AddSpecialBoxController::checkInfoLoaded( // We don't know what this user status is in the group. const auto channel = _peer->asChannel(); - request(MTPchannels_GetParticipant( + _api.request(MTPchannels_GetParticipant( channel->inputChannel, user->inputUser )).done([=](const MTPchannels_ChannelParticipant &result) { @@ -829,6 +830,7 @@ AddSpecialBoxSearchController::AddSpecialBoxSearchController( not_null additional) : _peer(peer) , _additional(additional) +, _api(_peer->session().api().instance()) , _timer([=] { searchOnServer(); }) { subscribeToMigration(); } @@ -924,7 +926,7 @@ void AddSpecialBoxSearchController::requestParticipants() { const auto participantsHash = 0; const auto channel = _peer->asChannel(); - _requestId = request(MTPchannels_GetParticipants( + _requestId = _api.request(MTPchannels_GetParticipants( channel->inputChannel, MTP_channelParticipantsSearch(MTP_string(_query)), MTP_int(_offset), @@ -1012,7 +1014,7 @@ void AddSpecialBoxSearchController::requestGlobal() { } auto perPage = SearchPeopleLimit; - _requestId = request(MTPcontacts_Search( + _requestId = _api.request(MTPcontacts_Search( MTP_string(_query), MTP_int(perPage) )).done([=](const MTPcontacts_Found &result, mtpRequestId requestId) { diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.h b/Telegram/SourceFiles/boxes/peers/add_participants_box.h index d15f474e85..2761d172d7 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.h @@ -69,7 +69,6 @@ private: class AddSpecialBoxController : public PeerListController , private base::Subscriber - , private MTP::Sender , public base::has_weak_ptr { public: using Role = ParticipantsBoxController::Role; @@ -87,12 +86,12 @@ public: AdminDoneCallback adminDoneCallback, BannedDoneCallback bannedDoneCallback); - Main::Session &session() const override; + [[nodiscard]] Main::Session &session() const override; void prepare() override; void rowClicked(not_null row) override; void loadMoreRows() override; - std::unique_ptr createSearchRow( + [[nodiscard]] std::unique_ptr createSearchRow( not_null peer) override; private: @@ -120,6 +119,7 @@ private: void migrate(not_null channel); not_null _peer; + MTP::Sender _api; Role _role = Role::Admins; int _offset = 0; mtpRequestId _loadRequestId = 0; @@ -139,7 +139,6 @@ protected: // Finds chat/channel members, then contacts, then global search results. class AddSpecialBoxSearchController : public PeerListSearchController - , private MTP::Sender , private base::Subscriber { public: using Role = ParticipantsBoxController::Role; @@ -181,6 +180,7 @@ private: not_null _peer; not_null _additional; + MTP::Sender _api; base::Timer _timer; QString _query; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 892b5a6a65..f250ca81f7 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -745,6 +745,7 @@ ParticipantsBoxController::ParticipantsBoxController( : PeerListController(CreateSearchController(peer, role, &_additional)) , _navigation(navigation) , _peer(peer) +, _api(_peer->session().api().instance()) , _role(role) , _additional(peer, _role) { subscribeToMigration(); @@ -1022,7 +1023,7 @@ void ParticipantsBoxController::restoreState( : nullptr; if (const auto my = dynamic_cast(typeErasedState)) { if (const auto requestId = base::take(_loadRequestId)) { - request(requestId).cancel(); + _api.request(requestId).cancel(); } _additional = std::move(my->additional); @@ -1251,7 +1252,7 @@ void ParticipantsBoxController::loadMoreRows() { : kParticipantsFirstPageCount; const auto participantsHash = 0; - _loadRequestId = request(MTPchannels_GetParticipants( + _loadRequestId = _api.request(MTPchannels_GetParticipants( channel->inputChannel, filter, MTP_int(_offset), @@ -1906,7 +1907,8 @@ ParticipantsBoxSearchController::ParticipantsBoxSearchController( not_null additional) : _channel(channel) , _role(role) -, _additional(additional) { +, _additional(additional) +, _api(_channel->session().api().instance()) { _timer.setCallback([=] { searchOnServer(); }); } @@ -1938,7 +1940,7 @@ void ParticipantsBoxSearchController::restoreState( std::unique_ptr state) { if (auto my = dynamic_cast(state.get())) { if (auto requestId = base::take(_requestId)) { - request(requestId).cancel(); + _api.request(requestId).cancel(); } _cache.clear(); _queries.clear(); @@ -2002,7 +2004,7 @@ bool ParticipantsBoxSearchController::loadMoreRows() { auto perPage = kParticipantsPerPage; auto participantsHash = 0; - _requestId = request(MTPchannels_GetParticipants( + _requestId = _api.request(MTPchannels_GetParticipants( _channel->inputChannel, filter, MTP_int(_offset), diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h index af0b8decc7..fd36c97ce5 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h @@ -134,7 +134,6 @@ private: class ParticipantsBoxController : public PeerListController , private base::Subscriber - , private MTP::Sender , public base::has_weak_ptr { public: using Role = ParticipantsRole; @@ -238,6 +237,7 @@ private: not_null _navigation; not_null _peer; + MTP::Sender _api; Role _role = Role::Admins; int _offset = 0; mtpRequestId _loadRequestId = 0; @@ -251,9 +251,7 @@ private: }; // Members, banned and restricted users server side search. -class ParticipantsBoxSearchController - : public PeerListSearchController - , private MTP::Sender { +class ParticipantsBoxSearchController : public PeerListSearchController { public: using Role = ParticipantsBoxController::Role; @@ -295,6 +293,7 @@ private: not_null _channel; Role _role = Role::Restricted; not_null _additional; + MTP::Sender _api; base::Timer _timer; QString _query; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index c84e6be4ef..7dd7e538f1 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -240,9 +240,7 @@ namespace { constexpr auto kMaxGroupChannelTitle = 128; // See also add_contact_box. constexpr auto kMaxChannelDescription = 255; // See also add_contact_box. -class Controller - : public base::has_weak_ptr - , private MTP::Sender { +class Controller : public base::has_weak_ptr { public: Controller( not_null navigation, @@ -334,6 +332,7 @@ private: const not_null _navigation; const not_null _box; not_null _peer; + MTP::Sender _api; const bool _isGroup = false; base::unique_qptr _wrap; @@ -344,7 +343,6 @@ private: const rpl::event_stream _privacyTypeUpdates; const rpl::event_stream _linkedChatUpdates; - MTP::Sender _linkedChatsRequester; mtpRequestId _linkedChatsRequestId = 0; rpl::lifetime _lifetime; @@ -358,6 +356,7 @@ Controller::Controller( : _navigation(navigation) , _box(box) , _peer(peer) +, _api(_peer->session().api().instance()) , _isGroup(_peer->isChat() || _peer->isMegagroup()) { _box->setTitle(_isGroup ? tr::lng_edit_group() @@ -644,7 +643,7 @@ void Controller::showEditLinkedChatBox() { callback(_linkedChatOriginalValue); return; } - _linkedChatsRequestId = _linkedChatsRequester.request( + _linkedChatsRequestId = _api.request( MTPchannels_GetGroupsForDiscussion() ).done([=](const MTPmessages_Chats &result) { _linkedChatsRequestId = 0; @@ -1187,7 +1186,7 @@ void Controller::saveUsername() { return; } - request(MTPchannels_UpdateUsername( + _api.request(MTPchannels_UpdateUsername( channel->inputChannel, MTP_string(*_savingData.username) )).done([=](const MTPBool &result) { @@ -1242,7 +1241,7 @@ void Controller::saveLinkedChat() { const auto input = *_savingData.linkedChat ? (*_savingData.linkedChat)->inputChannel : MTP_inputChannelEmpty(); - request(MTPchannels_SetDiscussionGroup( + _api.request(MTPchannels_SetDiscussionGroup( (channel->isBroadcast() ? channel->inputChannel : input), (channel->isBroadcast() ? input : channel->inputChannel) )).done([=](const MTPBool &result) { @@ -1283,14 +1282,14 @@ void Controller::saveTitle() { }; if (const auto channel = _peer->asChannel()) { - request(MTPchannels_EditTitle( + _api.request(MTPchannels_EditTitle( channel->inputChannel, MTP_string(*_savingData.title) )).done(std::move(onDone) ).fail(std::move(onFail) ).send(); } else if (const auto chat = _peer->asChat()) { - request(MTPmessages_EditChatTitle( + _api.request(MTPmessages_EditChatTitle( chat->inputChat, MTP_string(*_savingData.title) )).done(std::move(onDone) @@ -1311,7 +1310,7 @@ void Controller::saveDescription() { _peer->setAbout(*_savingData.description); continueSave(); }; - request(MTPmessages_EditChatAbout( + _api.request(MTPmessages_EditChatAbout( _peer->input, MTP_string(*_savingData.description) )).done([=](const MTPBool &result) { @@ -1368,7 +1367,7 @@ void Controller::togglePreHistoryHidden( done(); }; - request(MTPchannels_TogglePreHistoryHidden( + _api.request(MTPchannels_TogglePreHistoryHidden( channel->inputChannel, MTP_bool(hidden) )).done([=](const MTPUpdates &result) { @@ -1390,7 +1389,7 @@ void Controller::saveSignatures() { || *_savingData.signatures == channel->addsSignature()) { return continueSave(); } - request(MTPchannels_ToggleSignatures( + _api.request(MTPchannels_ToggleSignatures( channel->inputChannel, MTP_bool(*_savingData.signatures) )).done([=](const MTPUpdates &result) { diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index 8dd0c2eaa4..71ee082cad 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -51,9 +51,7 @@ namespace { constexpr auto kUsernameCheckTimeout = crl::time(200); constexpr auto kMinUsernameLength = 5; -class Controller - : public base::has_weak_ptr - , private MTP::Sender { +class Controller : public base::has_weak_ptr { public: Controller( not_null container, @@ -144,6 +142,7 @@ private: QString inviteLinkText(); not_null _peer; + MTP::Sender _api; std::optional _privacySavedValue; std::optional _usernameSavedValue; @@ -169,6 +168,7 @@ Controller::Controller( std::optional privacySavedValue, std::optional usernameSavedValue) : _peer(peer) +, _api(_peer->session().api().instance()) , _privacySavedValue(privacySavedValue) , _usernameSavedValue(usernameSavedValue) , _useLocationPhrases(useLocationPhrases) @@ -401,7 +401,7 @@ void Controller::privacyChanged(Privacy value) { refreshVisibilities(); _controls.usernameInput->setDisplayFocused(true); } else { - request(base::take(_checkUsernameRequestId)).cancel(); + _api.request(base::take(_checkUsernameRequestId)).cancel(); _checkUsernameTimer.cancel(); refreshVisibilities(); } @@ -420,11 +420,11 @@ void Controller::checkUsernameAvailability() { return; } if (_checkUsernameRequestId) { - request(_checkUsernameRequestId).cancel(); + _api.request(_checkUsernameRequestId).cancel(); } const auto channel = _peer->migrateToOrMe()->asChannel(); const auto username = channel ? channel->username : QString(); - _checkUsernameRequestId = request(MTPchannels_CheckUsername( + _checkUsernameRequestId = _api.request(MTPchannels_CheckUsername( channel ? channel->inputChannel : MTP_inputChannelEmpty(), MTP_string(checking) )).done([=](const MTPBool &result) { diff --git a/Telegram/SourceFiles/boxes/rate_call_box.cpp b/Telegram/SourceFiles/boxes/rate_call_box.cpp index be102184b8..85294a3fe1 100644 --- a/Telegram/SourceFiles/boxes/rate_call_box.cpp +++ b/Telegram/SourceFiles/boxes/rate_call_box.cpp @@ -31,6 +31,7 @@ RateCallBox::RateCallBox( uint64 callId, uint64 callAccessHash) : _session(session) +, _api(_session->api().instance()) , _callId(callId) , _callAccessHash(callAccessHash) { } @@ -120,7 +121,7 @@ void RateCallBox::send() { return; } auto comment = _comment ? _comment->getLastText().trimmed() : QString(); - _requestId = request(MTPphone_SetCallRating( + _requestId = _api.request(MTPphone_SetCallRating( MTP_flags(0), MTP_inputPhoneCall(MTP_long(_callId), MTP_long(_callAccessHash)), MTP_int(_rating), diff --git a/Telegram/SourceFiles/boxes/rate_call_box.h b/Telegram/SourceFiles/boxes/rate_call_box.h index 9efaa4d530..99ca677d8e 100644 --- a/Telegram/SourceFiles/boxes/rate_call_box.h +++ b/Telegram/SourceFiles/boxes/rate_call_box.h @@ -20,7 +20,7 @@ namespace Main { class Session; } // namespace Main -class RateCallBox : public Ui::BoxContent, private MTP::Sender { +class RateCallBox : public Ui::BoxContent { public: RateCallBox( QWidget*, @@ -41,6 +41,7 @@ private: void commentResized(); const not_null _session; + MTP::Sender _api; uint64 _callId = 0; uint64 _callAccessHash = 0; diff --git a/Telegram/SourceFiles/boxes/self_destruction_box.h b/Telegram/SourceFiles/boxes/self_destruction_box.h index 475f597491..95f7928c87 100644 --- a/Telegram/SourceFiles/boxes/self_destruction_box.h +++ b/Telegram/SourceFiles/boxes/self_destruction_box.h @@ -20,7 +20,7 @@ namespace Main { class Session; } // namespace Main -class SelfDestructionBox : public Ui::BoxContent, private MTP::Sender { +class SelfDestructionBox : public Ui::BoxContent { public: SelfDestructionBox( QWidget*, diff --git a/Telegram/SourceFiles/boxes/sessions_box.cpp b/Telegram/SourceFiles/boxes/sessions_box.cpp index 91247790d1..071058b17f 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.cpp +++ b/Telegram/SourceFiles/boxes/sessions_box.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "mainwidget.h" #include "mainwindow.h" +#include "apiwrap.h" #include "main/main_session.h" #include "data/data_session.h" #include "base/unixtime.h" @@ -77,6 +78,7 @@ private: SessionsBox::SessionsBox(QWidget*, not_null session) : _session(session) +, _api(_session->api().instance()) , _shortPollTimer([=] { shortPollSessions(); }) { } @@ -280,7 +282,7 @@ void SessionsBox::shortPollSessions() { if (_shortPollRequest) { return; } - _shortPollRequest = request(MTPaccount_GetAuthorizations( + _shortPollRequest = _api.request(MTPaccount_GetAuthorizations( )).done([=](const MTPaccount_Authorizations &result) { got(result); }).send(); @@ -294,7 +296,7 @@ void SessionsBox::terminateOne(uint64 hash) { _terminateBox->closeBox(); _terminateBox = nullptr; } - request(MTPaccount_ResetAuthorization( + _api.request(MTPaccount_ResetAuthorization( MTP_long(hash) )).done([=](const MTPBool &result) { _inner->terminatingOne(hash, false); @@ -330,12 +332,12 @@ void SessionsBox::terminateAll() { _terminateBox->closeBox(); _terminateBox = nullptr; } - request(MTPauth_ResetAuthorizations( + _api.request(MTPauth_ResetAuthorizations( )).done([=](const MTPBool &result) { - request(base::take(_shortPollRequest)).cancel(); + _api.request(base::take(_shortPollRequest)).cancel(); shortPollSessions(); }).fail([=](const RPCError &result) { - request(base::take(_shortPollRequest)).cancel(); + _api.request(base::take(_shortPollRequest)).cancel(); shortPollSessions(); }).send(); setLoading(true); diff --git a/Telegram/SourceFiles/boxes/sessions_box.h b/Telegram/SourceFiles/boxes/sessions_box.h index b27ec5dd42..b2c7953eb1 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.h +++ b/Telegram/SourceFiles/boxes/sessions_box.h @@ -22,7 +22,7 @@ namespace Main { class Session; } // namespace Main -class SessionsBox : public Ui::BoxContent, private MTP::Sender { +class SessionsBox : public Ui::BoxContent { public: SessionsBox(QWidget*, not_null session); @@ -60,6 +60,7 @@ private: void terminateAll(); const not_null _session; + MTP::Sender _api; bool _loading = false; Full _data; diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 597d718269..b5a4961124 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -99,7 +99,7 @@ private: void showPreview(); not_null _controller; - MTP::Sender _mtp; + MTP::Sender _api; std::vector _elements; std::unique_ptr _lottiePlayer; Stickers::Pack _pack; @@ -220,6 +220,7 @@ StickerSetBox::Inner::Inner( const MTPInputStickerSet &set) : RpWidget(parent) , _controller(controller) +, _api(_controller->session().api().instance()) , _input(set) , _previewTimer([=] { showPreview(); }) { set.match([&](const MTPDinputStickerSetID &data) { @@ -231,7 +232,7 @@ StickerSetBox::Inner::Inner( }, [&](const MTPDinputStickerSetAnimatedEmoji &) { }); - _mtp.request(MTPmessages_GetStickerSet( + _api.request(MTPmessages_GetStickerSet( _input )).done([=](const MTPmessages_StickerSet &result) { gotSet(result); @@ -700,7 +701,7 @@ void StickerSetBox::Inner::install() { } else if (_installRequest) { return; } - _installRequest = _mtp.request(MTPmessages_InstallStickerSet( + _installRequest = _api.request(MTPmessages_InstallStickerSet( _input, MTP_bool(false) )).done([=](const MTPmessages_StickerSetInstallResult &result) { diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index c426a2316b..1be373e51e 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -661,6 +661,7 @@ StickersBox::Inner::Inner( StickersBox::Section section) : RpWidget(parent) , _session(session) +, _api(_session->api().instance()) , _section(section) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) , _shiftingAnimation([=](crl::time now) { @@ -677,6 +678,7 @@ StickersBox::Inner::Inner( StickersBox::Inner::Inner(QWidget *parent, not_null megagroup) : RpWidget(parent) , _session(&megagroup->session()) +, _api(_session->api().instance()) , _section(StickersBox::Section::Installed) , _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom()) , _shiftingAnimation([=](crl::time now) { @@ -1469,11 +1471,13 @@ void StickersBox::Inner::handleMegagroupSetAddressChange() { } } } else if (!_megagroupSetRequestId) { - _megagroupSetRequestId = request(MTPmessages_GetStickerSet(MTP_inputStickerSetShortName(MTP_string(text)))).done([this](const MTPmessages_StickerSet &result) { + _megagroupSetRequestId = _api.request(MTPmessages_GetStickerSet( + MTP_inputStickerSetShortName(MTP_string(text)) + )).done([=](const MTPmessages_StickerSet &result) { _megagroupSetRequestId = 0; auto set = Stickers::FeedSetFull(result); setMegagroupSelectedSet(MTP_inputStickerSetID(MTP_long(set->id), MTP_long(set->access))); - }).fail([this](const RPCError &error) { + }).fail([=](const RPCError &error) { _megagroupSetRequestId = 0; setMegagroupSelectedSet(MTP_inputStickerSetEmpty()); }).send(); diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index d5aba39edb..3cdd90a18c 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -153,8 +153,7 @@ private: // This class is hold in header because it requires Qt preprocessing. class StickersBox::Inner : public Ui::RpWidget - , private base::Subscriber - , private MTP::Sender { + , private base::Subscriber { Q_OBJECT public: @@ -320,6 +319,7 @@ private: int countMaxNameWidth() const; const not_null _session; + MTP::Sender _api; Section _section; diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index ab5189452c..7b20008929 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_media_types.h" #include "data/data_user.h" +#include "apiwrap.h" #include "facades.h" #include "app.h" @@ -216,7 +217,8 @@ void BoxController::Row::stopLastActionRipple() { } BoxController::BoxController(not_null window) -: _window(window) { +: _window(window) +, _api(_window->session().api().instance()) { } Main::Session &BoxController::session() const { @@ -256,7 +258,7 @@ void BoxController::loadMoreRows() { return; } - _loadRequestId = request(MTPmessages_Search( + _loadRequestId = _api.request(MTPmessages_Search( MTP_flags(0), MTP_inputPeerEmpty(), MTP_string(), diff --git a/Telegram/SourceFiles/calls/calls_box_controller.h b/Telegram/SourceFiles/calls/calls_box_controller.h index 9833469f1c..d67e22c04a 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.h +++ b/Telegram/SourceFiles/calls/calls_box_controller.h @@ -15,10 +15,7 @@ class SessionController; namespace Calls { -class BoxController - : public PeerListController - , private base::Subscriber - , private MTP::Sender { +class BoxController : public PeerListController, private base::Subscriber { public: explicit BoxController(not_null window); @@ -44,6 +41,7 @@ private: not_null item) const; const not_null _window; + MTP::Sender _api; MsgId _offsetId = 0; mtpRequestId _loadRequestId = 0; diff --git a/Telegram/SourceFiles/calls/calls_call.cpp b/Telegram/SourceFiles/calls/calls_call.cpp index 7539f1544a..bf57bdca48 100644 --- a/Telegram/SourceFiles/calls/calls_call.cpp +++ b/Telegram/SourceFiles/calls/calls_call.cpp @@ -130,6 +130,7 @@ Call::Call( Type type) : _delegate(delegate) , _user(user) +, _api(_user->session().api().instance()) , _type(type) { _discardByTimeoutTimer.setCallback([this] { hangup(); }); @@ -189,7 +190,7 @@ void Call::startOutgoing() { Expects(_state == State::Requesting); Expects(_gaHash.size() == kSha256Size); - request(MTPphone_RequestCall( + _api.request(MTPphone_RequestCall( MTP_flags(0), _user->inputUser, MTP_int(rand_value()), @@ -236,11 +237,13 @@ void Call::startIncoming() { Expects(_type == Type::Incoming); Expects(_state == State::Starting); - request(MTPphone_ReceivedCall(MTP_inputPhoneCall(MTP_long(_id), MTP_long(_accessHash)))).done([this](const MTPBool &result) { + _api.request(MTPphone_ReceivedCall( + MTP_inputPhoneCall(MTP_long(_id), MTP_long(_accessHash)) + )).done([=](const MTPBool &result) { if (_state == State::Starting) { setState(State::WaitingIncoming); } - }).fail([this](const RPCError &error) { + }).fail([=](const RPCError &error) { handleRequestError(error); }).send(); } @@ -267,7 +270,7 @@ void Call::actuallyAnswer() { } else { _answerAfterDhConfigReceived = false; } - request(MTPphone_AcceptCall( + _api.request(MTPphone_AcceptCall( MTP_inputPhoneCall(MTP_long(_id), MTP_long(_accessHash)), MTP_bytes(_gb), MTP_phoneCallProtocol( @@ -504,7 +507,7 @@ void Call::confirmAcceptedCall(const MTPDphoneCallAccepted &call) { _keyFingerprint = ComputeFingerprint(_authKey); setState(State::ExchangingKeys); - request(MTPphone_ConfirmCall( + _api.request(MTPphone_ConfirmCall( MTP_inputPhoneCall(MTP_long(_id), MTP_long(_accessHash)), MTP_bytes(_ga), MTP_long(_keyFingerprint), @@ -840,7 +843,7 @@ void Call::finish(FinishType type, const MTPPhoneCallDiscardReason &reason) { auto duration = getDurationMs() / 1000; auto connectionId = _controller ? _controller->GetPreferredRelayID() : 0; _finishByTimeoutTimer.call(kHangupTimeoutMs, [this, finalState] { setState(finalState); }); - request(MTPphone_DiscardCall( + _api.request(MTPphone_DiscardCall( MTP_flags(0), MTP_inputPhoneCall( MTP_long(_id), diff --git a/Telegram/SourceFiles/calls/calls_call.h b/Telegram/SourceFiles/calls/calls_call.h index 2580b4026d..98bc6b5a66 100644 --- a/Telegram/SourceFiles/calls/calls_call.h +++ b/Telegram/SourceFiles/calls/calls_call.h @@ -31,7 +31,7 @@ struct DhConfig { bytes::vector p; }; -class Call : public base::has_weak_ptr, private MTP::Sender { +class Call : public base::has_weak_ptr { public: class Delegate { public: @@ -183,6 +183,7 @@ private: not_null _delegate; not_null _user; + MTP::Sender _api; Type _type = Type::Outgoing; State _state = State::Starting; FinishType _finishAfterRequestingCall = FinishType::None; diff --git a/Telegram/SourceFiles/calls/calls_instance.cpp b/Telegram/SourceFiles/calls/calls_instance.cpp index 7da4cef5e1..6faaff119c 100644 --- a/Telegram/SourceFiles/calls/calls_instance.cpp +++ b/Telegram/SourceFiles/calls/calls_instance.cpp @@ -32,7 +32,9 @@ constexpr auto kServerConfigUpdateTimeoutMs = 24 * 3600 * crl::time(1000); } // namespace -Instance::Instance(not_null session) : _session(session) { +Instance::Instance(not_null session) +: _session(session) +, _api(_session->api().instance()) { } void Instance::startOutgoingCall(not_null user) { @@ -139,7 +141,7 @@ void Instance::refreshDhConfig() { Expects(_currentCall != nullptr); const auto weak = base::make_weak(_currentCall); - request(MTPmessages_GetDhConfig( + _api.request(MTPmessages_GetDhConfig( MTP_int(_dhConfig.version), MTP_int(MTP::ModExpFirst::kRandomPowerSize) )).done([=](const MTPmessages_DhConfig &result) { @@ -203,13 +205,14 @@ void Instance::refreshServerConfig() { if (_lastServerConfigUpdateTime && (crl::now() - _lastServerConfigUpdateTime) < kServerConfigUpdateTimeoutMs) { return; } - _serverConfigRequestId = request(MTPphone_GetCallConfig()).done([this](const MTPDataJSON &result) { + _serverConfigRequestId = _api.request(MTPphone_GetCallConfig( + )).done([=](const MTPDataJSON &result) { _serverConfigRequestId = 0; _lastServerConfigUpdateTime = crl::now(); const auto &json = result.c_dataJSON().vdata().v; UpdateConfig(std::string(json.data(), json.size())); - }).fail([this](const RPCError &error) { + }).fail([=](const RPCError &error) { _serverConfigRequestId = 0; }).send(); } @@ -246,7 +249,7 @@ void Instance::handleCallUpdate(const MTPPhoneCall &call) { LOG(("API Error: Self found in phoneCallRequested.")); } if (alreadyInCall() || !user || user->isSelf()) { - request(MTPphone_DiscardCall( + _api.request(MTPphone_DiscardCall( MTP_flags(0), MTP_inputPhoneCall(phoneCall.vid(), phoneCall.vaccess_hash()), MTP_int(0), diff --git a/Telegram/SourceFiles/calls/calls_instance.h b/Telegram/SourceFiles/calls/calls_instance.h index f5d30fa9b9..d8987f4582 100644 --- a/Telegram/SourceFiles/calls/calls_instance.h +++ b/Telegram/SourceFiles/calls/calls_instance.h @@ -25,8 +25,7 @@ namespace Calls { class Panel; class Instance - : private MTP::Sender - , private Call::Delegate + : private Call::Delegate , private base::Subscriber , public base::has_weak_ptr { public: @@ -74,6 +73,7 @@ private: void handleCallUpdate(const MTPPhoneCall &call); const not_null _session; + MTP::Sender _api; DhConfig _dhConfig; diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 274f12f613..a99c0ecbe0 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "lang/lang_keys.h" #include "mainwindow.h" +#include "apiwrap.h" #include "window/window_session_controller.h" #include "history/view/history_view_cursor_state.h" #include "facades.h" @@ -130,6 +131,7 @@ GifsListWidget::GifsListWidget( QWidget *parent, not_null controller) : Inner(parent, controller) +, _api(controller->session().api().instance()) , _section(Section::Gifs) , _updateInlineItems([=] { updateInlineItems(); }) , _previewTimer([=] { showPreview(); }) { @@ -217,7 +219,7 @@ GifsListWidget::~GifsListWidget() { void GifsListWidget::cancelGifsSearch() { _footer->setLoading(false); if (_inlineRequestId) { - request(_inlineRequestId).cancel(); + _api.request(_inlineRequestId).cancel(); _inlineRequestId = 0; } _inlineRequestTimer.stop(); @@ -840,7 +842,7 @@ void GifsListWidget::searchForGifs(const QString &query) { if (_inlineQuery != query) { _footer->setLoading(false); if (_inlineRequestId) { - request(_inlineRequestId).cancel(); + _api.request(_inlineRequestId).cancel(); _inlineRequestId = 0; } if (_inlineCache.find(query) != _inlineCache.cend()) { @@ -855,7 +857,7 @@ void GifsListWidget::searchForGifs(const QString &query) { if (!_searchBot && !_searchBotRequestId) { auto username = str_const_toString(kSearchBotUsername); - _searchBotRequestId = request(MTPcontacts_ResolveUsername( + _searchBotRequestId = _api.request(MTPcontacts_ResolveUsername( MTP_string(username) )).done([=](const MTPcontacts_ResolvedPeer &result) { Expects(result.type() == mtpc_contacts_resolvedPeer); @@ -905,7 +907,7 @@ void GifsListWidget::sendInlineRequest() { } _footer->setLoading(true); - _inlineRequestId = request(MTPmessages_GetInlineBotResults( + _inlineRequestId = _api.request(MTPmessages_GetInlineBotResults( MTP_flags(0), _searchBot->inputUser, _inlineQueryPeer->input, diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h index 1859459c06..f1ae5e73f7 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h @@ -34,8 +34,7 @@ namespace ChatHelpers { class GifsListWidget : public TabbedSelector::Inner , public InlineBots::Layout::Context - , private base::Subscriber - , private MTP::Sender { + , private base::Subscriber { public: using InlineChosen = TabbedSelector::InlineChosen; @@ -119,6 +118,8 @@ private: void updateInlineItems(); void showPreview(); + MTP::Sender _api; + Section _section = Section::Gifs; crl::time _lastScrolled = 0; base::Timer _updateInlineItems; diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index d53b516a04..3a5afa29e6 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -828,6 +828,7 @@ StickersListWidget::StickersListWidget( QWidget *parent, not_null controller) : Inner(parent, controller) +, _api(controller->session().api().instance()) , _section(Section::Stickers) , _megagroupSetAbout(st::columnMinimalWidthThird - st::emojiScroll.width - st::emojiPanHeaderLeft) , _addText(tr::lng_stickers_featured_add(tr::now).toUpper()) @@ -1069,7 +1070,7 @@ void StickersListWidget::sendSearchRequest() { _footer->setLoading(true); const auto hash = int32(0); - _searchRequestId = request(MTPmessages_SearchStickerSets( + _searchRequestId = _api.request(MTPmessages_SearchStickerSets( MTP_flags(0), MTP_string(_searchQuery), MTP_int(hash) @@ -1092,7 +1093,7 @@ void StickersListWidget::searchForSets(const QString &query) { if (_searchQuery != cleaned) { _footer->setLoading(false); if (const auto requestId = base::take(_searchRequestId)) { - request(requestId).cancel(); + _api.request(requestId).cancel(); } if (_searchCache.find(cleaned) != _searchCache.cend()) { _searchRequestTimer.cancel(); @@ -1108,7 +1109,7 @@ void StickersListWidget::searchForSets(const QString &query) { void StickersListWidget::cancelSetsSearch() { _footer->setLoading(false); if (const auto requestId = base::take(_searchRequestId)) { - request(requestId).cancel(); + _api.request(requestId).cancel(); } _searchRequestTimer.cancel(); _searchQuery = _searchNextQuery = QString(); @@ -2468,7 +2469,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { return; } _megagroupSetIdRequested = set.vid().v; - request(MTPmessages_GetStickerSet( + _api.request(MTPmessages_GetStickerSet( _megagroupSet->mgInfo->stickerSet )).done([=](const MTPmessages_StickerSet &result) { if (const auto set = Stickers::FeedSetFull(result)) { @@ -2810,7 +2811,7 @@ void StickersListWidget::installSet(uint64 setId) { const auto input = Stickers::inputSetId(*it); if ((it->flags & MTPDstickerSet_ClientFlag::f_not_loaded) || it->stickers.empty()) { - request(MTPmessages_GetStickerSet( + _api.request(MTPmessages_GetStickerSet( input )).done([=](const MTPmessages_StickerSet &result) { Stickers::FeedSetFull(result); @@ -2825,7 +2826,7 @@ void StickersListWidget::installSet(uint64 setId) { void StickersListWidget::sendInstallRequest( uint64 setId, const MTPInputStickerSet &input) { - request(MTPmessages_InstallStickerSet( + _api.request(MTPmessages_InstallStickerSet( input, MTP_bool(false) )).done([=](const MTPmessages_StickerSetInstallResult &result) { @@ -2876,9 +2877,9 @@ void StickersListWidget::removeSet(uint64 setId) { auto it = sets.find(_removingSetId); if (it != sets.cend()) { if (it->id && it->access) { - request(MTPmessages_UninstallStickerSet(MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access)))).send(); + _api.request(MTPmessages_UninstallStickerSet(MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access)))).send(); } else if (!it->shortName.isEmpty()) { - request(MTPmessages_UninstallStickerSet(MTP_inputStickerSetShortName(MTP_string(it->shortName)))).send(); + _api.request(MTPmessages_UninstallStickerSet(MTP_inputStickerSetShortName(MTP_string(it->shortName)))).send(); } auto writeRecent = false; auto &recent = Stickers::GetRecentPack(); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 53c11c794a..b0e17bea7e 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -38,8 +38,7 @@ struct StickerIcon; class StickersListWidget : public TabbedSelector::Inner - , private base::Subscriber - , private MTP::Sender { + , private base::Subscriber { public: StickersListWidget( QWidget *parent, @@ -300,6 +299,7 @@ private: void showPreview(); + MTP::Sender _api; ChannelData *_megagroupSet = nullptr; uint64 _megagroupSetIdRequested = 0; std::vector _mySets; diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 916af7b228..048a6794eb 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -93,6 +93,7 @@ Application::Application(not_null launcher) , _dcOptions(std::make_unique()) , _account(std::make_unique(cDataFile())) , _langpack(std::make_unique()) +, _langCloudManager(std::make_unique(langpack())) , _emojiKeywords(std::make_unique()) , _audio(std::make_unique()) , _logo(Window::LoadLogo()) @@ -114,9 +115,6 @@ Application::Application(not_null launcher) ) | rpl::filter([=](MTP::Instance *instance) { return instance != nullptr; }) | rpl::start_with_next([=](not_null mtp) { - _langCloudManager = std::make_unique( - langpack(), - mtp); if (!UpdaterDisabled()) { UpdateChecker().setMtproto(mtp.get()); } @@ -134,11 +132,6 @@ Application::~Application() { // Some MTP requests can be cancelled from data clearing. unlockTerms(); activeAccount().destroySession(); - - // The langpack manager should be destroyed before MTProto instance, - // because it is MTP::Sender and it may have pending requests. - _langCloudManager.reset(); - activeAccount().clearMtp(); Shortcuts::Finish(); diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 1f68e48a0a..6854aaa327 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -266,7 +266,7 @@ private: std::unique_ptr _window; std::unique_ptr _mediaView; const std::unique_ptr _langpack; - std::unique_ptr _langCloudManager; + const std::unique_ptr _langCloudManager; const std::unique_ptr _emojiKeywords; std::unique_ptr _translator; base::Observable _passcodedChanged; diff --git a/Telegram/SourceFiles/data/data_search_controller.cpp b/Telegram/SourceFiles/data/data_search_controller.cpp index 01dcf7f86d..243654287a 100644 --- a/Telegram/SourceFiles/data/data_search_controller.cpp +++ b/Telegram/SourceFiles/data/data_search_controller.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_channel.h" #include "history/history.h" #include "history/history_item.h" +#include "apiwrap.h" namespace Api { namespace { @@ -191,6 +192,10 @@ SearchController::CacheEntry::CacheEntry(const Query &query) : std::nullopt) { } +SearchController::SearchController(not_null session) +: _api(session->api().instance()) { +} + bool SearchController::hasInCache(const Query &query) const { return query.query.isEmpty() || _cache.contains(query); } @@ -361,7 +366,7 @@ void SearchController::requestMore( if (!prepared) { return; } - auto requestId = request( + auto requestId = _api.request( std::move(*prepared) ).done([=](const MTPmessages_Messages &result) { listData->requests.remove(key); @@ -377,11 +382,13 @@ void SearchController::requestMore( parsed.fullCount); }).send(); listData->requests.emplace(key, [=] { - request(requestId).cancel(); + _api.request(requestId).cancel(); }); } -DelayedSearchController::DelayedSearchController() { +DelayedSearchController::DelayedSearchController( + not_null session) +: _controller(session) { _timer.setCallback([this] { setQueryFast(_nextQuery); }); } diff --git a/Telegram/SourceFiles/data/data_search_controller.h b/Telegram/SourceFiles/data/data_search_controller.h index c166d59f34..fcc2b88538 100644 --- a/Telegram/SourceFiles/data/data_search_controller.h +++ b/Telegram/SourceFiles/data/data_search_controller.h @@ -14,6 +14,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/value_ordering.h" #include "base/timer.h" +namespace Main { +class Session; +} // namespace Main + namespace Data { enum class LoadDirection : char; } // namespace Data @@ -40,7 +44,7 @@ SearchResult ParseSearchResult( Data::LoadDirection direction, const MTPmessages_Messages &data); -class SearchController : private MTP::Sender { +class SearchController final { public: using IdsList = Storage::SparseIdsList; struct Query { @@ -67,6 +71,7 @@ public: std::optional migratedList; }; + explicit SearchController(not_null session); void setQuery(const Query &query); bool hasInCache(const Query &query) const; @@ -124,6 +129,7 @@ private: const Query &query, Data *listData); + MTP::Sender _api; Cache _cache; Cache::iterator _current = _cache.end(); @@ -131,7 +137,7 @@ private: class DelayedSearchController { public: - DelayedSearchController(); + explicit DelayedSearchController(not_null session); using Query = SearchController::Query; using SavedState = SearchController::SavedState; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 555364637a..31758e82d8 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -226,6 +226,7 @@ InnerWidget::InnerWidget( , _controller(controller) , _channel(channel) , _history(channel->owner().history(channel)) +, _api(_channel->session().api().instance()) , _scrollDateCheck([=] { scrollDateCheck(); }) , _emptyText( st::historyAdminLogEmptyWidth @@ -407,7 +408,7 @@ void InnerWidget::applySearch(const QString &query) { void InnerWidget::requestAdmins() { auto participantsHash = 0; - request(MTPchannels_GetParticipants( + _api.request(MTPchannels_GetParticipants( _channel->inputChannel, MTP_channelParticipantsAdmins(), MTP_int(0), @@ -463,8 +464,8 @@ void InnerWidget::showFilter(Fn callback) { } void InnerWidget::clearAndRequestLog() { - request(base::take(_preloadUpRequestId)).cancel(); - request(base::take(_preloadDownRequestId)).cancel(); + _api.request(base::take(_preloadUpRequestId)).cancel(); + _api.request(base::take(_preloadDownRequestId)).cancel(); _filterChanged = true; _upLoaded = false; _downLoaded = true; @@ -635,7 +636,7 @@ void InnerWidget::preloadMore(Direction direction) { auto maxId = (direction == Direction::Up) ? _minId : 0; auto minId = (direction == Direction::Up) ? 0 : _maxId; auto perPage = _items.empty() ? kEventsFirstPage : kEventsPerPage; - requestId = request(MTPchannels_GetAdminLog( + requestId = _api.request(MTPchannels_GetAdminLog( MTP_flags(flags), _channel->inputChannel, MTP_string(_searchQuery), @@ -1217,7 +1218,7 @@ void InnerWidget::suggestRestrictUser(not_null user) { if (base::contains(_admins, user)) { editRestrictions(true, MTP_chatBannedRights(MTP_flags(0), MTP_int(0))); } else { - request(MTPchannels_GetParticipant( + _api.request(MTPchannels_GetParticipant( _channel->inputChannel, user->inputUser )).done([=](const MTPchannels_ChannelParticipant &result) { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index f20c58382b..c9405ea052 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -44,7 +44,6 @@ class InnerWidget final : public Ui::RpWidget , public Ui::AbstractTooltipShower , public HistoryView::ElementDelegate - , private MTP::Sender , private base::Subscriber { public: InnerWidget( @@ -216,9 +215,11 @@ private: template void enumerateDates(Method method); - not_null _controller; - not_null _channel; - not_null _history; + const not_null _controller; + const not_null _channel; + const not_null _history; + MTP::Sender _api; + std::vector _items; std::set _eventIds; std::map, not_null> _itemsByData; diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp index 47427556a6..065ef7857b 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_controller.h" #include "lang/lang_keys.h" #include "mtproto/sender.h" +#include "main/main_session.h" #include "window/window_session_controller.h" #include "ui/widgets/scroll_area.h" #include "ui/search_field_controller.h" @@ -27,10 +28,7 @@ namespace { constexpr auto kCommonGroupsPerPage = 40; constexpr auto kCommonGroupsSearchAfter = 20; -class ListController - : public PeerListController - , private base::Subscriber - , private MTP::Sender { +class ListController : public PeerListController , private base::Subscriber { public: ListController( not_null controller, @@ -58,6 +56,7 @@ private: bool wasLoading = false; }; const not_null _controller; + MTP::Sender _api; not_null _user; mtpRequestId _preloadRequestId = 0; bool _allLoaded = false; @@ -70,6 +69,7 @@ ListController::ListController( not_null user) : PeerListController() , _controller(controller) +, _api(_controller->session().api().instance()) , _user(user) { _controller->setSearchEnabledByContent(false); } @@ -95,7 +95,7 @@ void ListController::loadMoreRows() { if (_preloadRequestId || _allLoaded) { return; } - _preloadRequestId = request(MTPmessages_GetCommonChats( + _preloadRequestId = _api.request(MTPmessages_GetCommonChats( _user->inputUser, MTP_int(_preloadGroupId), MTP_int(kCommonGroupsPerPage) @@ -143,7 +143,7 @@ void ListController::restoreState( : nullptr; if (auto my = dynamic_cast(typeErasedState)) { if (auto requestId = base::take(_preloadRequestId)) { - request(requestId).cancel(); + _api.request(requestId).cancel(); } _allLoaded = my->allLoaded; _preloadGroupId = my->preloadGroupId; diff --git a/Telegram/SourceFiles/info/info_controller.cpp b/Telegram/SourceFiles/info/info_controller.cpp index 68c3284289..41f6951f68 100644 --- a/Telegram/SourceFiles/info/info_controller.cpp +++ b/Telegram/SourceFiles/info/info_controller.cpp @@ -196,7 +196,7 @@ void Controller::updateSearchControllers( auto searchQuery = memento->searchFieldQuery(); if (isMedia) { _searchController - = std::make_unique(); + = std::make_unique(&session()); auto mediaMemento = dynamic_cast(memento.get()); Assert(mediaMemento != nullptr); _searchController->restoreState( diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index 87d9e7da6b..03fdf601c1 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -754,6 +754,7 @@ Widget::Widget( not_null controller) : RpWidget(parent) , _controller(controller) +, _api(_controller->session().api().instance()) , _contentMaxHeight(st::emojiPanMaxHeight) , _contentHeight(_contentMaxHeight) , _scroll(this, st::inlineBotsScroll) { @@ -1133,9 +1134,16 @@ void Widget::onInlineRequest() { } } Notify::inlineBotRequesting(true); - _inlineRequestId = request(MTPmessages_GetInlineBotResults(MTP_flags(0), _inlineBot->inputUser, _inlineQueryPeer->input, MTPInputGeoPoint(), MTP_string(_inlineQuery), MTP_string(nextOffset))).done([this](const MTPmessages_BotResults &result, mtpRequestId requestId) { + _inlineRequestId = _api.request(MTPmessages_GetInlineBotResults( + MTP_flags(0), + _inlineBot->inputUser, + _inlineQueryPeer->input, + MTPInputGeoPoint(), + MTP_string(_inlineQuery), + MTP_string(nextOffset) + )).done([=](const MTPmessages_BotResults &result) { inlineResultsDone(result); - }).fail([this](const RPCError &error) { + }).fail([=](const RPCError &error) { // show error? Notify::inlineBotRequesting(false); _inlineRequestId = 0; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.h b/Telegram/SourceFiles/inline_bots/inline_results_widget.h index 2c2281e89a..d17b9da4cc 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.h @@ -173,7 +173,7 @@ private: } // namespace internal -class Widget : public Ui::RpWidget, private MTP::Sender { +class Widget : public Ui::RpWidget { Q_OBJECT public: @@ -246,6 +246,7 @@ private: void inlineResultsDone(const MTPmessages_BotResults &result); not_null _controller; + MTP::Sender _api; int _contentMaxHeight = 0; int _contentHeight = 0; diff --git a/Telegram/SourceFiles/intro/intro_qr.cpp b/Telegram/SourceFiles/intro/intro_qr.cpp index 2eb46ef522..92203e3161 100644 --- a/Telegram/SourceFiles/intro/intro_qr.cpp +++ b/Telegram/SourceFiles/intro/intro_qr.cpp @@ -170,12 +170,12 @@ QrWidget::QrWidget( not_null account, not_null data) : Step(parent, account, data) +, _api(account->mtp()) , _refreshTimer([=] { refreshCode(); }) { setTitleText(rpl::single(QString())); setDescriptionText(rpl::single(QString())); setErrorCentered(true); - account->destroyStaleAuthorizationKeys(); account->mtpUpdates( ) | rpl::start_with_next([=](const MTPUpdates &updates) { checkForTokenUpdate(updates); diff --git a/Telegram/SourceFiles/intro/intro_qr.h b/Telegram/SourceFiles/intro/intro_qr.h index 0a97d263d1..6bad082fb1 100644 --- a/Telegram/SourceFiles/intro/intro_qr.h +++ b/Telegram/SourceFiles/intro/intro_qr.h @@ -52,9 +52,9 @@ private: void showToken(const QByteArray &token); void done(const MTPauth_Authorization &authorization); + MTP::Sender _api; rpl::event_stream _qrCodes; base::Timer _refreshTimer; - MTP::Sender _api; mtpRequestId _requestId = 0; bool _forceRefresh = false; diff --git a/Telegram/SourceFiles/intro/intro_step.h b/Telegram/SourceFiles/intro/intro_step.h index 67e2ad2258..c538266225 100644 --- a/Telegram/SourceFiles/intro/intro_step.h +++ b/Telegram/SourceFiles/intro/intro_step.h @@ -177,7 +177,6 @@ private: object_ptr> _description; bool _errorCentered = false; - bool _errorBelowLink = false; rpl::variable _errorText; object_ptr> _error = { nullptr }; diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index e6bee53327..fe070bf52a 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -60,8 +60,6 @@ PhoneWidget::PhoneWidget( _country->onChooseCountry(qsl("US")); } _changed = false; - - account->destroyStaleAuthorizationKeys(); } void PhoneWidget::resizeEvent(QResizeEvent *e) { diff --git a/Telegram/SourceFiles/intro/intropwdcheck.cpp b/Telegram/SourceFiles/intro/intropwdcheck.cpp index 0e5bad618d..d563209108 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.cpp +++ b/Telegram/SourceFiles/intro/intropwdcheck.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/labels.h" +#include "main/main_account.h" #include "base/openssl_help.h" #include "styles/style_intro.h" #include "styles/style_boxes.h" @@ -28,6 +29,7 @@ PwdCheckWidget::PwdCheckWidget( not_null account, not_null data) : Step(parent, account, data) +, _api(account->mtp()) , _request(getData()->pwdRequest) , _hasRecovery(getData()->hasRecovery) , _notEmptyPassport(getData()->pwdNotEmptyPassport) @@ -115,7 +117,7 @@ void PwdCheckWidget::activate() { } void PwdCheckWidget::cancelled() { - request(base::take(_sentRequest)).cancel(); + _api.request(base::take(_sentRequest)).cancel(); } void PwdCheckWidget::stopCheck() { @@ -127,7 +129,7 @@ void PwdCheckWidget::onCheckRequest() { if (status < 0) { auto leftms = -status; if (leftms >= 1000) { - request(base::take(_sentRequest)).cancel(); + _api.request(base::take(_sentRequest)).cancel(); } } if (!_sentRequest && status == MTP::RequestSent) { @@ -202,8 +204,8 @@ void PwdCheckWidget::checkPasswordHash() { } void PwdCheckWidget::requestPasswordData() { - request(base::take(_sentRequest)).cancel(); - _sentRequest = request( + _api.request(base::take(_sentRequest)).cancel(); + _sentRequest = _api.request( MTPaccount_GetPassword() ).done([=](const MTPaccount_Password &result) { _sentRequest = 0; @@ -225,7 +227,7 @@ void PwdCheckWidget::passwordChecked() { return serverError(); } _request.id = 0; - _sentRequest = request( + _sentRequest = _api.request( MTPauth_CheckPassword(check.result) ).done([=](const MTPauth_Authorization &result) { pwdSubmitDone(false, result); @@ -289,7 +291,7 @@ void PwdCheckWidget::recoverStartFail(const RPCError &error) { void PwdCheckWidget::onToRecover() { if (_hasRecovery) { if (_sentRequest) { - request(base::take(_sentRequest)).cancel(); + _api.request(base::take(_sentRequest)).cancel(); } hideError(); _toRecover->hide(); @@ -301,7 +303,7 @@ void PwdCheckWidget::onToRecover() { _codeField->setFocus(); updateDescriptionText(); if (_emailPattern.isEmpty()) { - request( + _api.request( MTPauth_RequestPasswordRecovery() ).done([=](const MTPauth_PasswordRecovery &result) { recoverStarted(result); @@ -320,7 +322,7 @@ void PwdCheckWidget::onToPassword() { void PwdCheckWidget::showReset() { if (_sentRequest) { - request(base::take(_sentRequest)).cancel(); + _api.request(base::take(_sentRequest)).cancel(); } _toRecover->show(); _toPassword->hide(); @@ -355,7 +357,7 @@ void PwdCheckWidget::submit() { return; } const auto send = crl::guard(this, [=] { - _sentRequest = request( + _sentRequest = _api.request( MTPauth_RecoverPassword(MTP_string(code)) ).done([=](const MTPauth_Authorization &result) { pwdSubmitDone(true, result); diff --git a/Telegram/SourceFiles/intro/intropwdcheck.h b/Telegram/SourceFiles/intro/intropwdcheck.h index 02e392eae0..98263b4104 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.h +++ b/Telegram/SourceFiles/intro/intropwdcheck.h @@ -21,7 +21,7 @@ class LinkButton; namespace Intro { namespace details { -class PwdCheckWidget : public Step, private MTP::Sender { +class PwdCheckWidget : public Step { Q_OBJECT public: @@ -67,6 +67,7 @@ private: void passwordChecked(); void serverError(); + MTP::Sender _api; Core::CloudPasswordCheckRequest _request; crl::time _lastSrpIdInvalidTime = 0; bytes::vector _passwordHash; diff --git a/Telegram/SourceFiles/intro/introstart.cpp b/Telegram/SourceFiles/intro/introstart.cpp index e5aab0612b..b8b3cfc57d 100644 --- a/Telegram/SourceFiles/intro/introstart.cpp +++ b/Telegram/SourceFiles/intro/introstart.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "intro/intro_qr.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" +#include "main/main_account.h" namespace Intro { namespace details { @@ -27,6 +28,7 @@ StartWidget::StartWidget( } void StartWidget::submit() { + account().destroyStaleAuthorizationKeys(); goNext(); } diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index 493c8913a7..f6ed2d7e33 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -50,30 +50,42 @@ Widget::Widget(QWidget *parent, not_null account) st::defaultBoxButton)) , _next( this, - object_ptr( + object_ptr(this, nullptr, st::introNextButton)) +, _connecting(std::make_unique( this, - nullptr, - st::introNextButton)) { + rpl::single(true))) { + appendStep(new StartWidget(this, _account, getData())); + fixOrder(); + getData()->country = Platform::SystemCountry(); + _account->mtpValue( + ) | rpl::start_with_next([=](MTP::Instance *instance) { + if (instance) { + _api.emplace(instance); + createLanguageLink(); + } else { + _api.reset(); + } + }, lifetime()); + subscribe(Lang::CurrentCloudManager().firstLanguageSuggestion(), [=] { + createLanguageLink(); + }); + _back->entity()->setClickedCallback([=] { historyMove(Direction::Back); }); _back->hide(anim::type::instant); - _next->entity()->setClickedCallback([this] { getStep()->submit(); }); + _next->entity()->setClickedCallback([=] { getStep()->submit(); }); _settings->entity()->setClickedCallback([] { App::wnd()->showSettings(); }); getNearestDC(); - setupConnectingWidget(); - - appendStep(new StartWidget(this, _account, getData())); - fixOrder(); - - subscribe(Lang::CurrentCloudManager().firstLanguageSuggestion(), [this] { createLanguageLink(); }); - createLanguageLink(); - if (_changeLanguage) _changeLanguage->finishAnimating(); + + if (_changeLanguage) { + _changeLanguage->finishAnimating(); + } subscribe(Lang::Current().updated(), [this] { refreshLang(); }); @@ -98,12 +110,6 @@ Widget::Widget(QWidget *parent, not_null account) } } -void Widget::setupConnectingWidget() { - _connecting = std::make_unique( - this, - rpl::single(true)); -} - void Widget::refreshLang() { _changeLanguage.destroy(); createLanguageLink(); @@ -111,9 +117,13 @@ void Widget::refreshLang() { } void Widget::createLanguageLink() { - if (_changeLanguage) return; + if (_changeLanguage) { + return; + } - auto createLink = [this](const QString &text, const QString &languageId) { + const auto createLink = [=]( + const QString &text, + const QString &languageId) { _changeLanguage.create( this, object_ptr(this, text)); @@ -134,8 +144,8 @@ void Widget::createLanguageLink() { createLink( Lang::GetOriginalValue(tr::lng_switch_to_this.base), defaultId); - } else if (!suggested.isEmpty() && suggested != currentId) { - request(MTPlangpack_GetStrings( + } else if (!suggested.isEmpty() && suggested != currentId && _api) { + _api->request(MTPlangpack_GetStrings( MTP_string(Lang::CloudLangPackName()), MTP_string(suggested), MTP_vector(1, MTP_string("lng_switch_to_this")) @@ -339,18 +349,24 @@ void Widget::acceptTerms(Fn callback) { } void Widget::resetAccount() { - if (_resetRequest) return; + if (_resetRequest || !_api) { + return; + } Ui::show(Box(tr::lng_signin_sure_reset(tr::now), tr::lng_signin_reset(tr::now), st::attentionBoxButton, crl::guard(this, [this] { - if (_resetRequest) return; - _resetRequest = request(MTPaccount_DeleteAccount(MTP_string("Forgot password"))).done([this](const MTPBool &result) { + if (_resetRequest) { + return; + } + _resetRequest = _api->request(MTPaccount_DeleteAccount( + MTP_string("Forgot password") + )).done([=](const MTPBool &result) { _resetRequest = 0; Ui::hideLayer(); moveToStep( new SignupWidget(this, _account, getData()), Direction::Replace); - }).fail([this](const RPCError &error) { + }).fail([=](const RPCError &error) { _resetRequest = 0; const auto &type = error.type(); @@ -410,8 +426,12 @@ void Widget::resetAccount() { } void Widget::getNearestDC() { - request(MTPhelp_GetNearestDc()).done([this](const MTPNearestDc &result) { - auto &nearest = result.c_nearestDc(); + if (!_api) { + return; + } + _api->request(MTPhelp_GetNearestDc( + )).done([=](const MTPNearestDc &result) { + const auto &nearest = result.c_nearestDc(); DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3" ).arg(qs(nearest.vcountry()) ).arg(nearest.vnearest_dc().v diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index e9a84f541c..84c53c4d11 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -72,10 +72,7 @@ class Step; } // namespace details -class Widget - : public Ui::RpWidget - , private MTP::Sender - , private base::Subscriber { +class Widget : public Ui::RpWidget, private base::Subscriber { public: Widget(QWidget *parent, not_null account); @@ -91,7 +88,6 @@ protected: void keyPressEvent(QKeyEvent *e) override; private: - void setupConnectingWidget(); void refreshLang(); void animationCallback(); void createLanguageLink(); @@ -127,7 +123,8 @@ private: void getNearestDC(); void showTerms(Fn callback); - not_null _account; + const not_null _account; + std::optional _api; Ui::Animations::Simple _a_show; bool _showBack = false; diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index c025588fca..e081abe207 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -13,8 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/mtp_instance.h" #include "storage/localstorage.h" #include "core/application.h" -#include "apiwrap.h" #include "main/main_session.h" +#include "main/main_account.h" #include "boxes/confirm_box.h" #include "ui/wrap/padding_wrap.h" #include "ui/widgets/labels.h" @@ -156,11 +156,17 @@ Language ParseLanguage(const MTPLangPackLanguage &data) { }); } -CloudManager::CloudManager( - Instance &langpack, - not_null mtproto) -: MTP::Sender() -, _langpack(langpack) { +CloudManager::CloudManager(Instance &langpack) +: _langpack(langpack) { + Core::App().activeAccount().mtpValue( + ) | rpl::start_with_next([=](MTP::Instance *instance) { + if (instance) { + _api.emplace(instance); + resendRequests(); + } else { + _api.reset(); + } + }, _lifetime); } Pack CloudManager::packTypeFromId(const QString &id) const { @@ -195,7 +201,10 @@ mtpRequestId CloudManager::packRequestId(Pack pack) const { } void CloudManager::requestLangPackDifference(Pack pack) { - request(base::take(packRequestId(pack))).cancel(); + if (!_api) { + return; + } + _api->request(base::take(packRequestId(pack))).cancel(); if (_langpack.isCustom()) { return; } @@ -206,7 +215,7 @@ void CloudManager::requestLangPackDifference(Pack pack) { return; } if (version > 0) { - packRequestId(pack) = request(MTPlangpack_GetDifference( + packRequestId(pack) = _api->request(MTPlangpack_GetDifference( MTP_string(CloudLangPackName()), MTP_string(code), MTP_int(version) @@ -217,7 +226,7 @@ void CloudManager::requestLangPackDifference(Pack pack) { packRequestId(pack) = 0; }).send(); } else { - packRequestId(pack) = request(MTPlangpack_GetLangPack( + packRequestId(pack) = _api->request(MTPlangpack_GetLangPack( MTP_string(CloudLangPackName()), MTP_string(code) )).done([=](const MTPLangPackDifference &result) { @@ -284,7 +293,12 @@ void CloudManager::applyLangPackDifference( } void CloudManager::requestLanguageList() { - _languagesRequestId = request(MTPlangpack_GetLanguages( + if (!_api) { + _languagesRequestId = -1; + return; + } + _api->request(base::take(_languagesRequestId)).cancel(); + _languagesRequestId = _api->request(MTPlangpack_GetLanguages( MTP_string(CloudLangPackName()) )).done([=](const MTPVector &result) { auto languages = Languages(); @@ -402,10 +416,20 @@ void CloudManager::requestLanguageAndSwitch( return; } - request(_switchingToLanguageRequest).cancel(); - _switchingToLanguageRequest = request(MTPlangpack_GetLanguage( + _switchingToLanguageId = id; + _switchingToLanguageWarning = warning; + sendSwitchingToLanguageRequest(); +} + +void CloudManager::sendSwitchingToLanguageRequest() { + if (!_api) { + _switchingToLanguageId = -1; + return; + } + _api->request(_switchingToLanguageRequest).cancel(); + _switchingToLanguageRequest = _api->request(MTPlangpack_GetLanguage( MTP_string(Lang::CloudLangPackName()), - MTP_string(id) + MTP_string(_switchingToLanguageId) )).done([=](const MTPLangPackLanguage &result) { _switchingToLanguageRequest = 0; const auto language = Lang::ParseLanguage(result); @@ -416,7 +440,7 @@ void CloudManager::requestLanguageAndSwitch( performSwitchAndRestart(language); } }; - if (!warning) { + if (!_switchingToLanguageWarning) { finalize(); return; } @@ -438,9 +462,11 @@ void CloudManager::requestLanguageAndSwitch( void CloudManager::switchToLanguage(const Language &data) { if (_langpack.id() == data.id && data.id != qstr("#custom")) { return; + } else if (!_api) { + return; } - request(_switchingToLanguageRequest).cancel(); + _api->request(base::take(_getKeysForSwitchRequestId)).cancel(); if (data.id == qstr("#custom")) { performSwitchToCustom(); } else if (canApplyWithoutRestart(data.id)) { @@ -449,12 +475,12 @@ void CloudManager::switchToLanguage(const Language &data) { QVector keys; keys.reserve(3); keys.push_back(MTP_string("lng_sure_save_language")); - _switchingToLanguageRequest = request(MTPlangpack_GetStrings( + _getKeysForSwitchRequestId = _api->request(MTPlangpack_GetStrings( MTP_string(Lang::CloudLangPackName()), MTP_string(data.id), MTP_vector(std::move(keys)) )).done([=](const MTPVector &result) { - _switchingToLanguageRequest = 0; + _getKeysForSwitchRequestId = 0; const auto values = Instance::ParseStrings(result); const auto getValue = [&](ushort key) { auto it = values.find(key); @@ -473,7 +499,7 @@ void CloudManager::switchToLanguage(const Language &data) { [=] { performSwitchAndRestart(data); }), Ui::LayerOption::KeepOther); }).fail([=](const RPCError &error) { - _switchingToLanguageRequest = 0; + _getKeysForSwitchRequestId = 0; }).send(); } } @@ -481,7 +507,7 @@ void CloudManager::switchToLanguage(const Language &data) { void CloudManager::performSwitchToCustom() { auto filter = qsl("Language files (*.strings)"); auto title = qsl("Choose language .strings file"); - FileDialog::GetOpenPath(Core::App().getFileDialogParent(), title, filter, [weak = base::make_weak(this)](const FileDialog::OpenResult &result) { + FileDialog::GetOpenPath(Core::App().getFileDialogParent(), title, filter, [=, weak = base::make_weak(this)](const FileDialog::OpenResult &result) { if (!weak || result.paths.isEmpty()) { return; } @@ -491,9 +517,13 @@ void CloudManager::performSwitchToCustom() { filePath, { tr::lng_sure_save_language.base }); if (loader.errors().isEmpty()) { - weak->request(weak->_switchingToLanguageRequest).cancel(); - if (weak->canApplyWithoutRestart(qsl("#custom"))) { - weak->_langpack.switchToCustomFile(filePath); + if (_api) { + _api->request( + base::take(_switchingToLanguageRequest) + ).cancel(); + } + if (canApplyWithoutRestart(qsl("#custom"))) { + _langpack.switchToCustomFile(filePath); } else { const auto values = loader.found(); const auto getValue = [&](ushort key) { @@ -506,7 +536,7 @@ void CloudManager::performSwitchToCustom() { + "\n\n" + getValue(tr::lng_sure_save_language.base); const auto change = [=] { - weak->_langpack.switchToCustomFile(filePath); + _langpack.switchToCustomFile(filePath); App::restart(); }; Ui::show( @@ -572,9 +602,25 @@ void CloudManager::switchLangPackId(const Language &data) { void CloudManager::changeIdAndReInitConnection(const Language &data) { _langpack.switchToId(data); + if (_api) { + const auto mtproto = _api->instance(); + mtproto->reInitConnection(mtproto->mainDcId()); + } +} - auto mtproto = requestMTP(); - mtproto->reInitConnection(mtproto->mainDcId()); +void CloudManager::resendRequests() { + if (packRequestId(Pack::Base)) { + requestLangPackDifference(Pack::Base); + } + if (packRequestId(Pack::Current)) { + requestLangPackDifference(Pack::Current); + } + if (_languagesRequestId) { + requestLanguageList(); + } + if (_switchingToLanguageRequest) { + sendSwitchingToLanguageRequest(); + } } CloudManager &CurrentCloudManager() { diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.h b/Telegram/SourceFiles/lang/lang_cloud_manager.h index f95b4854ab..d8b53deb84 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.h +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.h @@ -22,9 +22,9 @@ struct Language; Language ParseLanguage(const MTPLangPackLanguage &data); -class CloudManager : public base::has_weak_ptr, private MTP::Sender, private base::Subscriber { +class CloudManager : public base::has_weak_ptr, private base::Subscriber { public: - CloudManager(Instance &langpack, not_null mtproto); + explicit CloudManager(Instance &langpack); using Languages = std::vector; @@ -72,6 +72,10 @@ private: void switchLangPackId(const Language &data); void changeIdAndReInitConnection(const Language &data); + void sendSwitchingToLanguageRequest(); + void resendRequests(); + + std::optional _api; Instance &_langpack; Languages _languages; base::Observable _languagesChanged; @@ -87,6 +91,12 @@ private: base::Observable _firstLanguageSuggestion; mtpRequestId _switchingToLanguageRequest = 0; + QString _switchingToLanguageId; + bool _switchingToLanguageWarning = false; + + mtpRequestId _getKeysForSwitchRequestId = 0; + + rpl::lifetime _lifetime; }; diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp index faa11e7cc9..fcc3a8ad64 100644 --- a/Telegram/SourceFiles/main/main_account.cpp +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -498,16 +498,16 @@ rpl::producer<> Account::configUpdates() const { } void Account::resetAuthorizationKeys() { + _mtpValue = nullptr; _mtp = nullptr; - _mtpValue = _mtp.get(); startMtp(); Local::writeMtpData(); } void Account::clearMtp() { + _mtpValue = nullptr; _mtp = nullptr; _mtpForKeysDestroy = nullptr; - _mtpValue = _mtp.get(); } } // namespace Main diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.cpp index ced2d5b1dd..95b5404daf 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.cpp @@ -29,7 +29,8 @@ LoaderMtproto::LoaderMtproto( , _location(location) , _dcId(location.dcId()) , _size(size) -, _origin(origin) { +, _origin(origin) +, _api(_owner->api().instance()) { } LoaderMtproto::~LoaderMtproto() { @@ -68,7 +69,7 @@ void LoaderMtproto::stop() { crl::on_main(this, [=] { ranges::for_each( base::take(_requests), - _sender.requestCanceller(), + _api.requestCanceller(), &base::flat_map::value_type::second); _requested.clear(); }); @@ -82,7 +83,7 @@ void LoaderMtproto::cancel(int offset) { void LoaderMtproto::cancelForOffset(int offset) { if (const auto requestId = _requests.take(offset)) { - _sender.request(*requestId).cancel(); + _api.request(*requestId).cancel(); sendNext(); } else { _requested.remove(offset); @@ -122,7 +123,7 @@ void LoaderMtproto::sendNext() { changeRequestedAmount(index, kPartSize); const auto usedFileReference = _location.fileReference(); - const auto id = _sender.request(MTPupload_GetFile( + const auto id = _api.request(MTPupload_GetFile( MTP_flags(0), _location.tl(Auth().userId()), MTP_int(offset), diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.h b/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.h index 755e63dd9f..bd9d1ef0e8 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.h +++ b/Telegram/SourceFiles/media/streaming/media_streaming_loader_mtproto.h @@ -70,7 +70,7 @@ private: const int _size = 0; const Data::FileOrigin _origin; - MTP::Sender _sender; + MTP::Sender _api; PriorityQueue _requested; base::flat_map _requests; diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index 888728b9d5..5bef40a885 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -262,7 +262,7 @@ Instance::Private::Private( not_null instance, not_null options, Instance::Mode mode) -: Sender() +: Sender(instance) , _instance(instance) , _dcOptions(options) , _mode(mode) { diff --git a/Telegram/SourceFiles/mtproto/sender.h b/Telegram/SourceFiles/mtproto/sender.h index 3e1fd6c710..6d91b2914c 100644 --- a/Telegram/SourceFiles/mtproto/sender.h +++ b/Telegram/SourceFiles/mtproto/sender.h @@ -14,9 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace MTP { -class Instance; -Instance *MainInstance(); - class Sender { class RequestBuilder { public: @@ -104,11 +101,11 @@ class Sender { bool operator()(mtpRequestId requestId, const RPCError &error) override { if (_skipPolicy == FailSkipPolicy::Simple) { - if (MTP::isDefaultHandledError(error)) { + if (isDefaultHandledError(error)) { return false; } } else if (_skipPolicy == FailSkipPolicy::HandleFlood) { - if (MTP::isDefaultHandledError(error) && !MTP::isFloodError(error)) { + if (isDefaultHandledError(error) && !isFloodError(error)) { return false; } } @@ -195,7 +192,12 @@ class Sender { }; public: - Sender() noexcept { + explicit Sender(not_null instance) noexcept + : _instance(instance) { + } + + [[nodiscard]] not_null instance() const { + return _instance; } template @@ -245,7 +247,7 @@ public: } mtpRequestId send() { - const auto id = MainInstance()->send( + const auto id = sender()->instance()->send( _request, takeOnDone(), takeOnFail(), @@ -293,16 +295,13 @@ public: } void requestSendDelayed() { - MainInstance()->sendAnything(); + _instance->sendAnything(); } void requestCancellingDiscard() { for (auto &request : _requests) { request.handled(); } } - not_null requestMTP() const { - return MainInstance(); - } private: class RequestWrap { @@ -392,6 +391,7 @@ private: } } + const not_null _instance; base::flat_set _requests; }; diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index d43349366a..6d4e2c0fb2 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/file_upload.h" #include "storage/file_download.h" #include "app.h" +#include "apiwrap.h" #include #include @@ -620,6 +621,7 @@ FormController::FormController( not_null controller, const FormRequest &request) : _controller(controller) +, _api(_controller->session().api().instance()) , _request(PreprocessRequest(request)) , _shortPollTimer([=] { reloadPassword(); }) , _view(std::make_unique(this)) { @@ -741,7 +743,7 @@ std::vector> FormController::submitGetErrors() { credentialsEncryptedData.secret, bytes::make_span(_request.publicKey.toUtf8())); - _submitRequestId = request(MTPaccount_AcceptAuthorization( + _submitRequestId = _api.request(MTPaccount_AcceptAuthorization( MTP_int(_request.botId), MTP_string(_request.scope), MTP_string(_request.publicKey), @@ -808,8 +810,8 @@ void FormController::requestPasswordData(mtpRequestId &guard) { return passwordServerError(); } - request(base::take(guard)).cancel(); - guard = request( + _api.request(base::take(guard)).cancel(); + guard = _api.request( MTPaccount_GetPassword() ).done([=, &guard](const MTPaccount_Password &result) { guard = 0; @@ -843,7 +845,7 @@ void FormController::submitPassword( const Core::CloudPasswordResult &check, const QByteArray &password, bool submitSaved) { - _passwordCheckRequestId = request(MTPaccount_GetPasswordSettings( + _passwordCheckRequestId = _api.request(MTPaccount_GetPasswordSettings( check.result )).handleFloodErrors( ).done([=](const MTPaccount_PasswordSettings &result) { @@ -936,7 +938,7 @@ void FormController::checkSavedPasswordSettings( void FormController::checkSavedPasswordSettings( const Core::CloudPasswordResult &check, const SavedCredentials &credentials) { - _passwordCheckRequestId = request(MTPaccount_GetPasswordSettings( + _passwordCheckRequestId = _api.request(MTPaccount_GetPasswordSettings( check.result )).done([=](const MTPaccount_PasswordSettings &result) { Expects(result.type() == mtpc_account_passwordSettings); @@ -982,7 +984,7 @@ void FormController::recoverPassword() { } else if (_recoverRequestId) { return; } - _recoverRequestId = request(MTPauth_RequestPasswordRecovery( + _recoverRequestId = _api.request(MTPauth_RequestPasswordRecovery( )).done([=](const MTPauth_PasswordRecovery &result) { Expects(result.type() == mtpc_auth_passwordRecovery); @@ -1024,7 +1026,7 @@ void FormController::cancelPassword() { if (_passwordRequestId) { return; } - _passwordRequestId = request(MTPaccount_CancelPasswordEmail( + _passwordRequestId = _api.request(MTPaccount_CancelPasswordEmail( )).done([=](const MTPBool &result) { _passwordRequestId = 0; reloadPassword(); @@ -1093,7 +1095,7 @@ void FormController::resetSecret( const Core::CloudPasswordResult &check, const bytes::vector &password) { using Flag = MTPDaccount_passwordInputSettings::Flag; - _saveSecretRequestId = request(MTPaccount_UpdatePasswordSettings( + _saveSecretRequestId = _api.request(MTPaccount_UpdatePasswordSettings( check.result, MTP_account_passwordInputSettings( MTP_flags(Flag::f_new_secure_settings), @@ -1625,7 +1627,7 @@ void FormController::verify( nonconst->verification.requestId = [&] { switch (nonconst->type) { case Value::Type::Phone: - return request(MTPaccount_VerifyPhone( + return _api.request(MTPaccount_VerifyPhone( MTP_string(getPhoneFromValue(nonconst)), MTP_string(nonconst->verification.phoneCodeHash), MTP_string(prepared) @@ -1643,7 +1645,7 @@ void FormController::verify( } }).send(); case Value::Type::Email: - return request(MTPaccount_VerifyEmail( + return _api.request(MTPaccount_VerifyEmail( MTP_string(getEmailFromValue(nonconst)), MTP_string(prepared) )).done([=](const MTPBool &result) { @@ -1825,7 +1827,7 @@ void FormController::cancelValueVerification(not_null value) { void FormController::clearValueVerification(not_null value) { const auto was = (value->verification.codeLength != 0); if (const auto requestId = base::take(value->verification.requestId)) { - request(requestId).cancel(); + _api.request(requestId).cancel(); } value->verification = Verification(); if (was) { @@ -1872,7 +1874,7 @@ void FormController::deleteValueEdit(not_null value) { } const auto nonconst = findValue(value); - nonconst->saveRequestId = request(MTPaccount_DeleteSecureValue( + nonconst->saveRequestId = _api.request(MTPaccount_DeleteSecureValue( MTP_vector(1, ConvertType(nonconst->type)) )).done([=](const MTPBool &result) { resetValue(*nonconst); @@ -2019,7 +2021,7 @@ void FormController::sendSaveRequest( const MTPInputSecureValue &data) { Expects(value->saveRequestId == 0); - value->saveRequestId = request(MTPaccount_SaveSecureValue( + value->saveRequestId = _api.request(MTPaccount_SaveSecureValue( data, MTP_long(_secretId) )).done([=](const MTPSecureValue &result) { @@ -2092,7 +2094,7 @@ QString FormController::getPlainTextFromValue( } void FormController::startPhoneVerification(not_null value) { - value->verification.requestId = request(MTPaccount_SendVerifyPhoneCode( + value->verification.requestId = _api.request(MTPaccount_SendVerifyPhoneCode( MTP_string(getPhoneFromValue(value)), MTP_codeSettings(MTP_flags(0)) )).done([=](const MTPauth_SentCode &result) { @@ -2149,7 +2151,7 @@ void FormController::startPhoneVerification(not_null value) { } void FormController::startEmailVerification(not_null value) { - value->verification.requestId = request(MTPaccount_SendVerifyEmailCode( + value->verification.requestId = _api.request(MTPaccount_SendVerifyEmailCode( MTP_string(getEmailFromValue(value)) )).done([=](const MTPaccount_SentEmailCode &result) { Expects(result.type() == mtpc_account_sentEmailCode); @@ -2171,7 +2173,7 @@ void FormController::requestPhoneCall(not_null value) { value->verification.call->setStatus( { SentCodeCall::State::Calling, 0 }); - request(MTPauth_ResendCode( + _api.request(MTPauth_ResendCode( MTP_string(getPhoneFromValue(value)), MTP_string(value->verification.phoneCodeHash) )).done([=](const MTPauth_SentCode &code) { @@ -2222,7 +2224,7 @@ void FormController::saveSecret( saved.hashForSecret); using Flag = MTPDaccount_passwordInputSettings::Flag; - _saveSecretRequestId = request(MTPaccount_UpdatePasswordSettings( + _saveSecretRequestId = _api.request(MTPaccount_UpdatePasswordSettings( check.result, MTP_account_passwordInputSettings( MTP_flags(Flag::f_new_secure_settings), @@ -2270,7 +2272,7 @@ void FormController::requestForm() { formFail(NonceNameByScope(_request.scope).toUpper() + "_EMPTY"); return; } - _formRequestId = request(MTPaccount_GetAuthorizationForm( + _formRequestId = _api.request(MTPaccount_GetAuthorizationForm( MTP_int(_request.botId), MTP_string(_request.scope), MTP_string(_request.publicKey) @@ -2478,7 +2480,7 @@ void FormController::formDone(const MTPaccount_AuthorizationForm &result) { void FormController::requestConfig() { const auto hash = ConfigInstance().hash; - _configRequestId = request(MTPhelp_GetPassportConfig( + _configRequestId = _api.request(MTPhelp_GetPassportConfig( MTP_int(hash) )).done([=](const MTPhelp_PassportConfig &result) { _configRequestId = 0; @@ -2555,7 +2557,7 @@ void FormController::requestPassword() { if (_passwordRequestId) { return; } - _passwordRequestId = request(MTPaccount_GetPassword( + _passwordRequestId = _api.request(MTPaccount_GetPassword( )).done([=](const MTPaccount_Password &result) { _passwordRequestId = 0; passwordDone(result); diff --git a/Telegram/SourceFiles/passport/passport_form_controller.h b/Telegram/SourceFiles/passport/passport_form_controller.h index b7f56d4671..4ae25ac651 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.h +++ b/Telegram/SourceFiles/passport/passport_form_controller.h @@ -318,7 +318,7 @@ struct FileKey { }; -class FormController : private MTP::Sender, public base::has_weak_ptr { +class FormController : public base::has_weak_ptr { public: FormController( not_null controller, @@ -512,6 +512,7 @@ private: void shortPollEmailConfirmation(); not_null _controller; + MTP::Sender _api; FormRequest _request; UserData *_bot = nullptr; diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 6a15f9733f..5368c1ece4 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -180,7 +180,8 @@ AdminLog::OwnedItem GenerateForwardedItem( BlockedBoxController::BlockedBoxController( not_null window) -: _window(window) { +: _window(window) +, _api(_window->session().api().instance()) { } Main::Session &BlockedBoxController::session() const { @@ -220,7 +221,7 @@ void BlockedBoxController::loadMoreRows() { return; } - _loadRequestId = request(MTPcontacts_GetBlocked( + _loadRequestId = _api.request(MTPcontacts_GetBlocked( MTP_int(_offset), MTP_int(kBlockedPerPage) )).done([=](const MTPcontacts_Blocked &result) { diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index 1ba146bf8d..461b97b25b 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -16,8 +16,7 @@ namespace Settings { class BlockedBoxController : public PeerListController - , private base::Subscriber - , private MTP::Sender { + , private base::Subscriber { public: explicit BlockedBoxController( not_null window); @@ -39,6 +38,7 @@ private: std::unique_ptr createRow(not_null user) const; const not_null _window; + MTP::Sender _api; int _offset = 0; mtpRequestId _loadRequestId = 0; diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index 56e2d717d9..00d3cf6dc2 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -288,10 +288,11 @@ TimeId OccupiedBySomeoneTill(History *history) { Helper::Helper(not_null session) : _session(session) +, _api(_session->api().instance()) , _templates(_session) , _reoccupyTimer([=] { reoccupy(); }) , _checkOccupiedTimer([=] { checkOccupiedChats(); }) { - request(MTPhelp_GetSupportName( + _api.request(MTPhelp_GetSupportName( )).done([=](const MTPhelp_SupportName &result) { result.match([&](const MTPDhelp_supportName &data) { setSupportName(qs(data.vname())); @@ -422,7 +423,7 @@ bool Helper::isOccupiedBySomeone(History *history) const { } void Helper::refreshInfo(not_null user) { - request(MTPhelp_GetUserInfo( + _api.request(MTPhelp_GetUserInfo( user->inputUser )).done([=](const MTPhelp_UserInfo &result) { applyInfo(user, result); @@ -531,7 +532,7 @@ void Helper::saveInfo( return; } else { i->second.data = text; - request(base::take(i->second.requestId)).cancel(); + _api.request(base::take(i->second.requestId)).cancel(); } } else { _userInfoSaving.emplace(user, SavingInfo{ text }); @@ -545,7 +546,7 @@ void Helper::saveInfo( const auto entities = Api::EntitiesToMTP( text.entities, Api::ConvertOption::SkipLocal); - _userInfoSaving[user].requestId = request(MTPhelp_EditUserInfo( + _userInfoSaving[user].requestId = _api.request(MTPhelp_EditUserInfo( user->inputUser, MTP_string(text.text), entities diff --git a/Telegram/SourceFiles/support/support_helper.h b/Telegram/SourceFiles/support/support_helper.h index e3cde4971b..46cf1b468a 100644 --- a/Telegram/SourceFiles/support/support_helper.h +++ b/Telegram/SourceFiles/support/support_helper.h @@ -39,7 +39,7 @@ inline bool operator!=(const UserInfo &a, const UserInfo &b) { return !(a == b); } -class Helper : private MTP::Sender { +class Helper final { public: explicit Helper(not_null session); @@ -87,6 +87,7 @@ private: Fn done); not_null _session; + MTP::Sender _api; Templates _templates; QString _supportName; QString _supportNameNormalized;