diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 576d99c4b..3aef4ace3 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -970,7 +970,7 @@ void PeerListBox::Inner::loadProfilePhotos() { void PeerListBox::Inner::checkScrollForPreload() { if (_visibleBottom + PreloadHeightsCount * (_visibleBottom - _visibleTop) > height()) { - _controller->preloadRows(); + _controller->loadMoreRows(); } } diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index e7f08733d..6aafced06 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -219,6 +219,7 @@ class PeerListSearchController { public: virtual void searchQuery(const QString &query) = 0; virtual bool isLoading() = 0; + virtual bool loadMoreRows() = 0; virtual ~PeerListSearchController() = default; void setDelegate(gsl::not_null delegate) { @@ -249,7 +250,7 @@ public: virtual void rowClicked(gsl::not_null row) = 0; virtual void rowActionClicked(gsl::not_null row) { } - virtual void preloadRows() { + virtual void loadMoreRows() { } bool isSearchLoading() const { return _searchController ? _searchController->isLoading() : false; @@ -276,6 +277,9 @@ protected: gsl::not_null delegate() const { return _delegate; } + PeerListSearchController *searchController() const { + return _searchController.get(); + } void setDescriptionText(const QString &text); void setSearchLoadingText(const QString &text); @@ -541,6 +545,9 @@ public: void searchQuery(const QString &query) override; bool isLoading() override; + bool loadMoreRows() override { + return false; + } private: bool searchInCache(); diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index 852c9a915..f17aea6e5 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -205,10 +205,10 @@ void BoxController::prepare() { setDescriptionText(lang(lng_contacts_loading)); delegate()->peerListRefreshRows(); - preloadRows(); + loadMoreRows(); } -void BoxController::preloadRows() { +void BoxController::loadMoreRows() { if (_loadRequestId || _allLoaded) { return; } diff --git a/Telegram/SourceFiles/calls/calls_box_controller.h b/Telegram/SourceFiles/calls/calls_box_controller.h index 36868d1d7..e32c99891 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.h +++ b/Telegram/SourceFiles/calls/calls_box_controller.h @@ -29,7 +29,7 @@ public: void prepare() override; void rowClicked(gsl::not_null row) override; void rowActionClicked(gsl::not_null row) override; - void preloadRows() override; + void loadMoreRows() override; private: void receivedCalls(const QVector &result); diff --git a/Telegram/SourceFiles/profile/profile_block_settings.cpp b/Telegram/SourceFiles/profile/profile_block_settings.cpp index 14d7b879a..68b5f5777 100644 --- a/Telegram/SourceFiles/profile/profile_block_settings.cpp +++ b/Telegram/SourceFiles/profile/profile_block_settings.cpp @@ -33,8 +33,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "apiwrap.h" #include "lang/lang_keys.h" -#include "mainwindow.h" // tmp - namespace Profile { namespace { @@ -46,6 +44,7 @@ public: void searchQuery(const QString &query) override; bool isLoading() override; + bool loadMoreRows() override; private: bool searchInCache(); @@ -62,7 +61,33 @@ private: int _offset = 0; bool _allLoaded = false; std::map _cache; - std::map _queries; + std::map> _queries; // query, offset + +}; + +class BlockedBoxController : public PeerListController, private base::Subscriber, private MTP::Sender, public base::enable_weak_from_this { +public: + BlockedBoxController(gsl::not_null channel, bool restricted); + + void prepare() override; + void rowClicked(gsl::not_null row) override; + void rowActionClicked(gsl::not_null row) override; + void loadMoreRows() override; + + void peerListSearchAddRow(gsl::not_null peer) override; + +private: + bool appendRow(UserData *user); + bool prependRow(UserData *user); + std::unique_ptr createRow(UserData *user) const; + + gsl::not_null _channel; + bool _restricted = false; + int _offset = 0; + mtpRequestId _loadRequestId = 0; + bool _allLoaded = false; + std::map _rights; + QPointer _editBox; }; @@ -78,6 +103,7 @@ void BlockedBoxSearchController::searchQuery(const QString &query) { _query = query; _offset = 0; _requestId = 0; + _allLoaded = false; if (!_query.isEmpty() && !searchInCache()) { _timer.callOnce(AutoSearchTimeout); } else { @@ -98,17 +124,7 @@ bool BlockedBoxSearchController::searchInCache() { void BlockedBoxSearchController::searchOnServer() { Expects(!_query.isEmpty()); - auto filter = _restricted ? MTP_channelParticipantsBanned(MTP_string(_query)) : MTP_channelParticipantsKicked(MTP_string(_query)); - _requestId = request(MTPchannels_GetParticipants(_channel->inputChannel, filter , MTP_int(_offset), MTP_int(kBlockedPerPage))).done([this](const MTPchannels_ChannelParticipants &result, mtpRequestId requestId) { - searchDone(result, requestId); - }).fail([this](const RPCError &error, mtpRequestId requestId) { - if (_requestId == requestId) { - _requestId = 0; - _allLoaded = true; - delegate()->peerListSearchRefreshRows(); - } - }).send(); - _queries.emplace(_requestId, _query); + loadMoreRows(); } void BlockedBoxSearchController::searchDone(const MTPchannels_ChannelParticipants &result, mtpRequestId requestId) { @@ -120,8 +136,10 @@ void BlockedBoxSearchController::searchDone(const MTPchannels_ChannelParticipant App::feedUsers(participants.vusers); auto it = _queries.find(requestId); if (it != _queries.cend()) { - query = it->second; - _cache[query] = result; + query = it->second.first; // query + if (it->second.second == 0) { // offset + _cache[query] = result; + } _queries.erase(it); } } @@ -155,34 +173,25 @@ bool BlockedBoxSearchController::isLoading() { return _timer.isActive() || _requestId; } -class BlockedBoxController : public PeerListController, private base::Subscriber, private MTP::Sender, public base::enable_weak_from_this { -public: - BlockedBoxController(gsl::not_null channel, bool restricted); - - void prepare() override; - void rowClicked(gsl::not_null row) override; - void rowActionClicked(gsl::not_null row) override; - void preloadRows() override; - bool searchInLocal() override { +bool BlockedBoxSearchController::loadMoreRows() { + if (_query.isEmpty()) { return false; } - - void peerListSearchAddRow(gsl::not_null peer) override; - -private: - bool appendRow(UserData *user); - bool prependRow(UserData *user); - std::unique_ptr createRow(UserData *user) const; - - gsl::not_null _channel; - bool _restricted = false; - int _offset = 0; - mtpRequestId _loadRequestId = 0; - bool _allLoaded = false; - std::map _rights; - QPointer _editBox; - -}; + if (!_allLoaded && !isLoading()) { + auto filter = _restricted ? MTP_channelParticipantsBanned(MTP_string(_query)) : MTP_channelParticipantsKicked(MTP_string(_query)); + _requestId = request(MTPchannels_GetParticipants(_channel->inputChannel, filter, MTP_int(_offset), MTP_int(kBlockedPerPage))).done([this](const MTPchannels_ChannelParticipants &result, mtpRequestId requestId) { + searchDone(result, requestId); + }).fail([this](const RPCError &error, mtpRequestId requestId) { + if (_requestId == requestId) { + _requestId = 0; + _allLoaded = true; + delegate()->peerListSearchRefreshRows(); + } + }).send(); + _queries.emplace(_requestId, std::make_pair(_query, _offset)); + } + return true; +} void BlockedBoxController::peerListSearchAddRow(gsl::not_null peer) { PeerListController::peerListSearchAddRow(peer); @@ -203,10 +212,13 @@ void BlockedBoxController::prepare() { setSearchNoResultsText(lang(lng_blocked_list_not_found)); delegate()->peerListRefreshRows(); - preloadRows(); + loadMoreRows(); } -void BlockedBoxController::preloadRows() { +void BlockedBoxController::loadMoreRows() { + if (searchController()->loadMoreRows()) { + return; + } if (_loadRequestId || _allLoaded) { return; } @@ -269,10 +281,10 @@ void BlockedBoxController::rowActionClicked(gsl::not_null row) { if (rights.c_channelBannedRights().vflags.v == 0 || rights.c_channelBannedRights().is_view_messages()) { if (auto row = weak->delegate()->peerListFindRow(user->id)) { weak->delegate()->peerListRemoveRow(row); - weak->delegate()->peerListRefreshRows(); if (!weak->delegate()->peerListFullRowsCount()) { weak->setDescriptionText(lang(lng_blocked_list_not_found)); } + weak->delegate()->peerListRefreshRows(); } } else { weak->_rights[user] = rights; diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index db77713c6..972f1d344 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -104,10 +104,10 @@ void BlockedBoxController::prepare() { } })); - preloadRows(); + loadMoreRows(); } -void BlockedBoxController::preloadRows() { +void BlockedBoxController::loadMoreRows() { if (_loadRequestId || _allLoaded) { return; } diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index f172c2a49..550e06d30 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -31,7 +31,7 @@ public: void prepare() override; void rowClicked(gsl::not_null row) override; void rowActionClicked(gsl::not_null row) override; - void preloadRows() override; + void loadMoreRows() override; static void BlockNewUser();