Mark history as having pending resized items.

This commit is contained in:
John Preston 2018-01-30 13:51:35 +03:00
parent d4f4698c69
commit 20889d7003
4 changed files with 38 additions and 59 deletions

View File

@ -1525,43 +1525,18 @@ void History::addOlderSlice(const QVector<MTPMessage> &slice) {
return; 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()) { if (const auto added = createItems(slice); !added.empty()) {
auto minAdded = -1;
auto maxAdded = -1;
startBuildingFrontBlock(added.size()); startBuildingFrontBlock(added.size());
for (const auto item : added) { for (const auto item : added) {
addItemToBlock(item); 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()) { if (loadedAtBottom()) {
// Add photos to overview and authors to lastAuthors. // Add photos to overview and authors to lastAuthors.
addItemsToLists(added); addItemsToLists(added);
} }
logged.push_back(QString::number(minAdded));
logged.push_back(QString::number(maxAdded));
CrashReports::SetAnnotation(
"old_minmaxwas_minmaxadd",
logged.join(";"));
addToSharedMedia(added); addToSharedMedia(added);
CrashReports::ClearAnnotation("old_minmaxwas_minmaxadd");
} else { } else {
// If no items were added it means we've loaded everything old. // If no items were added it means we've loaded everything old.
oldLoaded = true; oldLoaded = true;
@ -1588,32 +1563,11 @@ void History::addNewerSlice(const QVector<MTPMessage> &slice) {
if (const auto added = createItems(slice); !added.empty()) { if (const auto added = createItems(slice); !added.empty()) {
Assert(!isBuildingFrontBlock()); 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) { for (const auto item : added) {
addItemToBlock(item); 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); addToSharedMedia(added);
CrashReports::ClearAnnotation("new_minmaxwas_minmaxadd");
} else { } else {
newLoaded = true; newLoaded = true;
setLastMessage(lastAvailableMessage()); setLastMessage(lastAvailableMessage());
@ -2153,12 +2107,11 @@ void History::startBuildingFrontBlock(int expectedItemsCount) {
_buildingFrontBlock->expectedItemsCount = expectedItemsCount; _buildingFrontBlock->expectedItemsCount = expectedItemsCount;
} }
HistoryBlock *History::finishBuildingFrontBlock() { void History::finishBuildingFrontBlock() {
Assert(isBuildingFrontBlock()); Expects(isBuildingFrontBlock());
// Some checks if there was some message history already // Some checks if there was some message history already
auto block = _buildingFrontBlock->block; if (const auto block = base::take(_buildingFrontBlock)->block) {
if (block) {
if (blocks.size() > 1) { if (blocks.size() > 1) {
// ... item, item, item, last ], [ first, item, item ... // ... item, item, item, last ], [ first, item, item ...
const auto last = block->messages.back().get(); const auto last = block->messages.back().get();
@ -2171,9 +2124,6 @@ HistoryBlock *History::finishBuildingFrontBlock() {
block->messages.back()->nextInBlocksRemoved(); block->messages.back()->nextInBlocksRemoved();
} }
} }
_buildingFrontBlock = nullptr;
return block;
} }
void History::clearNotifications() { void History::clearNotifications() {

View File

@ -424,7 +424,7 @@ protected:
// Only when we scroll up and add a new slice to the // Only when we scroll up and add a new slice to the
// front we want to create a new front block. // front we want to create a new front block.
void startBuildingFrontBlock(int expectedItemsCount = 1); void startBuildingFrontBlock(int expectedItemsCount = 1);
HistoryBlock *finishBuildingFrontBlock(); // Returns the built block or nullptr if nothing was added. void finishBuildingFrontBlock();
bool isBuildingFrontBlock() const { bool isBuildingFrontBlock() const {
return _buildingFrontBlock != nullptr; return _buildingFrontBlock != nullptr;
} }

View File

@ -253,12 +253,38 @@ void HistoryInner::enumerateItemsInHistory(History *history, int historytop, Met
for (const auto &logBlock : history->blocks) { for (const auto &logBlock : history->blocks) {
QStringList debugItems; QStringList debugItems;
for (const auto &logItem : logBlock->messages) { 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(
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)); "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"); Unexpected("itembottom > _visibleAreaTop");
} }
Assert(itembottom > _visibleAreaTop); Assert(itembottom > _visibleAreaTop);

View File

@ -137,6 +137,9 @@ Element::Element(
, _context(delegate->elementContext()) { , _context(delegate->elementContext()) {
Auth().data().registerItemView(this); Auth().data().registerItemView(this);
refreshMedia(); refreshMedia();
if (_context == Context::History) {
_data->_history->setHasPendingResizedItems();
}
} }
not_null<ElementDelegate*> Element::delegate() const { not_null<ElementDelegate*> Element::delegate() const {