mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Ensure message view range is properly truncated with view is configured.
// FREEBIE
This commit is contained in:
parent
51d11cdcc6
commit
57b76b3411
1 changed files with 37 additions and 5 deletions
|
@ -112,6 +112,12 @@ typedef enum : NSUInteger {
|
||||||
kMediaTypeVideo,
|
kMediaTypeVideo,
|
||||||
} kMediaTypes;
|
} kMediaTypes;
|
||||||
|
|
||||||
|
typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
|
||||||
|
// This mode should only be used when initially configuring the range,
|
||||||
|
// since we want the range to monotonically grow after that.
|
||||||
|
MessagesRangeSizeMode_Truncate,
|
||||||
|
MessagesRangeSizeMode_Normal
|
||||||
|
};
|
||||||
@protocol OWSMessagesCollectionViewFlowLayoutDelegate <NSObject>
|
@protocol OWSMessagesCollectionViewFlowLayoutDelegate <NSObject>
|
||||||
|
|
||||||
// Returns YES for all but the unread indicator
|
// Returns YES for all but the unread indicator
|
||||||
|
@ -424,7 +430,7 @@ typedef enum : NSUInteger {
|
||||||
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||||
[self.messageMappings updateWithTransaction:transaction];
|
[self.messageMappings updateWithTransaction:transaction];
|
||||||
}];
|
}];
|
||||||
[self updateMessageMappingRangeOptions];
|
[self updateMessageMappingRangeOptions:MessagesRangeSizeMode_Truncate];
|
||||||
[self updateShouldObserveDBModifications];
|
[self updateShouldObserveDBModifications];
|
||||||
self.page = 0;
|
self.page = 0;
|
||||||
|
|
||||||
|
@ -640,6 +646,25 @@ typedef enum : NSUInteger {
|
||||||
|
|
||||||
- (NSIndexPath *_Nullable)indexPathOfUnreadMessagesIndicator
|
- (NSIndexPath *_Nullable)indexPathOfUnreadMessagesIndicator
|
||||||
{
|
{
|
||||||
|
__block TSUnreadIndicatorInteraction *_Nullable unreadIndicator = nil;
|
||||||
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||||
|
[[TSDatabaseView threadSpecialMessagesDatabaseView:transaction]
|
||||||
|
enumerateRowsInGroup:self.thread.uniqueId
|
||||||
|
usingBlock:^(
|
||||||
|
NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) {
|
||||||
|
|
||||||
|
if ([object isKindOfClass:[TSUnreadIndicatorInteraction class]]) {
|
||||||
|
unreadIndicator = (TSUnreadIndicatorInteraction *)object;
|
||||||
|
*stop = YES;
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}];
|
||||||
|
|
||||||
|
if (!unreadIndicator) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: We could do binary search.
|
||||||
int numberOfMessages = (int)[self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
|
int numberOfMessages = (int)[self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
|
||||||
for (int i = 0; i < numberOfMessages; i++) {
|
for (int i = 0; i < numberOfMessages; i++) {
|
||||||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
|
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
|
||||||
|
@ -2388,17 +2413,24 @@ typedef enum : NSUInteger {
|
||||||
[self setShowLoadEarlierMessagesHeader:[self shouldShowLoadEarlierMessages]];
|
[self setShowLoadEarlierMessagesHeader:[self shouldShowLoadEarlierMessages]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateMessageMappingRangeOptions
|
- (void)updateMessageMappingRangeOptions:(MessagesRangeSizeMode)mode
|
||||||
{
|
{
|
||||||
// The "old" range length may have been increased by insertions of new messages
|
// The "old" range length may have been increased by insertions of new messages
|
||||||
// at the bottom of the window.
|
// at the bottom of the window.
|
||||||
NSUInteger oldLength = [self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
|
NSUInteger oldLength = [self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
|
||||||
|
|
||||||
|
NSUInteger targetLength = oldLength;
|
||||||
|
if (mode == MessagesRangeSizeMode_Truncate) {
|
||||||
|
// During the initial configuration of the view, we want to truncate the
|
||||||
|
targetLength = MIN(targetLength, (NSUInteger)(kYapDatabasePageSize * kYapDatabaseMaxInitialPageCount));
|
||||||
|
}
|
||||||
|
|
||||||
// The "page-based" range length may have been increased by loading "prev" pages at the
|
// The "page-based" range length may have been increased by loading "prev" pages at the
|
||||||
// top of the window.
|
// top of the window.
|
||||||
NSUInteger rangeLength;
|
NSUInteger rangeLength;
|
||||||
while (YES) {
|
while (YES) {
|
||||||
rangeLength = kYapDatabasePageSize * (self.page + 1);
|
rangeLength = kYapDatabasePageSize * (self.page + 1);
|
||||||
if (rangeLength >= oldLength) {
|
if (rangeLength >= targetLength) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
self.page = self.page + 1;
|
self.page = self.page + 1;
|
||||||
|
@ -3425,7 +3457,7 @@ typedef enum : NSUInteger {
|
||||||
// range that are not within the current mapping's contents. We
|
// range that are not within the current mapping's contents. We
|
||||||
// may need to extend the mapping's contents to reflect the current
|
// may need to extend the mapping's contents to reflect the current
|
||||||
// range.
|
// range.
|
||||||
[self updateMessageMappingRangeOptions];
|
[self updateMessageMappingRangeOptions:MessagesRangeSizeMode_Normal];
|
||||||
[self resetContentAndLayout];
|
[self resetContentAndLayout];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -4350,7 +4382,7 @@ typedef enum : NSUInteger {
|
||||||
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||||
[self.messageMappings updateWithTransaction:transaction];
|
[self.messageMappings updateWithTransaction:transaction];
|
||||||
}];
|
}];
|
||||||
[self updateMessageMappingRangeOptions];
|
[self updateMessageMappingRangeOptions:MessagesRangeSizeMode_Normal];
|
||||||
}
|
}
|
||||||
|
|
||||||
self.messageAdapterCache = [[NSCache alloc] init];
|
self.messageAdapterCache = [[NSCache alloc] init];
|
||||||
|
|
Loading…
Reference in a new issue