Improve handling of edge cases around unread indicator delimiting deleted message(s).

pull/1/head
Matthew Chen 8 years ago
parent 368ad922d6
commit 2d241623b7

@ -3413,6 +3413,12 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
if (lastVisibleViewItem) { if (lastVisibleViewItem) {
uint64_t lastVisibleTimestamp = lastVisibleViewItem.interaction.timestampForSorting; uint64_t lastVisibleTimestamp = lastVisibleViewItem.interaction.timestampForSorting;
self.lastVisibleTimestamp = MAX(self.lastVisibleTimestamp, lastVisibleTimestamp); self.lastVisibleTimestamp = MAX(self.lastVisibleTimestamp, lastVisibleTimestamp);
// If we delete the last unread message (manually or due to disappearing messages)
// we may need to clean up an obsolete unread indicator.
if (lastVisibleViewItem.interaction.interactionType == OWSInteractionType_UnreadIndicator) {
[self ensureDynamicInteractions];
}
} }
[self ensureScrollDownButton]; [self ensureScrollDownButton];

@ -137,7 +137,7 @@ NS_ASSUME_NONNULL_BEGIN
dbConnection:(YapDatabaseConnection *)dbConnection dbConnection:(YapDatabaseConnection *)dbConnection
hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator
firstUnseenInteractionTimestamp: firstUnseenInteractionTimestamp:
(nullable NSNumber *)firstUnseenInteractionTimestampParameter (nullable NSNumber *)firstUnseenInteractionTimestampParam
maxRangeSize:(int)maxRangeSize maxRangeSize:(int)maxRangeSize
{ {
OWSAssert(thread); OWSAssert(thread);
@ -232,6 +232,21 @@ 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.
//
// Make a local copy of this parameter that we can modify.
NSNumber *_Nullable firstUnseenInteractionTimestampParameter = firstUnseenInteractionTimestampParam;
if (firstUnseenInteractionTimestampParameter) {
// Due to disappearing messages or manual deletion,
// firstUnseenInteractionTimestampParameter may refer to an obsolete
// interaction in which case we want to discard it.
TSInteraction *_Nullable lastInteraction =
[[transaction ext:TSMessageDatabaseViewExtensionName] lastObjectInGroup:thread.uniqueId];
if (!lastInteraction
|| lastInteraction.timestampForSorting
< firstUnseenInteractionTimestampParameter.unsignedLongLongValue) {
firstUnseenInteractionTimestampParameter = nil;
}
}
if (firstUnseenInteractionTimestampParameter) { if (firstUnseenInteractionTimestampParameter) {
result.firstUnseenInteractionTimestamp = firstUnseenInteractionTimestampParameter; result.firstUnseenInteractionTimestamp = firstUnseenInteractionTimestampParameter;
} else { } else {

Loading…
Cancel
Save