Fix ability to attach photos from camera (#1112)

* Fix ability to attach photos from camera

Looks like this came about with the animated GIF handling. We'll only
go down the byte-comparison-mime-type-detecting code path for attaching
existing photos, since it only exists for animated GIFs.

This will also revert to properly compressing our image attachments, so
long as they are taken from the camera.

* Prevent crash when tapping broken image

It never makes sense to present a "full screen" nil image. Previously
this happened when camera-capture was broken, but could conceivably
happen for other as-of-yet unknown reasons.

// FREEBIE
pull/1/head
Michael Kirk 10 years ago
parent c0bb704d2d
commit 5869fb8e06

@ -931,8 +931,10 @@ typedef enum : NSUInteger {
if ([[messageItem media] isKindOfClass:[TSPhotoAdapter class]]) { if ([[messageItem media] isKindOfClass:[TSPhotoAdapter class]]) {
TSPhotoAdapter *messageMedia = (TSPhotoAdapter *)[messageItem media]; TSPhotoAdapter *messageMedia = (TSPhotoAdapter *)[messageItem media];
if ([messageMedia isImage]) {
tappedImage = ((UIImageView *)[messageMedia mediaView]).image; tappedImage = ((UIImageView *)[messageMedia mediaView]).image;
if(tappedImage == nil) {
DDLogWarn(@"tapped TSPhotoAdapter with nil image");
} else {
CGRect convertedRect = CGRect convertedRect =
[self.collectionView convertRect:[collectionView cellForItemAtIndexPath:indexPath].frame [self.collectionView convertRect:[collectionView cellForItemAtIndexPath:indexPath].frame
toView:nil]; toView:nil];
@ -952,13 +954,14 @@ typedef enum : NSUInteger {
[vc presentFromViewController:self.navigationController]; [vc presentFromViewController:self.navigationController];
} }
} else {
DDLogWarn(@"Currently unsupported");
} }
} else if ([[messageItem media] isKindOfClass:[TSAnimatedAdapter class]]) { } else if ([[messageItem media] isKindOfClass:[TSAnimatedAdapter class]]) {
// Show animated image full-screen // Show animated image full-screen
TSAnimatedAdapter *messageMedia = (TSAnimatedAdapter *)[messageItem media]; TSAnimatedAdapter *messageMedia = (TSAnimatedAdapter *)[messageItem media];
tappedImage = ((UIImageView *)[messageMedia mediaView]).image; tappedImage = ((UIImageView *)[messageMedia mediaView]).image;
if(tappedImage == nil) {
DDLogWarn(@"tapped TSAnimatedAdapter with nil image");
} else {
CGRect convertedRect = CGRect convertedRect =
[self.collectionView convertRect:[collectionView cellForItemAtIndexPath:indexPath].frame [self.collectionView convertRect:[collectionView cellForItemAtIndexPath:indexPath].frame
toView:nil]; toView:nil];
@ -976,6 +979,7 @@ typedef enum : NSUInteger {
isAnimated:YES]; isAnimated:YES];
[vc presentFromViewController:self.navigationController]; [vc presentFromViewController:self.navigationController];
} }
}
} else if ([[messageItem media] isKindOfClass:[TSVideoAttachmentAdapter class]]) { } else if ([[messageItem media] isKindOfClass:[TSVideoAttachmentAdapter class]]) {
// fileurl disappeared should look up in db as before. will do refactor // fileurl disappeared should look up in db as before. will do refactor
// full screen, check this setup with a .mov // full screen, check this setup with a .mov
@ -1364,7 +1368,7 @@ typedef enum : NSUInteger {
/* /*
* Fetching data from UIImagePickerController * Fetching data from UIImagePickerController
*/ */
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info {
[UIUtil modalCompletionBlock](); [UIUtil modalCompletionBlock]();
[self resetFrame]; [self resetFrame];
@ -1373,6 +1377,16 @@ typedef enum : NSUInteger {
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
[self sendQualityAdjustedAttachment:videoURL]; [self sendQualityAdjustedAttachment:videoURL];
} else { } else {
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
{
// Image captured from camera
UIImage *pictureCamera = [[info objectForKey:UIImagePickerControllerOriginalImage] normalizedImage];
if (pictureCamera) {
DDLogVerbose(@"Sending picture attachement ...");
[self sendMessageAttachment:[self qualityAdjustedAttachmentForImage:pictureCamera] ofType:@"image/jpeg"];
}
} else {
// Image picked from library
// Send image as NSData to accommodate both static and animated images // Send image as NSData to accommodate both static and animated images
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] [library assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL]
@ -1414,6 +1428,7 @@ typedef enum : NSUInteger {
}]; }];
} }
} }
}
- (void)sendMessageAttachment:(NSData *)attachmentData ofType:(NSString *)attachmentType { - (void)sendMessageAttachment:(NSData *)attachmentData ofType:(NSString *)attachmentType {
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]

Loading…
Cancel
Save