From 20889d7003456ff282e0e724b501871187f25a34 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Jan 2018 13:51:35 +0300 Subject: [PATCH] Mark history as having pending resized items. --- Telegram/SourceFiles/history/history.cpp | 58 ++----------------- Telegram/SourceFiles/history/history.h | 2 +- .../history/history_inner_widget.cpp | 34 +++++++++-- .../history/view/history_view_element.cpp | 3 + 4 files changed, 38 insertions(+), 59 deletions(-) diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index b9e18a9562..98d88dc01a 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1525,43 +1525,18 @@ void History::addOlderSlice(const QVector &slice) { return; } - auto firstAdded = (HistoryItem*)nullptr; - auto lastAdded = (HistoryItem*)nullptr; - - auto logged = QStringList(); - logged.push_back(QString::number(minMsgId())); - logged.push_back(QString::number(maxMsgId())); - if (const auto added = createItems(slice); !added.empty()) { - auto minAdded = -1; - auto maxAdded = -1; - startBuildingFrontBlock(added.size()); for (const auto item : added) { addItemToBlock(item); - if (minAdded < 0 || minAdded > item->id) { - minAdded = item->id; - } - if (maxAdded < 0 || maxAdded < item->id) { - maxAdded = item->id; - } } - auto block = finishBuildingFrontBlock(); + finishBuildingFrontBlock(); if (loadedAtBottom()) { // Add photos to overview and authors to lastAuthors. addItemsToLists(added); } - - logged.push_back(QString::number(minAdded)); - logged.push_back(QString::number(maxAdded)); - CrashReports::SetAnnotation( - "old_minmaxwas_minmaxadd", - logged.join(";")); - addToSharedMedia(added); - - CrashReports::ClearAnnotation("old_minmaxwas_minmaxadd"); } else { // If no items were added it means we've loaded everything old. oldLoaded = true; @@ -1588,32 +1563,11 @@ void History::addNewerSlice(const QVector &slice) { if (const auto added = createItems(slice); !added.empty()) { Assert(!isBuildingFrontBlock()); - auto logged = QStringList(); - logged.push_back(QString::number(minMsgId())); - logged.push_back(QString::number(maxMsgId())); - - auto minAdded = -1; - auto maxAdded = -1; - for (const auto item : added) { addItemToBlock(item); - if (minAdded < 0 || minAdded > item->id) { - minAdded = item->id; - } - if (maxAdded < 0 || maxAdded < item->id) { - maxAdded = item->id; - } } - logged.push_back(QString::number(minAdded)); - logged.push_back(QString::number(maxAdded)); - CrashReports::SetAnnotation( - "new_minmaxwas_minmaxadd", - logged.join(";")); - addToSharedMedia(added); - - CrashReports::ClearAnnotation("new_minmaxwas_minmaxadd"); } else { newLoaded = true; setLastMessage(lastAvailableMessage()); @@ -2153,12 +2107,11 @@ void History::startBuildingFrontBlock(int expectedItemsCount) { _buildingFrontBlock->expectedItemsCount = expectedItemsCount; } -HistoryBlock *History::finishBuildingFrontBlock() { - Assert(isBuildingFrontBlock()); +void History::finishBuildingFrontBlock() { + Expects(isBuildingFrontBlock()); // Some checks if there was some message history already - auto block = _buildingFrontBlock->block; - if (block) { + if (const auto block = base::take(_buildingFrontBlock)->block) { if (blocks.size() > 1) { // ... item, item, item, last ], [ first, item, item ... const auto last = block->messages.back().get(); @@ -2171,9 +2124,6 @@ HistoryBlock *History::finishBuildingFrontBlock() { block->messages.back()->nextInBlocksRemoved(); } } - - _buildingFrontBlock = nullptr; - return block; } void History::clearNotifications() { diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index c8bfdfd58c..d83e30b741 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -424,7 +424,7 @@ protected: // Only when we scroll up and add a new slice to the // front we want to create a new front block. void startBuildingFrontBlock(int expectedItemsCount = 1); - HistoryBlock *finishBuildingFrontBlock(); // Returns the built block or nullptr if nothing was added. + void finishBuildingFrontBlock(); bool isBuildingFrontBlock() const { return _buildingFrontBlock != nullptr; } diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index ceec8194e7..db1f2308b6 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -253,12 +253,38 @@ void HistoryInner::enumerateItemsInHistory(History *history, int historytop, Met for (const auto &logBlock : history->blocks) { QStringList debugItems; for (const auto &logItem : logBlock->messages) { - debugItems.push_back(QString("%1,%2").arg(logItem->y()).arg(logItem->height())); + debugItems.push_back(QString("%1,%2" + ).arg(logItem->y() + ).arg(logItem->height() + )); } - debug.push_back(QString("b(%1,%2:%3)").arg(logBlock->y()).arg(logBlock->height()).arg(debugItems.join(';'))); + debug.push_back(QString("b(%1,%2:%3)" + ).arg(logBlock->y() + ).arg(logBlock->height() + ).arg(debugItems.join(';') + )); } - CrashReports::SetAnnotation("geometry", QString("height:%1 ").arg(history->height()) + debug.join(';')); - CrashReports::SetAnnotation("info", QString("block:%1(%2,%3), item:%4(%5,%6), limits:%7,%8").arg(blockIndex).arg(block->y()).arg(block->height()).arg(itemIndex).arg(view->y()).arg(view->height()).arg(_visibleAreaTop).arg(_visibleAreaBottom)); + CrashReports::SetAnnotation( + "geometry", + QString("height:%1 " + ).arg(history->height() + ) + debug.join(';')); + CrashReports::SetAnnotation( + "info", + QString("block:%1(%2,%3), " + "item:%4(%5,%6), " + "limits:%7,%8, " + "has:%9" + ).arg(blockIndex + ).arg(block->y() + ).arg(block->height() + ).arg(itemIndex + ).arg(view->y() + ).arg(view->height() + ).arg(_visibleAreaTop + ).arg(_visibleAreaBottom + ).arg(Logs::b(history->hasPendingResizedItems()) + )); Unexpected("itembottom > _visibleAreaTop"); } Assert(itembottom > _visibleAreaTop); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index e9bb6779d7..c4e2c9f814 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -137,6 +137,9 @@ Element::Element( , _context(delegate->elementContext()) { Auth().data().registerItemView(this); refreshMedia(); + if (_context == Context::History) { + _data->_history->setHasPendingResizedItems(); + } } not_null Element::delegate() const {