2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-01 23:25:15 +00:00

Register streaming loaders in Storage::Downloader.

This commit is contained in:
John Preston
2019-04-12 14:50:41 +04:00
parent cca906d383
commit b2895a39ed
11 changed files with 158 additions and 98 deletions

View File

@@ -36,8 +36,9 @@ constexpr auto kMaxWebFileQueries = 8;
} // namespace
Downloader::Downloader()
: _killDownloadSessionsTimer([=] { killDownloadSessions(); })
Downloader::Downloader(not_null<ApiWrap*> api)
: _api(api)
, _killDownloadSessionsTimer([=] { killDownloadSessions(); })
, _queueForWeb(kMaxWebFileQueries) {
}
@@ -48,14 +49,16 @@ void Downloader::clearPriorities() {
void Downloader::requestedAmountIncrement(MTP::DcId dcId, int index, int amount) {
Expects(index >= 0 && index < MTP::kDownloadSessionsCount);
using namespace rpl::mappers;
auto it = _requestedBytesAmount.find(dcId);
if (it == _requestedBytesAmount.cend()) {
it = _requestedBytesAmount.emplace(dcId, RequestedInDc { { 0 } }).first;
}
it->second[index] += amount;
if (it->second[index]) {
if (amount > 0) {
killDownloadSessionsStop(dcId);
} else {
} else if (ranges::find_if(it->second, _1 > 0) == end(it->second)) {
killDownloadSessionsStart(dcId);
}
}