mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Respond to CR.
// FREEBIE
This commit is contained in:
parent
6704396998
commit
ebf500d805
|
@ -12,6 +12,6 @@
|
|||
|
||||
- (CGSize)ows_adjustBubbleSize:(CGSize)bubbleSize forImageSize:(CGSize)imageSize;
|
||||
|
||||
- (CGSize)sizeOfImageAtURL:(NSURL *_Nullable)imageURL;
|
||||
- (CGSize)sizeOfImageAtURL:(NSURL *)imageURL;
|
||||
|
||||
@end
|
||||
|
|
|
@ -38,15 +38,14 @@
|
|||
return bubbleSize;
|
||||
}
|
||||
|
||||
- (CGSize)sizeOfImageAtURL:(NSURL *_Nullable)imageURL
|
||||
- (CGSize)sizeOfImageAtURL:(NSURL *)imageURL
|
||||
{
|
||||
if (!imageURL) {
|
||||
return CGSizeZero;
|
||||
}
|
||||
OWSAssert(imageURL);
|
||||
|
||||
// With CGImageSource we avoid loading the whole image into memory.
|
||||
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL);
|
||||
if (!source) {
|
||||
OWSAssert(0);
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
|
@ -61,6 +60,8 @@
|
|||
NSNumber *height = properties[(NSString *)kCGImagePropertyPixelHeight];
|
||||
if (width && height) {
|
||||
imageSize = CGSizeMake(width.floatValue, height.floatValue);
|
||||
} else {
|
||||
OWSAssert(0);
|
||||
}
|
||||
}
|
||||
CFRelease(source);
|
||||
|
|
|
@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@interface TSAnimatedAdapter : JSQMediaItem <OWSMessageEditing, OWSMessageMediaAdapter>
|
||||
|
||||
@property (nonatomic) NSString *attachmentId;
|
||||
@property (nonatomic, readonly) NSString *attachmentId;
|
||||
|
||||
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
|
||||
@property (nonatomic) BOOL incoming;
|
||||
@property (nonatomic) CGSize imageSize;
|
||||
@property (nonatomic) NSString *attachmentId;
|
||||
|
||||
// See comments on OWSMessageMediaAdapter.
|
||||
@property (nonatomic, nullable, weak) id lastPresentingCell;
|
||||
|
@ -40,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
_attachment = attachment;
|
||||
_attachmentId = attachment.uniqueId;
|
||||
_incoming = incoming;
|
||||
_imageSize = [self sizeOfImageAtURL:attachment.mediaURL];
|
||||
_imageSize = attachment.mediaURL ? [self sizeOfImageAtURL:attachment.mediaURL] : CGSizeZero;
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -100,6 +101,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
if (self.cachedImageView == nil) {
|
||||
// Use Flipboard FLAnimatedImage library to display gifs
|
||||
NSData *fileData = [NSData dataWithContentsOfURL:[self.attachment mediaURL]];
|
||||
if (!fileData) {
|
||||
DDLogError(@"%@ Could not load image: %@", [self tag], [self.attachment mediaURL]);
|
||||
OWSAssert(0);
|
||||
return nil;
|
||||
}
|
||||
FLAnimatedImage *animatedGif = [FLAnimatedImage animatedImageWithGIFData:fileData];
|
||||
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
|
||||
imageView.animatedImage = animatedGif;
|
||||
|
@ -141,11 +147,20 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
utiType = (NSString *)kUTTypeGIF;
|
||||
}
|
||||
|
||||
UIPasteboard *pasteboard = UIPasteboard.generalPasteboard;
|
||||
NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]];
|
||||
[pasteboard setData:data forPasteboardType:utiType];
|
||||
if (!data) {
|
||||
DDLogError(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]);
|
||||
OWSAssert(0);
|
||||
return;
|
||||
}
|
||||
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
|
||||
} else if (action == NSSelectorFromString(@"save:")) {
|
||||
NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]];
|
||||
if (!data) {
|
||||
DDLogError(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]);
|
||||
OWSAssert(0);
|
||||
return;
|
||||
}
|
||||
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
|
||||
[library writeImageDataToSavedPhotosAlbum:data
|
||||
metadata:nil
|
||||
|
@ -161,6 +176,18 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
}
|
||||
|
||||
#pragma mark - Logging
|
||||
|
||||
+ (NSString *)tag
|
||||
{
|
||||
return [NSString stringWithFormat:@"[%@]", self.class];
|
||||
}
|
||||
|
||||
- (NSString *)tag
|
||||
{
|
||||
return self.class.tag;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming
|
||||
{
|
||||
self = [super initWithImage:nil];
|
||||
self = [super init];
|
||||
|
||||
if (!self) {
|
||||
return self;
|
||||
|
@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
_attachment = attachment;
|
||||
_attachmentId = attachment.uniqueId;
|
||||
_incoming = incoming;
|
||||
_imageSize = [self sizeOfImageAtURL:attachment.mediaURL];
|
||||
_imageSize = attachment.mediaURL ? [self sizeOfImageAtURL:attachment.mediaURL] : CGSizeZero;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -74,6 +74,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
if (self.cachedImageView == nil) {
|
||||
UIImage *image = self.attachment.image;
|
||||
if (!image) {
|
||||
DDLogError(@"%@ Could not load image: %@", [self tag], [self.attachment mediaURL]);
|
||||
OWSAssert(0);
|
||||
return nil;
|
||||
}
|
||||
CGSize size = [self mediaViewDisplaySize];
|
||||
|
@ -125,10 +127,20 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
utiType = (NSString *)kUTTypeImage;
|
||||
}
|
||||
NSData *data = [NSData dataWithContentsOfURL:self.attachment.mediaURL];
|
||||
if (!data) {
|
||||
DDLogError(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]);
|
||||
OWSAssert(0);
|
||||
return;
|
||||
}
|
||||
[UIPasteboard.generalPasteboard setData:data forPasteboardType:utiType];
|
||||
return;
|
||||
} else if (action == NSSelectorFromString(@"save:")) {
|
||||
NSData *data = [NSData dataWithContentsOfURL:[self.attachment mediaURL]];
|
||||
if (!data) {
|
||||
DDLogError(@"%@ Could not load image data: %@", [self tag], [self.attachment mediaURL]);
|
||||
OWSAssert(0);
|
||||
return;
|
||||
}
|
||||
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
|
||||
[library writeImageDataToSavedPhotosAlbum:data
|
||||
metadata:nil
|
||||
|
@ -161,6 +173,18 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
}
|
||||
|
||||
#pragma mark - Logging
|
||||
|
||||
+ (NSString *)tag
|
||||
{
|
||||
return [NSString stringWithFormat:@"[%@]", self.class];
|
||||
}
|
||||
|
||||
- (NSString *)tag
|
||||
{
|
||||
return self.class.tag;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
Loading…
Reference in a new issue