Use finalIndex in row changes.

pull/1/head
Matthew Chen 8 years ago
parent bb22adbeba
commit 658746093d

@ -2889,20 +2889,25 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
for (YapDatabaseViewRowChange *rowChange in rowChanges) { for (YapDatabaseViewRowChange *rowChange in rowChanges) {
switch (rowChange.type) { switch (rowChange.type) {
case YapDatabaseViewChangeDelete: { case YapDatabaseViewChangeDelete: {
DDLogVerbose(@"YapDatabaseViewChangeDelete: %@, %@", rowChange.collectionKey, rowChange.indexPath); DDLogVerbose(@"YapDatabaseViewChangeDelete: %@, %@, %zd",
rowChange.collectionKey,
rowChange.indexPath,
rowChange.finalIndex);
[self.collectionView deleteItemsAtIndexPaths:@[ rowChange.indexPath ]]; [self.collectionView deleteItemsAtIndexPaths:@[ rowChange.indexPath ]];
YapCollectionKey *collectionKey = rowChange.collectionKey; YapCollectionKey *collectionKey = rowChange.collectionKey;
OWSAssert(collectionKey.key.length > 0); OWSAssert(collectionKey.key.length > 0);
break; break;
} }
case YapDatabaseViewChangeInsert: { case YapDatabaseViewChangeInsert: {
DDLogVerbose( DDLogVerbose(@"YapDatabaseViewChangeInsert: %@, %@, %zd",
@"YapDatabaseViewChangeInsert: %@, %@", rowChange.collectionKey, rowChange.newIndexPath); rowChange.collectionKey,
rowChange.newIndexPath,
rowChange.finalIndex);
[self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]]; [self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]];
// We don't want to reload a row that we just inserted. // 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]]) { if ([viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction; TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction;
if (!outgoingMessage.isFromLinkedDevice) { if (!outgoingMessage.isFromLinkedDevice) {
@ -2913,21 +2918,25 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
break; break;
} }
case YapDatabaseViewChangeMove: { case YapDatabaseViewChangeMove: {
DDLogVerbose(@"YapDatabaseViewChangeMove: %@, %@, %@", DDLogVerbose(@"YapDatabaseViewChangeMove: %@, %@, %@, %zd",
rowChange.collectionKey, rowChange.collectionKey,
rowChange.indexPath, rowChange.indexPath,
rowChange.newIndexPath); rowChange.newIndexPath,
rowChange.finalIndex);
[self.collectionView deleteItemsAtIndexPaths:@[ rowChange.indexPath ]]; [self.collectionView deleteItemsAtIndexPaths:@[ rowChange.indexPath ]];
[self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]]; [self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]];
// We don't want to reload a row that we just moved. // We don't want to reload a row that we just moved.
[rowsThatChangedSize removeObject:@(rowChange.newIndexPath.row)]; [rowsThatChangedSize removeObject:@(rowChange.finalIndex)];
break; break;
} }
case YapDatabaseViewChangeUpdate: { case YapDatabaseViewChangeUpdate: {
DDLogVerbose(@"YapDatabaseViewChangeUpdate: %@, %@", rowChange.collectionKey, rowChange.indexPath); DDLogVerbose(@"YapDatabaseViewChangeUpdate: %@, %@, %zd",
rowChange.collectionKey,
rowChange.indexPath,
rowChange.finalIndex);
[self.collectionView reloadItemsAtIndexPaths:@[ rowChange.indexPath ]]; [self.collectionView reloadItemsAtIndexPaths:@[ rowChange.indexPath ]];
// We don't want to reload a row that we've already reloaded. // We don't want to reload a row that we've already reloaded.
[rowsThatChangedSize removeObject:@(rowChange.indexPath.row)]; [rowsThatChangedSize removeObject:@(rowChange.finalIndex)];
break; break;
} }
} }
@ -2987,13 +2996,13 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
break; break;
case YapDatabaseViewChangeInsert: { case YapDatabaseViewChangeInsert: {
isOnlyUpdatingLastOutgoingMessage = NO; isOnlyUpdatingLastOutgoingMessage = NO;
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:rowChange.newIndexPath.row]; ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex];
if ([viewItem.interaction isKindOfClass:[TSOutgoingMessage class]] if ([viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]
&& rowChange.newIndexPath.row >= (NSInteger)oldViewItemCount) { && rowChange.finalIndex >= oldViewItemCount) {
continue; continue;
} }
if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.newIndexPath.row) { if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) {
lastNonUpdateRow = @(rowChange.newIndexPath.row); lastNonUpdateRow = @(rowChange.finalIndex);
} }
} }
case YapDatabaseViewChangeMove: case YapDatabaseViewChangeMove:
@ -3002,13 +3011,13 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.indexPath.row) { if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.indexPath.row) {
lastNonUpdateRow = @(rowChange.indexPath.row); lastNonUpdateRow = @(rowChange.indexPath.row);
} }
if (!lastNonUpdateRow || lastNonUpdateRow.integerValue < rowChange.newIndexPath.row) { if (!lastNonUpdateRow || lastNonUpdateRow.unsignedIntegerValue < rowChange.finalIndex) {
lastNonUpdateRow = @(rowChange.newIndexPath.row); lastNonUpdateRow = @(rowChange.finalIndex);
} }
break; break;
case YapDatabaseViewChangeUpdate: { case YapDatabaseViewChangeUpdate: {
isOnlyInsertingNewOutgoingMessages = NO; isOnlyInsertingNewOutgoingMessages = NO;
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:rowChange.indexPath.row]; ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex];
if (![viewItem.interaction isKindOfClass:[TSOutgoingMessage class]] if (![viewItem.interaction isKindOfClass:[TSOutgoingMessage class]]
|| rowChange.indexPath.row != (NSInteger)(oldViewItemCount - 1)) { || rowChange.indexPath.row != (NSInteger)(oldViewItemCount - 1)) {
isOnlyUpdatingLastOutgoingMessage = NO; isOnlyUpdatingLastOutgoingMessage = NO;

@ -245,6 +245,10 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{ actionBlock:^{
[DebugUIMessages performRandomActions:100 thread:thread]; [DebugUIMessages performRandomActions:100 thread:thread];
}], }],
[OWSTableItem itemWithTitle:@"Perform 1,000 random actions"
actionBlock:^{
[DebugUIMessages performRandomActions:1000 thread:thread];
}],
] mutableCopy]; ] mutableCopy];
if ([thread isKindOfClass:[TSContactThread class]]) { if ([thread isKindOfClass:[TSContactThread class]]) {
TSContactThread *contactThread = (TSContactThread *)thread; TSContactThread *contactThread = (TSContactThread *)thread;

Loading…
Cancel
Save