Fix long conversation crash the right way

This commit is contained in:
Niels Andriesse 2021-04-19 09:35:09 +10:00
parent 0296416b1a
commit 8a54a243a4
4 changed files with 28 additions and 19 deletions

View File

@ -149,7 +149,8 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
Storage.read { transaction in
unreadCount = self.thread.unreadMessageCount(transaction: transaction)
}
unreadViewItems = unreadCount != 0 ? [ConversationViewItem](viewItems[viewItems.endIndex - Int(unreadCount) ..< viewItems.endIndex]) : []
let clampedUnreadCount = min(unreadCount, UInt(kConversationInitialMaxRangeSize))
unreadViewItems = clampedUnreadCount != 0 ? [ConversationViewItem](viewItems[viewItems.endIndex - Int(clampedUnreadCount) ..< viewItems.endIndex]) : []
}
required init?(coder: NSCoder) {

View File

@ -91,6 +91,24 @@ typedef NS_ENUM(NSUInteger, ConversationUpdateItemType) {
#pragma mark -
// Always load up to n messages when user arrives.
//
// The smaller this number is, the faster the conversation can display.
// To test, shrink you accessibility font as much as possible, then count how many 1-line system info messages (our
// shortest cells) can fit on screen at a time on an iPhoneX
//
// PERF: we could do less messages on shorter (older, slower) devices
// PERF: we could cache the cell height, since some messages will be much taller.
static const int kYapDatabasePageSize = 250;
// Never show more than n messages in conversation view when user arrives.
static const int kConversationInitialMaxRangeSize = 250;
// Never show more than n messages in conversation view at a time.
static const int kYapDatabaseRangeMaxLength = 250;
#pragma mark -
@interface ConversationViewModel : NSObject
@property (nonatomic, readonly) ConversationViewState *viewState;

View File

@ -162,24 +162,6 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark -
// Always load up to n messages when user arrives.
//
// The smaller this number is, the faster the conversation can display.
// To test, shrink you accessibility font as much as possible, then count how many 1-line system info messages (our
// shortest cells) can fit on screen at a time on an iPhoneX
//
// PERF: we could do less messages on shorter (older, slower) devices
// PERF: we could cache the cell height, since some messages will be much taller.
static const int kYapDatabasePageSize = 25000;
// Never show more than n messages in conversation view when user arrives.
static const int kConversationInitialMaxRangeSize = 25000;
// Never show more than n messages in conversation view at a time.
static const int kYapDatabaseRangeMaxLength = 25000;
#pragma mark -
@interface ConversationViewModel ()
@property (nonatomic, weak) id<ConversationViewModelDelegate> delegate;

View File

@ -198,6 +198,14 @@ NS_ASSUME_NONNULL_BEGIN
visibleUnseenMessageCount++;
interactionAfterUnreadIndicator = interaction;
if (visibleUnseenMessageCount + 1 >= maxRangeSize) {
// If there are more unseen messages than can be displayed in the
// messages view, show the unread indicator at the top of the
// displayed messages.
*stop = YES;
hasMoreUnseenMessages = YES;
}
}];
if (!interactionAfterUnreadIndicator) {