Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent 13e9f11b4e
commit 999e8c8e31

@ -708,15 +708,23 @@ typedef enum : NSUInteger {
- (NSIndexPath *_Nullable)indexPathOfMessageOnOpen - (NSIndexPath *_Nullable)indexPathOfMessageOnOpen
{ {
OWSAssert(self.focusMessageIdOnOpen); OWSAssert(self.focusMessageIdOnOpen);
OWSAssert(self.dynamicInteractions.focusMessagePosition);
NSInteger row = 0; if (!self.dynamicInteractions.focusMessagePosition) {
for (ConversationViewItem *viewItem in self.viewItems) { // This might happen if the focus message has disappeared
if ([viewItem.interaction.uniqueId isEqualToString:self.focusMessageIdOnOpen]) { // before this view could appear.
return [NSIndexPath indexPathForRow:row inSection:0]; OWSFail(@"%@ focus message has unknown position.", self.logTag);
} return nil;
row++;
} }
return nil; NSUInteger focusMessagePosition = self.dynamicInteractions.focusMessagePosition.unsignedIntegerValue;
if (focusMessagePosition >= self.viewItems.count) {
// This might happen if the focus message is outside the maximum
// valid load window size for this view.
OWSFail(@"%@ focus message has invalid position.", self.logTag);
return nil;
}
NSInteger row = (NSInteger)((self.viewItems.count - 1) - focusMessagePosition);
return [NSIndexPath indexPathForRow:row inSection:0];
} }
- (void)scrollToDefaultPosition - (void)scrollToDefaultPosition

@ -25,6 +25,10 @@ NS_ASSUME_NONNULL_BEGIN
// to include the unread indicator. // to include the unread indicator.
@property (nonatomic, nullable, readonly) NSNumber *unreadIndicatorPosition; @property (nonatomic, nullable, readonly) NSNumber *unreadIndicatorPosition;
// Represents the "reverse index" of the focus message, if any.
// The "reverse index" is the distance of this interaction from
// the last interaction in the thread. Therefore the last interaction
// will have a "reverse index" of zero.
@property (nonatomic, nullable, readonly) NSNumber *focusMessagePosition; @property (nonatomic, nullable, readonly) NSNumber *focusMessagePosition;
// If there are unseen messages in the thread, this is the timestamp // If there are unseen messages in the thread, this is the timestamp

@ -639,23 +639,29 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(transaction); OWSAssert(transaction);
OWSAssert(focusMessageId); OWSAssert(focusMessageId);
// Enumerate in reverse to count the number of messages after the "focus message". YapDatabaseViewTransaction *databaseView = [transaction ext:TSMessageDatabaseViewExtensionName];
__block NSUInteger count = 0;
__block BOOL didMatch = NO; NSString *_Nullable group = nil;
[[transaction ext:TSMessageDatabaseViewExtensionName] NSUInteger index;
enumerateKeysInGroup:thread.uniqueId BOOL success =
withOptions:NSEnumerationReverse [databaseView getGroup:&group index:&index forKey:focusMessageId inCollection:TSInteraction.collection];
usingBlock:^(NSString *collection, NSString *key, NSUInteger index, BOOL *stop) { if (!success) {
if ([key isEqualToString:focusMessageId]) { // This might happen if the focus message has disappeared
didMatch = YES; // before this view could appear.
*stop = YES; OWSFail(@"%@ failed to find focus message index.", self.logTag);
return; return nil;
} }
if (![group isEqualToString:thread.uniqueId]) {
count++; OWSFail(@"%@ focus message has invalid group.", self.logTag);
}]; return nil;
}
return didMatch ? @(count) : nil; NSUInteger count = [databaseView numberOfItemsInGroup:thread.uniqueId];
if (index >= count) {
OWSFail(@"%@ focus message has invalid index.", self.logTag);
return nil;
}
NSUInteger position = (count - index) - 1;
return @(position);
} }
+ (BOOL)shouldShowGroupProfileBannerInThread:(TSThread *)thread blockingManager:(OWSBlockingManager *)blockingManager + (BOOL)shouldShowGroupProfileBannerInThread:(TSThread *)thread blockingManager:(OWSBlockingManager *)blockingManager

Loading…
Cancel
Save