mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge branch 'mkirk/fix-collectionview-crash'
This commit is contained in:
commit
63c94efc86
2 changed files with 59 additions and 17 deletions
|
@ -3402,20 +3402,20 @@ typedef enum : NSUInteger {
|
||||||
for (YapDatabaseViewRowChange *rowChange in rowChanges) {
|
for (YapDatabaseViewRowChange *rowChange in rowChanges) {
|
||||||
switch (rowChange.type) {
|
switch (rowChange.type) {
|
||||||
case YapDatabaseViewChangeDelete: {
|
case YapDatabaseViewChangeDelete: {
|
||||||
DDLogVerbose(@"YapDatabaseViewChangeDelete: %@, %@, %zd",
|
DDLogVerbose(@"YapDatabaseViewChangeDelete collectionKey: %@, indexPath: %@, finalIndex: %lu",
|
||||||
rowChange.collectionKey,
|
rowChange.collectionKey,
|
||||||
rowChange.indexPath,
|
rowChange.indexPath,
|
||||||
rowChange.finalIndex);
|
(unsigned long)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(@"YapDatabaseViewChangeInsert: %@, %@, %zd",
|
DDLogVerbose(@"YapDatabaseViewChangeInsert collectionKey: %@, newIndexPath: %@, finalIndex: %lu",
|
||||||
rowChange.collectionKey,
|
rowChange.collectionKey,
|
||||||
rowChange.newIndexPath,
|
rowChange.newIndexPath,
|
||||||
rowChange.finalIndex);
|
(unsigned long)rowChange.finalIndex);
|
||||||
[self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]];
|
[self.collectionView insertItemsAtIndexPaths:@[ rowChange.newIndexPath ]];
|
||||||
|
|
||||||
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex];
|
ConversationViewItem *_Nullable viewItem = [self viewItemForIndex:(NSInteger)rowChange.finalIndex];
|
||||||
|
@ -3429,19 +3429,20 @@ typedef enum : NSUInteger {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case YapDatabaseViewChangeMove: {
|
case YapDatabaseViewChangeMove: {
|
||||||
DDLogVerbose(@"YapDatabaseViewChangeMove: %@, %@, %@, %zd",
|
DDLogVerbose(@"YapDatabaseViewChangeMove collectionKey: %@, indexPath: %@, newIndexPath: %@, "
|
||||||
|
@"finalIndex: %lu",
|
||||||
rowChange.collectionKey,
|
rowChange.collectionKey,
|
||||||
rowChange.indexPath,
|
rowChange.indexPath,
|
||||||
rowChange.newIndexPath,
|
rowChange.newIndexPath,
|
||||||
rowChange.finalIndex);
|
(unsigned long)rowChange.finalIndex);
|
||||||
[self.collectionView moveItemAtIndexPath:rowChange.indexPath toIndexPath:rowChange.newIndexPath];
|
[self.collectionView moveItemAtIndexPath:rowChange.indexPath toIndexPath:rowChange.newIndexPath];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case YapDatabaseViewChangeUpdate: {
|
case YapDatabaseViewChangeUpdate: {
|
||||||
DDLogVerbose(@"YapDatabaseViewChangeUpdate: %@, %@, %zd",
|
DDLogVerbose(@"YapDatabaseViewChangeUpdate collectionKey: %@, indexPath: %@, finalIndex: %lu",
|
||||||
rowChange.collectionKey,
|
rowChange.collectionKey,
|
||||||
rowChange.indexPath,
|
rowChange.indexPath,
|
||||||
rowChange.finalIndex);
|
(unsigned long)rowChange.finalIndex);
|
||||||
[self.collectionView reloadItemsAtIndexPaths:@[ rowChange.indexPath ]];
|
[self.collectionView reloadItemsAtIndexPaths:@[ rowChange.indexPath ]];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3466,16 +3467,31 @@ typedef enum : NSUInteger {
|
||||||
[self scrollToBottomAnimated:shouldAnimateScrollToBottom];
|
[self scrollToBottomAnimated:shouldAnimateScrollToBottom];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (shouldAnimateUpdates) {
|
if (shouldAnimateUpdates) {
|
||||||
[self.collectionView performBatchUpdates:batchUpdates completion:batchUpdatesCompletion];
|
[self.collectionView performBatchUpdates:batchUpdates completion:batchUpdatesCompletion];
|
||||||
} else {
|
} else {
|
||||||
[UIView performWithoutAnimation:^{
|
// HACK: We use `UIView.animateWithDuration:0` rather than `UIView.performWithAnimation` to work around a UIKit
|
||||||
[self.collectionView performBatchUpdates:batchUpdates completion:batchUpdatesCompletion];
|
// Crash like:
|
||||||
if (scrollToBottom) {
|
//
|
||||||
[self scrollToBottomAnimated:NO];
|
// *** Assertion failure in -[ConversationViewLayout prepareForCollectionViewUpdates:],
|
||||||
}
|
// /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UICollectionViewLayout.m:760
|
||||||
}];
|
// *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'While
|
||||||
|
// preparing update a visible view at <NSIndexPath: 0xc000000011c00016> {length = 2, path = 0 - 142} wasn't
|
||||||
|
// found in the current data model and was not in an update animation. This is an internal error.'
|
||||||
|
//
|
||||||
|
// I'm unclear if this is a bug in UIKit, or if we're doing something crazy in
|
||||||
|
// ConversationViewLayout#prepareLayout. To reproduce, rapidily insert and delete items into the conversation.
|
||||||
|
// See `DebugUIMessages#thrashCellsInThread:`
|
||||||
|
[UIView animateWithDuration:0.0
|
||||||
|
animations:^{
|
||||||
|
[self.collectionView performBatchUpdates:batchUpdates completion:batchUpdatesCompletion];
|
||||||
|
if (scrollToBottom) {
|
||||||
|
[self scrollToBottomAnimated:shouldAnimateUpdates];
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
self.lastReloadDate = [NSDate new];
|
self.lastReloadDate = [NSDate new];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,10 +85,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
actionBlock:^{
|
actionBlock:^{
|
||||||
[DebugUIMessages deleteAllMessagesInThread:thread];
|
[DebugUIMessages deleteAllMessagesInThread:thread];
|
||||||
}]];
|
}]];
|
||||||
[items addObject:[OWSTableItem itemWithTitle:@"👷 Send All Contact Shares"
|
[items addObject:[OWSTableItem itemWithTitle:@"👷 Thrash insert/deletes"
|
||||||
actionBlock:^{
|
actionBlock:^{
|
||||||
[DebugUIMessages sendAllContacts:thread];
|
[DebugUIMessages thrashInsertAndDeleteForThread:(TSThread *)thread
|
||||||
|
counter:300];
|
||||||
}]];
|
}]];
|
||||||
|
|
||||||
[items addObjectsFromArray:[self itemsForActions:@[
|
[items addObjectsFromArray:[self itemsForActions:@[
|
||||||
[DebugUIMessages fakeAllContactShareAction:thread],
|
[DebugUIMessages fakeAllContactShareAction:thread],
|
||||||
[DebugUIMessages sendMessageVariationsAction:thread],
|
[DebugUIMessages sendMessageVariationsAction:thread],
|
||||||
|
@ -126,6 +128,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
actionBlock:^{
|
actionBlock:^{
|
||||||
[DebugUIMessages selectSendMediaAction:thread];
|
[DebugUIMessages selectSendMediaAction:thread];
|
||||||
}],
|
}],
|
||||||
|
[OWSTableItem itemWithTitle:@"Send All Contact Shares"
|
||||||
|
actionBlock:^{
|
||||||
|
[DebugUIMessages sendAllContacts:thread];
|
||||||
|
}],
|
||||||
[OWSTableItem itemWithTitle:@"Select Quoted Reply"
|
[OWSTableItem itemWithTitle:@"Select Quoted Reply"
|
||||||
actionBlock:^{
|
actionBlock:^{
|
||||||
[DebugUIMessages selectQuotedReplyAction:thread];
|
[DebugUIMessages selectQuotedReplyAction:thread];
|
||||||
|
@ -3111,7 +3117,7 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
|
||||||
OWSAssert(thread);
|
OWSAssert(thread);
|
||||||
|
|
||||||
return
|
return
|
||||||
[DebugUIMessagesGroupAction allGroupActionWithLabel:@"👷 All Fake Contact Shares"
|
[DebugUIMessagesGroupAction allGroupActionWithLabel:@"All Fake Contact Shares"
|
||||||
subactions:[self allFakeContactShareActions:thread includeLabels:YES]];
|
subactions:[self allFakeContactShareActions:thread includeLabels:YES]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3700,6 +3706,26 @@ typedef OWSContact * (^OWSContactBlock)(YapDatabaseReadWriteTransaction *transac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (void)thrashInsertAndDeleteForThread:(TSThread *)thread counter:(NSUInteger)counter
|
||||||
|
{
|
||||||
|
if (counter == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t sendDelay = arc4random_uniform((uint32_t)(0.01 * NSEC_PER_SEC));
|
||||||
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, sendDelay), dispatch_get_main_queue(), ^{
|
||||||
|
[self sendFakeMessages:1 thread:thread];
|
||||||
|
});
|
||||||
|
|
||||||
|
uint32_t deleteDelay = arc4random_uniform((uint32_t)(0.01 * NSEC_PER_SEC));
|
||||||
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, deleteDelay), dispatch_get_main_queue(), ^{
|
||||||
|
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection
|
||||||
|
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||||
|
[self deleteRandomMessages:1 thread:thread transaction:transaction];
|
||||||
|
}];
|
||||||
|
[self thrashInsertAndDeleteForThread:thread counter:counter - 1];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Remove.
|
// TODO: Remove.
|
||||||
+ (void)sendFakeMessages:(NSUInteger)counter
|
+ (void)sendFakeMessages:(NSUInteger)counter
|
||||||
thread:(TSThread *)thread
|
thread:(TSThread *)thread
|
||||||
|
|
Loading…
Reference in a new issue