diff --git a/Telegram/SourceFiles/info/boosts/giveaway/giveaway_list_controllers.cpp b/Telegram/SourceFiles/info/boosts/giveaway/giveaway_list_controllers.cpp index f65fda97d8..975dab5b3e 100644 --- a/Telegram/SourceFiles/info/boosts/giveaway/giveaway_list_controllers.cpp +++ b/Telegram/SourceFiles/info/boosts/giveaway/giveaway_list_controllers.cpp @@ -9,9 +9,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "data/data_channel.h" +#include "data/data_folder.h" #include "data/data_peer.h" #include "data/data_session.h" #include "data/data_user.h" +#include "dialogs/dialogs_indexed_list.h" +#include "history/history.h" #include "lang/lang_keys.h" #include "main/main_session.h" #include "ui/boxes/confirm_box.h" @@ -156,7 +159,26 @@ MyChannelsListController::MyChannelsListController( std::make_unique(&peer->session())) , _peer(peer) , _show(show) -, _selected(std::move(selected)) { +, _selected(std::move(selected)) +, _otherChannels(std::make_unique>>()) { + { + const auto addList = [&](not_null list) { + for (const auto &row : list->all()) { + if (const auto history = row->history()) { + const auto channel = history->peer->asChannel(); + if (channel && !channel->isMegagroup()) { + _otherChannels->push_back(channel); + } + } + } + }; + auto &data = _peer->owner(); + addList(data.chatsList()->indexed()); + if (const auto folder = data.folderLoaded(Data::Folder::kId)) { + addList(folder->chatsList()->indexed()); + } + addList(data.contactsNoChatsList()); + } } std::unique_ptr MyChannelsListController::createSearchRow( @@ -175,6 +197,24 @@ std::unique_ptr MyChannelsListController::createRestoredRow( return nullptr; } +void MyChannelsListController::loadMoreRows() { + if (_apiLifetime || !_otherChannels) { + return; + } else if (_lastAddedIndex >= _otherChannels->size()) { + _otherChannels.release(); + return; + } + constexpr auto kPerPage = int(40); + const auto till = std::min( + int(_otherChannels->size()), + _lastAddedIndex + kPerPage); + while (_lastAddedIndex < till) { + delegate()->peerListAppendRow( + createRow(_otherChannels->at(_lastAddedIndex++))); + } + delegate()->peerListRefreshRows(); +} + void MyChannelsListController::rowClicked(not_null row) { const auto channel = row->peer()->asChannel(); const auto checked = !row->checked(); diff --git a/Telegram/SourceFiles/info/boosts/giveaway/giveaway_list_controllers.h b/Telegram/SourceFiles/info/boosts/giveaway/giveaway_list_controllers.h index 8f3f44ecf0..6459d6d8fd 100644 --- a/Telegram/SourceFiles/info/boosts/giveaway/giveaway_list_controllers.h +++ b/Telegram/SourceFiles/info/boosts/giveaway/giveaway_list_controllers.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/edit_participants_box.h" +class ChannelData; class PeerData; class PeerListRow; @@ -60,6 +61,7 @@ public: Main::Session &session() const override; void prepare() override; void rowClicked(not_null row) override; + void loadMoreRows() override; std::unique_ptr createSearchRow( not_null peer) override; @@ -76,6 +78,8 @@ private: Fn _checkErrorCallback; std::vector> _selected; + std::unique_ptr>> _otherChannels; + int _lastAddedIndex = 0; rpl::lifetime _apiLifetime;