Fix saved music page-after-page loading.

This commit is contained in:
John Preston
2025-10-03 13:47:33 +04:00
parent 71443f7def
commit fbfe47528b
3 changed files with 15 additions and 12 deletions
+10 -9
View File
@@ -260,7 +260,8 @@ void SavedMusic::loadMore(PeerId peerId, bool reload) {
musicIdToMsg(peerId, entry, document));
}
}
entry.loaded = list.empty() || (count == entry.list.size());
entry.loaded = list.empty()
|| (entry.total == entry.list.size());
});
_changed.fire_copy(peerId);
}).fail([=](const MTP::Error &error) {
@@ -332,24 +333,24 @@ rpl::producer<SavedMusicSlice> SavedMusicList(
if (i == end(loaded)) {
i = begin(loaded);
}
const auto hasBefore = int(i - begin(loaded));
const auto hasAfter = int(end(loaded) - i);
if (hasAfter < limit) {
const auto hasAfter = int(i - begin(loaded));
const auto hasBefore = int(end(loaded) - i);
if (hasBefore < limit) {
savedMusic->loadMore(peerId);
}
const auto takeBefore = std::min(hasBefore, limit);
const auto takeAfter = std::min(hasAfter, limit);
const auto takeBefore = std::min(hasBefore, limit);
auto ids = std::vector<not_null<HistoryItem*>>();
ids.reserve(takeBefore + takeAfter);
for (auto j = i - takeBefore; j != i + takeAfter; ++j) {
ids.reserve(takeAfter + takeBefore);
for (auto j = i - takeAfter; j != i + takeBefore; ++j) {
ids.push_back(*j);
}
const auto added = int(ids.size());
state->slice = SavedMusicSlice(
std::move(ids),
count,
(hasBefore - takeBefore),
count - hasBefore - added);
count - (hasAfter - takeAfter) - added,
hasAfter - takeAfter);
consumer.put_next_copy(state->slice);
};
const auto schedule = [=] {
@@ -63,7 +63,7 @@ rpl::producer<StoriesIdsSlice> AlbumStoriesIds(
std::move(ids),
count,
(hasBefore - takeBefore),
count - hasBefore - added);
count - (hasBefore - takeBefore) - added);
consumer.put_next_copy(state->slice);
};
const auto schedule = [=] {
@@ -120,7 +120,9 @@ void MusicProvider::checkPreload(
const auto visibleWidth = viewport.width();
const auto visibleHeight = viewport.height();
const auto preloadedHeight = kPreloadedScreensCountFull * visibleHeight;
const auto minItemHeight = MinStoryHeight(visibleWidth);
const auto minItemHeight = MinItemHeight(
Type::MusicFile,
visibleWidth);
const auto preloadedCount = preloadedHeight / minItemHeight;
const auto preloadIdsLimitMin = (preloadedCount / 2) + 1;
const auto preloadIdsLimit = preloadIdsLimitMin
@@ -165,7 +167,7 @@ void MusicProvider::setSearchQuery(QString query) {
void MusicProvider::refreshViewer() {
_viewerLifetime.destroy();
const auto aroundId = _aroundId;
auto ids = Data::SavedMusicList(_peer, aroundId, _idsLimit);
auto ids = Data::SavedMusicList(_peer, aroundId, _idsLimit);
std::move(
ids
) | rpl::start_with_next([=](Data::SavedMusicSlice &&slice) {