From 79eafbe71a38c3ccfbb5e7752aa17801c6d7d7ec Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 14 Aug 2016 22:15:45 +0300 Subject: [PATCH] Overview filling fix when you scroll the history down till the bottom. --- Telegram/SourceFiles/history.cpp | 45 +++++++++++++++++++------------- Telegram/SourceFiles/history.h | 3 +++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 6d4076dd12..095603bec3 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -1345,24 +1345,8 @@ void History::addNewerSlice(const QVector &slice) { } } - if (!wasLoadedAtBottom && loadedAtBottom()) { // add all loaded photos to overview - int32 mask = 0; - for (int32 i = 0; i < OverviewCount; ++i) { - if (overviewCountData[i] == 0) continue; // all loaded - if (!overview[i].isEmpty() || !overviewIds[i].isEmpty()) { - overview[i].clear(); - overviewIds[i].clear(); - mask |= (1 << i); - } - } - for_const (HistoryBlock *block, blocks) { - for_const (HistoryItem *item, block->items) { - mask |= item->addToOverview(AddToOverviewBack); - } - } - for (int32 t = 0; t < OverviewCount; ++t) { - if ((mask & (1 << t)) && App::wnd()) App::wnd()->mediaOverviewUpdated(peer, MediaOverviewType(t)); - } + if (!wasLoadedAtBottom) { + checkAddAllToOverview(); } if (isChannel()) asChannelHistory()->checkJoinedMessage(); @@ -1373,12 +1357,37 @@ void History::checkLastMsg() { if (lastMsg) { if (!newLoaded && !lastMsg->detached()) { newLoaded = true; + checkAddAllToOverview(); } } else if (newLoaded) { setLastMessage(lastImportantMessage()); } } +void History::checkAddAllToOverview() { + if (!loadedAtBottom()) { + return; + } + + int32 mask = 0; + for (int32 i = 0; i < OverviewCount; ++i) { + if (overviewCountData[i] == 0) continue; // all loaded + if (!overview[i].isEmpty() || !overviewIds[i].isEmpty()) { + overview[i].clear(); + overviewIds[i].clear(); + mask |= (1 << i); + } + } + for_const (HistoryBlock *block, blocks) { + for_const (HistoryItem *item, block->items) { + mask |= item->addToOverview(AddToOverviewBack); + } + } + for (int32 t = 0; t < OverviewCount; ++t) { + if ((mask & (1 << t)) && App::wnd()) App::wnd()->mediaOverviewUpdated(peer, MediaOverviewType(t)); + } +} + int History::countUnread(MsgId upTo) { int result = 0; for (auto i = blocks.cend(), e = blocks.cbegin(); i != e;) { diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index 484e670905..ca8bd5ca91 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -494,6 +494,9 @@ private: // After adding a new history slice check the lastMsg and newLoaded. void checkLastMsg(); + // Add all items to the media overview if we were not loaded at bottom and now are. + void checkAddAllToOverview(); + enum class Flag { f_has_pending_resized_items = (1 << 0), f_pending_resize = (1 << 1),