|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
#import "AttachmentUploadView.h"
|
|
|
|
|
#import "JSQMediaItem+OWS.h"
|
|
|
|
|
#import "TSAttachmentStream.h"
|
|
|
|
|
#import <AssetsLibrary/AssetsLibrary.h>
|
|
|
|
|
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
|
|
|
|
|
#import <MobileCoreServices/MobileCoreServices.h>
|
|
|
|
|
#import <SignalServiceKit/MimeTypeUtil.h>
|
|
|
|
@ -17,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
@property (nonatomic, nullable) UIImageView *cachedImageView;
|
|
|
|
|
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
|
|
|
|
@property (nonatomic) BOOL incoming;
|
|
|
|
|
@property (nonatomic) CGSize imageSize;
|
|
|
|
|
|
|
|
|
|
// See comments on OWSMessageMediaAdapter.
|
|
|
|
|
@property (nonatomic, nullable, weak) id lastPresentingCell;
|
|
|
|
@ -29,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithImage:attachment.image];
|
|
|
|
|
self = [super initWithImage:nil];
|
|
|
|
|
|
|
|
|
|
if (!self) {
|
|
|
|
|
return self;
|
|
|
|
@ -39,12 +41,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
_attachment = attachment;
|
|
|
|
|
_attachmentId = attachment.uniqueId;
|
|
|
|
|
_incoming = incoming;
|
|
|
|
|
_imageSize = [self sizeOfImageAtURL:attachment.mediaURL];
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)clearAllViews
|
|
|
|
|
{
|
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
|
|
[_cachedImageView removeFromSuperview];
|
|
|
|
|
_cachedImageView = nil;
|
|
|
|
|
_attachmentUploadView = nil;
|
|
|
|
@ -64,13 +69,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
#pragma mark - JSQMessageMediaData protocol
|
|
|
|
|
|
|
|
|
|
- (UIView *)mediaView {
|
|
|
|
|
if (self.image == nil) {
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
|
|
if (self.cachedImageView == nil) {
|
|
|
|
|
UIImage *image = self.attachment.image;
|
|
|
|
|
if (!image) {
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
CGSize size = [self mediaViewDisplaySize];
|
|
|
|
|
UIImageView *imageView = [[UIImageView alloc] initWithImage:self.image];
|
|
|
|
|
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
|
|
|
|
|
imageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
|
|
|
imageView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height);
|
|
|
|
|
imageView.clipsToBounds = YES;
|
|
|
|
@ -93,7 +100,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CGSize)mediaViewDisplaySize {
|
|
|
|
|
return [self ows_adjustBubbleSize:[super mediaViewDisplaySize] forImage:self.image];
|
|
|
|
|
return [self ows_adjustBubbleSize:[super mediaViewDisplaySize] forImageSize:self.imageSize];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - OWSMessageEditing Protocol
|
|
|
|
@ -106,14 +113,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
- (void)performEditingAction:(SEL)action
|
|
|
|
|
{
|
|
|
|
|
NSString *actionString = NSStringFromSelector(action);
|
|
|
|
|
if (!self.image) {
|
|
|
|
|
OWSAssert(NO);
|
|
|
|
|
DDLogWarn(@"Refusing to perform '%@' action with nil image for %@: attachmentId=%@. (corrupted attachment?)",
|
|
|
|
|
actionString,
|
|
|
|
|
self.class,
|
|
|
|
|
self.attachmentId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (action == @selector(copy:)) {
|
|
|
|
|
// We should always copy to the pasteboard as data, not an UIImage.
|
|
|
|
@ -129,7 +128,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
|
|
|
|
|
return;
|
|
|
|
|
} else if (action == NSSelectorFromString(@"save:")) {
|
|
|
|
|
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
|
|
|
|
|
NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]];
|
|
|
|
|
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
|
|
|
|
|
[library writeImageDataToSavedPhotosAlbum:data
|
|
|
|
|
metadata:nil
|
|
|
|
|
completionBlock:^(NSURL *assetURL, NSError *error) {
|
|
|
|
|
if (error) {
|
|
|
|
|
DDLogWarn(@"Error Saving image to photo album: %@", error);
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|