From 658746093deec074023deb90753effab35643983 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 17 Nov 2017 10:49:34 -0500 Subject: [PATCH] Use finalIndex in row changes. --- .../ConversationViewController.m | 43 +++++++++++-------- .../ViewControllers/DebugUI/DebugUIMessages.m | 4 ++ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 1b874ca7f..956efb530 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -2889,20 +2889,25 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { for (YapDatabaseViewRowChange *rowChange in rowChanges) { switch (rowChange.type) { case YapDatabaseViewChangeDelete: { - DDLogVerbose(@"YapDatabaseViewChangeDelete: %@, %@", rowChange.collectionKey, rowChange.indexPath); + DDLogVerbose(@"YapDatabaseViewChangeDelete: %@, %@, %zd", + rowChange.collectionKey, + rowChange.indexPath, + rowChange.finalIndex); [self.collectionView deleteItemsAtIndexPaths:@[ rowChange.indexPath ]]; YapCollectionKey *collectionKey = rowChange.collectionKey; OWSAssert(collectionKey.key.length > 0); break; } case YapDatabaseViewChangeInsert: { - DDLogVerbose( - @"YapDatabaseViewChangeInsert: %@, %@", rowChange.collectionKey, rowChange.newIndexPath); + DDLogVerbose(@"YapDatabaseViewChangeInsert: %@, %@, %zd", + rowChange.collectionKey, + rowChange.newIndexPath, + rowChange.finalIndex); [self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]]; // We don't want to reload a row that we just inserted. - [rowsThatChangedSize removeObject:@(rowChange.newIndexPath.row)]; + [rowsThatChangedSize removeObject:@(rowChange.finalIndex)]; - ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:rowChange.newIndexPath.row]; + ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex]; if ([viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]) { TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction; if (!outgoingMessage.isFromLinkedDevice) { @@ -2913,21 +2918,25 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { break; } case YapDatabaseViewChangeMove: { - DDLogVerbose(@"YapDatabaseViewChangeMove: %@, %@, %@", + DDLogVerbose(@"YapDatabaseViewChangeMove: %@, %@, %@, %zd", rowChange.collectionKey, rowChange.indexPath, - rowChange.newIndexPath); + rowChange.newIndexPath, + rowChange.finalIndex); [self.collectionView deleteItemsAtIndexPaths:@[ rowChange.indexPath ]]; [self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]]; // We don't want to reload a row that we just moved. - [rowsThatChangedSize removeObject:@(rowChange.newIndexPath.row)]; + [rowsThatChangedSize removeObject:@(rowChange.finalIndex)]; break; } case YapDatabaseViewChangeUpdate: { - DDLogVerbose(@"YapDatabaseViewChangeUpdate: %@, %@", rowChange.collectionKey, rowChange.indexPath); + DDLogVerbose(@"YapDatabaseViewChangeUpdate: %@, %@, %zd", + rowChange.collectionKey, + rowChange.indexPath, + rowChange.finalIndex); [self.collectionView reloadItemsAtIndexPaths:@[ rowChange.indexPath ]]; // We don't want to reload a row that we've already reloaded. - [rowsThatChangedSize removeObject:@(rowChange.indexPath.row)]; + [rowsThatChangedSize removeObject:@(rowChange.finalIndex)]; break; } } @@ -2987,13 +2996,13 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { break; case YapDatabaseViewChangeInsert: { isOnlyUpdatingLastOutgoingMessage = NO; - ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:rowChange.newIndexPath.row]; + ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex]; if ([viewItem.interaction isKindOfClass:[TSOutgoingMessage class]] - && rowChange.newIndexPath.row >= (NSInteger)oldViewItemCount) { + && rowChange.finalIndex >= oldViewItemCount) { continue; } - if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.newIndexPath.row) { - lastNonUpdateRow = @(rowChange.newIndexPath.row); + if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) { + lastNonUpdateRow = @(rowChange.finalIndex); } } case YapDatabaseViewChangeMove: @@ -3002,13 +3011,13 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.indexPath.row) { lastNonUpdateRow = @(rowChange.indexPath.row); } - if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.newIndexPath.row) { - lastNonUpdateRow = @(rowChange.newIndexPath.row); + if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) { + lastNonUpdateRow = @(rowChange.finalIndex); } break; case YapDatabaseViewChangeUpdate: { isOnlyInsertingNewOutgoingMessages = NO; - ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:rowChange.indexPath.row]; + ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex]; if (![viewItem.interaction isKindOfClass:[TSOutgoingMessage class]] || rowChange.indexPath.row != (NSInteger)(oldViewItemCount - 1)) { isOnlyUpdatingLastOutgoingMessage = NO; diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index f40e35f72..177b03067 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -245,6 +245,10 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ [DebugUIMessages performRandomActions:100 thread:thread]; }], + [OWSTableItem itemWithTitle:@"Perform 1,000 random actions" + actionBlock:^{ + [DebugUIMessages performRandomActions:1000 thread:thread]; + }], ] mutableCopy]; if ([thread isKindOfClass:[TSContactThread class]]) { TSContactThread *contactThread = (TSContactThread *)thread;