Fix edge cases in the unseen indicator.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 226a975859
commit b5f5599774

@ -1095,8 +1095,6 @@ typedef enum : NSUInteger {
selector:@selector(scrollToDefaultPosition) selector:@selector(scrollToDefaultPosition)
userInfo:nil userInfo:nil
repeats:NO]; repeats:NO];
[self markVisibleMessagesAsRead];
} }
- (NSIndexPath *_Nullable)indexPathOfUnreadMessagesIndicator - (NSIndexPath *_Nullable)indexPathOfUnreadMessagesIndicator
@ -1344,6 +1342,8 @@ typedef enum : NSUInteger {
[self updateNavigationBarSubtitleLabel]; [self updateNavigationBarSubtitleLabel];
[MarkIdentityAsSeenJob runWithThread:self.thread]; [MarkIdentityAsSeenJob runWithThread:self.thread];
[ProfileFetcherJob runWithThread:self.thread networkManager:self.networkManager]; [ProfileFetcherJob runWithThread:self.thread networkManager:self.networkManager];
[self markVisibleMessagesAsRead];
} }
- (void)viewWillDisappear:(BOOL)animated - (void)viewWillDisappear:(BOOL)animated

@ -167,17 +167,15 @@ NS_ASSUME_NONNULL_BEGIN
// have been marked as read. // have been marked as read.
// //
// IFF this variable is non-null, there are unseen messages in the thread. // IFF this variable is non-null, there are unseen messages in the thread.
NSNumber *firstUnseenInteractionTimestamp = nil;
if (firstUnseenInteractionTimestampParameter) { if (firstUnseenInteractionTimestampParameter) {
firstUnseenInteractionTimestamp = firstUnseenInteractionTimestampParameter; result.firstUnseenInteractionTimestamp = firstUnseenInteractionTimestampParameter;
} else { } else {
TSInteraction *firstUnseenInteraction = TSInteraction *firstUnseenInteraction =
[[transaction ext:TSUnseenDatabaseViewExtensionName] firstObjectInGroup:thread.uniqueId]; [[transaction ext:TSUnseenDatabaseViewExtensionName] firstObjectInGroup:thread.uniqueId];
if (firstUnseenInteraction) { if (firstUnseenInteraction) {
firstUnseenInteractionTimestamp = @(firstUnseenInteraction.timestampForSorting); result.firstUnseenInteractionTimestamp = @(firstUnseenInteraction.timestampForSorting);
} }
} }
result.firstUnseenInteractionTimestamp = firstUnseenInteractionTimestamp;
TSIncomingMessage *firstIncomingMessage = TSIncomingMessage *firstIncomingMessage =
[[transaction ext:TSThreadIncomingMessageDatabaseViewExtensionName] firstObjectInGroup:thread.uniqueId]; [[transaction ext:TSThreadIncomingMessageDatabaseViewExtensionName] firstObjectInGroup:thread.uniqueId];
@ -196,7 +194,7 @@ NS_ASSUME_NONNULL_BEGIN
__block BOOL hasMoreUnseenMessages = NO; __block BOOL hasMoreUnseenMessages = NO;
__block TSInteraction *interactionAfterUnreadIndicator = nil; __block TSInteraction *interactionAfterUnreadIndicator = nil;
NSUInteger missingUnseenSafetyNumberChangeCount = 0; NSUInteger missingUnseenSafetyNumberChangeCount = 0;
if (firstUnseenInteractionTimestamp != nil) { if (result.firstUnseenInteractionTimestamp != nil) {
[[transaction ext:TSMessageDatabaseViewExtensionName] [[transaction ext:TSMessageDatabaseViewExtensionName]
enumerateRowsInGroup:thread.uniqueId enumerateRowsInGroup:thread.uniqueId
withOptions:NSEnumerationReverse withOptions:NSEnumerationReverse
@ -220,7 +218,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
if (interaction.timestampForSorting if (interaction.timestampForSorting
< firstUnseenInteractionTimestamp.unsignedLongLongValue) { < result.firstUnseenInteractionTimestamp.unsignedLongLongValue) {
// By default we want the unread indicator to appear just before // By default we want the unread indicator to appear just before
// the first unread message. // the first unread message.
*stop = YES; *stop = YES;
@ -246,7 +244,7 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableSet<NSData *> *missingUnseenSafetyNumberChanges = [NSMutableSet set]; NSMutableSet<NSData *> *missingUnseenSafetyNumberChanges = [NSMutableSet set];
for (TSInvalidIdentityKeyErrorMessage *safetyNumberChange in blockingSafetyNumberChanges) { for (TSInvalidIdentityKeyErrorMessage *safetyNumberChange in blockingSafetyNumberChanges) {
BOOL isUnseen = safetyNumberChange.timestampForSorting BOOL isUnseen = safetyNumberChange.timestampForSorting
>= firstUnseenInteractionTimestamp.unsignedLongLongValue; >= result.firstUnseenInteractionTimestamp.unsignedLongLongValue;
if (!isUnseen) { if (!isUnseen) {
continue; continue;
} }
@ -264,10 +262,11 @@ NS_ASSUME_NONNULL_BEGIN
= (missingUnseenSafetyNumberChanges.count + nonBlockingSafetyNumberChanges.count); = (missingUnseenSafetyNumberChanges.count + nonBlockingSafetyNumberChanges.count);
} }
} }
if (hasMoreUnseenMessages) { if (result.firstUnseenInteractionTimestamp) {
// The unread indicator is _before_ the last visible unseen message. // The unread indicator is _before_ the last visible unseen message.
result.unreadIndicatorPosition = @(visibleUnseenMessageCount); result.unreadIndicatorPosition = @(visibleUnseenMessageCount);
} }
OWSAssert((result.firstUnseenInteractionTimestamp != nil) == (result.unreadIndicatorPosition != nil));
TSMessage *firstMessage = firstIncomingMessage; TSMessage *firstMessage = firstIncomingMessage;
if (!firstMessage if (!firstMessage
@ -399,7 +398,10 @@ NS_ASSUME_NONNULL_BEGIN
missingUnseenSafetyNumberChangeCount:missingUnseenSafetyNumberChangeCount]; missingUnseenSafetyNumberChangeCount:missingUnseenSafetyNumberChangeCount];
[indicator saveWithTransaction:transaction]; [indicator saveWithTransaction:transaction];
DDLogInfo(@"%@ Creating TSUnreadIndicatorInteraction: %@", self.tag, indicator.uniqueId); DDLogInfo(@"%@ Creating TSUnreadIndicatorInteraction: %@ (%llu)",
self.tag,
indicator.uniqueId,
indicator.timestampForSorting);
} }
} }
}]; }];

Loading…
Cancel
Save