|
|
|
@ -487,8 +487,17 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
|
|
|
|
|
_callOnOpen = callOnViewAppearing;
|
|
|
|
|
|
|
|
|
|
[self.uiDatabaseConnection beginLongLivedReadTransaction];
|
|
|
|
|
self.messageMappings =
|
|
|
|
|
[[YapDatabaseViewMappings alloc] initWithGroups:@[ thread.uniqueId ] view:TSMessageDatabaseViewExtensionName];
|
|
|
|
|
|
|
|
|
|
if (thread.uniqueId.length > 0) {
|
|
|
|
|
self.messageMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[ thread.uniqueId ]
|
|
|
|
|
view:TSMessageDatabaseViewExtensionName];
|
|
|
|
|
} else {
|
|
|
|
|
OWSFail(@"uniqueId unexpectedly empty for thread: %@", thread);
|
|
|
|
|
self.messageMappings =
|
|
|
|
|
[[YapDatabaseViewMappings alloc] initWithGroups:@[] view:TSMessageDatabaseViewExtensionName];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We need to impose the range restrictions on the mappings immediately to avoid
|
|
|
|
|
// doing a great deal of unnecessary work and causing a perf hotspot.
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
@ -2202,33 +2211,38 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
|
|
|
|
|
if ([[messageItem media] isKindOfClass:[TSPhotoAdapter class]]) {
|
|
|
|
|
TSPhotoAdapter *messageMedia = (TSPhotoAdapter *)[messageItem media];
|
|
|
|
|
|
|
|
|
|
UIImage *tappedImage = ((UIImageView *)[messageMedia mediaView]).image;
|
|
|
|
|
UIView *mediaView = [messageMedia mediaView];
|
|
|
|
|
if (![mediaView isKindOfClass:[UIImageView class]]) {
|
|
|
|
|
OWSFail(@"unexpected mediaView of type: %@", [mediaView class]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
UIImageView *imageView = (UIImageView *)mediaView;
|
|
|
|
|
UIImage *tappedImage = imageView.image;
|
|
|
|
|
if (tappedImage == nil) {
|
|
|
|
|
DDLogWarn(@"tapped TSPhotoAdapter with nil image");
|
|
|
|
|
} else {
|
|
|
|
|
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
|
|
|
|
JSQMessagesCollectionViewCell *cell
|
|
|
|
|
= (JSQMessagesCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
|
|
|
|
|
OWSAssert([cell isKindOfClass:[JSQMessagesCollectionViewCell class]]);
|
|
|
|
|
CGRect convertedRect = [cell.mediaView convertRect:cell.mediaView.bounds toView:window];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
|
|
|
|
JSQMessagesCollectionViewCell *cell
|
|
|
|
|
= (JSQMessagesCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
|
|
|
|
|
OWSAssert([cell isKindOfClass:[JSQMessagesCollectionViewCell class]]);
|
|
|
|
|
CGRect convertedRect = [cell.mediaView convertRect:cell.mediaView.bounds toView:window];
|
|
|
|
|
|
|
|
|
|
__block TSAttachment *attachment = nil;
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
attachment = [TSAttachment fetchObjectWithUniqueID:messageMedia.attachmentId
|
|
|
|
|
transaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
__block TSAttachment *attachment = nil;
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
attachment =
|
|
|
|
|
[TSAttachment fetchObjectWithUniqueID:messageMedia.attachmentId transaction:transaction];
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
if ([attachment isKindOfClass:[TSAttachmentStream class]]) {
|
|
|
|
|
TSAttachmentStream *attStream = (TSAttachmentStream *)attachment;
|
|
|
|
|
FullImageViewController *vc =
|
|
|
|
|
[[FullImageViewController alloc] initWithAttachment:attStream
|
|
|
|
|
fromRect:convertedRect
|
|
|
|
|
forInteraction:interaction
|
|
|
|
|
messageItem:messageItem
|
|
|
|
|
isAnimated:NO];
|
|
|
|
|
if ([attachment isKindOfClass:[TSAttachmentStream class]]) {
|
|
|
|
|
TSAttachmentStream *attStream = (TSAttachmentStream *)attachment;
|
|
|
|
|
FullImageViewController *vc = [[FullImageViewController alloc] initWithAttachment:attStream
|
|
|
|
|
fromRect:convertedRect
|
|
|
|
|
forInteraction:interaction
|
|
|
|
|
messageItem:messageItem
|
|
|
|
|
isAnimated:NO];
|
|
|
|
|
|
|
|
|
|
[vc presentFromViewController:self];
|
|
|
|
|
}
|
|
|
|
|
[vc presentFromViewController:self];
|
|
|
|
|
}
|
|
|
|
|
} else if ([[messageItem media] isKindOfClass:[TSAnimatedAdapter class]]) {
|
|
|
|
|
// Show animated image full-screen
|
|
|
|
@ -3956,20 +3970,30 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
|
|
|
|
|
|
|
|
|
|
TSThread *thread = self.thread;
|
|
|
|
|
uint64_t lastVisibleTimestamp = self.lastVisibleTimestamp;
|
|
|
|
|
|
|
|
|
|
[self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
|
NSMutableArray<id<OWSReadTracking>> *interactions = [NSMutableArray new];
|
|
|
|
|
|
|
|
|
|
[[TSDatabaseView unseenDatabaseViewExtension:transaction]
|
|
|
|
|
enumerateRowsInGroup:thread.uniqueId
|
|
|
|
|
usingBlock:^(
|
|
|
|
|
NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) {
|
|
|
|
|
|
|
|
|
|
TSInteraction *interaction = object;
|
|
|
|
|
if (interaction.timestampForSorting > lastVisibleTimestamp) {
|
|
|
|
|
if (![object conformsToProtocol:@protocol(OWSReadTracking)]) {
|
|
|
|
|
OWSFail(@"Expected to conform to OWSReadTracking: object with class: %@ collection: %@ "
|
|
|
|
|
@"key: %@",
|
|
|
|
|
[object class],
|
|
|
|
|
collection,
|
|
|
|
|
key);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
id<OWSReadTracking> possiblyRead = (id<OWSReadTracking>)object;
|
|
|
|
|
|
|
|
|
|
if (possiblyRead.timestampForSorting > lastVisibleTimestamp) {
|
|
|
|
|
*stop = YES;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
id<OWSReadTracking> possiblyRead = (id<OWSReadTracking>)object;
|
|
|
|
|
OWSAssert(!possiblyRead.read);
|
|
|
|
|
if (!possiblyRead.read) {
|
|
|
|
|
[interactions addObject:possiblyRead];
|
|
|
|
|