Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 3d451846a6
commit 7b84019251

@ -5,6 +5,8 @@
#import "OWSMessageEditing.h" #import "OWSMessageEditing.h"
#import <JSQMessagesViewController/JSQPhotoMediaItem.h> #import <JSQMessagesViewController/JSQPhotoMediaItem.h>
NS_ASSUME_NONNULL_BEGIN
@class TSAttachmentStream; @class TSAttachmentStream;
@interface TSAnimatedAdapter : JSQMediaItem <OWSMessageEditing> @interface TSAnimatedAdapter : JSQMediaItem <OWSMessageEditing>
@ -15,3 +17,5 @@
@property NSData *fileData; @property NSData *fileData;
@end @end
NS_ASSUME_NONNULL_END

@ -11,16 +11,20 @@
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h> #import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
#import <MobileCoreServices/MobileCoreServices.h> #import <MobileCoreServices/MobileCoreServices.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSAnimatedAdapter () @interface TSAnimatedAdapter ()
@property (nonatomic) UIImageView *cachedImageView; @property (nonatomic, nullable) UIImageView *cachedImageView;
@property (nonatomic) UIImage *image; @property (nonatomic) UIImage *image;
@property (nonatomic) TSAttachmentStream *attachment; @property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic) AttachmentUploadView *attachmentUploadView; @property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming; @property (nonatomic) BOOL incoming;
@end @end
#pragma mark -
@implementation TSAnimatedAdapter @implementation TSAnimatedAdapter
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming
@ -124,3 +128,5 @@
} }
@end @end
NS_ASSUME_NONNULL_END

@ -5,6 +5,8 @@
#import "OWSMessageEditing.h" #import "OWSMessageEditing.h"
#import <JSQMessagesViewController/JSQMediaItem.h> #import <JSQMessagesViewController/JSQMediaItem.h>
NS_ASSUME_NONNULL_BEGIN
@class TSAttachmentStream; @class TSAttachmentStream;
@interface TSGenericAttachmentAdapter : JSQMediaItem <OWSMessageEditing> @interface TSGenericAttachmentAdapter : JSQMediaItem <OWSMessageEditing>
@ -12,3 +14,5 @@
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming; - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming;
@end @end
NS_ASSUME_NONNULL_END

@ -13,16 +13,19 @@
#import <MobileCoreServices/MobileCoreServices.h> #import <MobileCoreServices/MobileCoreServices.h>
#import <SignalServiceKit/MimeTypeUtil.h> #import <SignalServiceKit/MimeTypeUtil.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSGenericAttachmentAdapter () @interface TSGenericAttachmentAdapter ()
@property (nonatomic) UIView *cachedMediaView; @property (nonatomic, nullable) UIView *cachedMediaView;
@property (nonatomic) TSAttachmentStream *attachment; @property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic) AttachmentUploadView *attachmentUploadView; @property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming; @property (nonatomic) BOOL incoming;
@property (nonatomic) NSString *attachmentId;
@end @end
#pragma mark -
@implementation TSGenericAttachmentAdapter @implementation TSGenericAttachmentAdapter
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming
@ -31,13 +34,17 @@
if (self) { if (self) {
_attachment = attachment; _attachment = attachment;
_attachmentId = attachment.uniqueId;
_incoming = incoming; _incoming = incoming;
} }
return self; return self;
} }
- (NSString *)attachmentId
{
return self.attachment.uniqueId;
}
- (void)clearCachedMediaViews - (void)clearCachedMediaViews
{ {
[super clearCachedMediaViews]; [super clearCachedMediaViews];
@ -194,3 +201,5 @@
} }
@end @end
NS_ASSUME_NONNULL_END

@ -18,6 +18,8 @@
#import "TSOutgoingMessage.h" #import "TSOutgoingMessage.h"
#import <MobileCoreServices/MobileCoreServices.h> #import <MobileCoreServices/MobileCoreServices.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSMessageAdapter () @interface TSMessageAdapter ()
// --- // ---
@ -60,6 +62,7 @@
@end @end
#pragma mark -
@implementation TSMessageAdapter @implementation TSMessageAdapter
@ -134,8 +137,8 @@
if ([attachment.contentType isEqualToString:OWSMimeTypeOversizeTextMessage]) { if ([attachment.contentType isEqualToString:OWSMimeTypeOversizeTextMessage]) {
NSData *textData = [NSData dataWithContentsOfURL:stream.mediaURL]; NSData *textData = [NSData dataWithContentsOfURL:stream.mediaURL];
NSString *fullText = [[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding]; NSString *fullText = [[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding];
// TODO: Tune this value. // Only show up to 2kb of text.
const NSUInteger kMaxTextDisplayLength = 256; const NSUInteger kMaxTextDisplayLength = 2 * 1024;
NSString *displayText = [[DisplayableTextFilter new] displayableText:fullText]; NSString *displayText = [[DisplayableTextFilter new] displayableText:fullText];
if (displayText.length > kMaxTextDisplayLength) { if (displayText.length > kMaxTextDisplayLength) {
// Trim whitespace before _AND_ after slicing the snipper from the string. // Trim whitespace before _AND_ after slicing the snipper from the string.
@ -152,27 +155,24 @@
} else if ([stream isAnimated]) { } else if ([stream isAnimated]) {
adapter.mediaItem = adapter.mediaItem =
[[TSAnimatedAdapter alloc] initWithAttachment:stream incoming:isIncomingAttachment]; [[TSAnimatedAdapter alloc] initWithAttachment:stream incoming:isIncomingAttachment];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing = adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment;
[interaction isKindOfClass:[TSOutgoingMessage class]];
break; break;
} else if ([stream isImage]) { } else if ([stream isImage]) {
adapter.mediaItem = adapter.mediaItem =
[[TSPhotoAdapter alloc] initWithAttachment:stream incoming:isIncomingAttachment]; [[TSPhotoAdapter alloc] initWithAttachment:stream incoming:isIncomingAttachment];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing = adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment;
[interaction isKindOfClass:[TSOutgoingMessage class]];
break; break;
} else if ([stream isVideo]) { } else if ([stream isVideo]) {
adapter.mediaItem = [[TSVideoAttachmentAdapter alloc] adapter.mediaItem = [[TSVideoAttachmentAdapter alloc]
initWithAttachment:stream initWithAttachment:stream
incoming:[interaction isKindOfClass:[TSIncomingMessage class]]]; incoming:[interaction isKindOfClass:[TSIncomingMessage class]]];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing = adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment;
[interaction isKindOfClass:[TSOutgoingMessage class]];
break; break;
} else { } else {
adapter.mediaItem = [[TSGenericAttachmentAdapter alloc] adapter.mediaItem = [[TSGenericAttachmentAdapter alloc]
initWithAttachment:stream initWithAttachment:stream
incoming:[interaction isKindOfClass:[TSIncomingMessage class]]]; incoming:[interaction isKindOfClass:[TSIncomingMessage class]]];
adapter.mediaItem.appliesMediaViewMaskAsOutgoing = YES; adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment;
break; break;
} }
} else if ([attachment isKindOfClass:[TSAttachmentPointer class]]) { } else if ([attachment isKindOfClass:[TSAttachmentPointer class]]) {
@ -402,3 +402,5 @@
} }
@end @end
NS_ASSUME_NONNULL_END

@ -5,6 +5,8 @@
#import "OWSMessageEditing.h" #import "OWSMessageEditing.h"
#import <JSQMessagesViewController/JSQPhotoMediaItem.h> #import <JSQMessagesViewController/JSQPhotoMediaItem.h>
NS_ASSUME_NONNULL_BEGIN
@class TSAttachmentStream; @class TSAttachmentStream;
@interface TSPhotoAdapter : JSQPhotoMediaItem <OWSMessageEditing> @interface TSPhotoAdapter : JSQPhotoMediaItem <OWSMessageEditing>
@ -15,3 +17,5 @@
@property NSString *attachmentId; @property NSString *attachmentId;
@end @end
NS_ASSUME_NONNULL_END

@ -9,14 +9,18 @@
#import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h> #import <JSQMessagesViewController/JSQMessagesMediaViewBubbleImageMasker.h>
#import <MobileCoreServices/MobileCoreServices.h> #import <MobileCoreServices/MobileCoreServices.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSPhotoAdapter () @interface TSPhotoAdapter ()
@property (nonatomic) UIImageView *cachedImageView; @property (nonatomic, nullable) UIImageView *cachedImageView;
@property (nonatomic) AttachmentUploadView *attachmentUploadView; @property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@property (nonatomic) BOOL incoming; @property (nonatomic) BOOL incoming;
@end @end
#pragma mark -
@implementation TSPhotoAdapter @implementation TSPhotoAdapter
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming
@ -126,3 +130,5 @@
} }
@end @end
NS_ASSUME_NONNULL_END

@ -1,9 +1,12 @@
// Created by Frederic Jacobs on 17/12/14. //
// Copyright (c) 2014 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSMessageEditing.h" #import "OWSMessageEditing.h"
#import <JSQMessagesViewController/JSQVideoMediaItem.h> #import <JSQMessagesViewController/JSQVideoMediaItem.h>
NS_ASSUME_NONNULL_BEGIN
@class TSAttachmentStream; @class TSAttachmentStream;
@interface TSVideoAttachmentAdapter : JSQVideoMediaItem <OWSMessageEditing> @interface TSVideoAttachmentAdapter : JSQVideoMediaItem <OWSMessageEditing>
@ -24,3 +27,5 @@
- (void)resetAudioDuration; - (void)resetAudioDuration;
@end @end
NS_ASSUME_NONNULL_END

@ -14,22 +14,23 @@
#import <SCWaveformView.h> #import <SCWaveformView.h>
#define AUDIO_BAR_HEIGHT 36 #define AUDIO_BAR_HEIGHT 36
NS_ASSUME_NONNULL_BEGIN
@interface TSVideoAttachmentAdapter () @interface TSVideoAttachmentAdapter ()
@property (nonatomic) UIImage *image; @property (nonatomic) UIImage *image;
@property (nonatomic) UIImageView *cachedImageView; @property (nonatomic, nullable) UIImageView *cachedImageView;
@property (nonatomic) UIImageView *videoPlayButton;
@property (nonatomic) TSAttachmentStream *attachment; @property (nonatomic) TSAttachmentStream *attachment;
@property (nonatomic) UIProgressView *audioProgress; @property (nonatomic, nullable) SCWaveformView *waveform;
@property (nonatomic) SCWaveformView *waveform; @property (nonatomic, nullable) UIButton *audioPlayPauseButton;
@property (nonatomic) UIButton *audioPlayPauseButton; @property (nonatomic, nullable) UILabel *durationLabel;
@property (nonatomic) UILabel *durationLabel;
@property (nonatomic) UIView *audioBubble;
@property (nonatomic) BOOL incoming; @property (nonatomic) BOOL incoming;
@property (nonatomic) AttachmentUploadView *attachmentUploadView; @property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView;
@end @end
#pragma mark -
@implementation TSVideoAttachmentAdapter @implementation TSVideoAttachmentAdapter
- (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming { - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming {
@ -113,17 +114,15 @@
isOutgoing:self.appliesMediaViewMaskAsOutgoing]; isOutgoing:self.appliesMediaViewMaskAsOutgoing];
self.cachedImageView = imageView; self.cachedImageView = imageView;
UIImage *img = [UIImage imageNamed:@"play_button"]; UIImage *img = [UIImage imageNamed:@"play_button"];
_videoPlayButton = [[UIImageView alloc] initWithImage:img]; UIImageView *videoPlayButton = [[UIImageView alloc] initWithImage:img];
_videoPlayButton.frame = CGRectMake((size.width / 2) - 18, (size.height / 2) - 18, 37, 37); videoPlayButton.frame = CGRectMake((size.width / 2) - 18, (size.height / 2) - 18, 37, 37);
[self.cachedImageView addSubview:_videoPlayButton]; [self.cachedImageView addSubview:videoPlayButton];
if (!_incoming) { if (!_incoming) {
__weak TSVideoAttachmentAdapter *weakSelf = self;
self.attachmentUploadView = [[AttachmentUploadView alloc] initWithAttachment:self.attachment self.attachmentUploadView = [[AttachmentUploadView alloc] initWithAttachment:self.attachment
superview:imageView superview:imageView
attachmentStateCallback:^(BOOL isAttachmentReady) { attachmentStateCallback:^(BOOL isAttachmentReady) {
weakSelf.videoPlayButton.hidden videoPlayButton.hidden = !isAttachmentReady;
= !isAttachmentReady;
}]; }];
} }
} }
@ -143,11 +142,11 @@
self.waveform.progress = 0.0; self.waveform.progress = 0.0;
} }
_audioBubble = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, size.width, size.height)]; UIView *audioBubble = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, size.width, size.height)];
_audioBubble.backgroundColor = audioBubble.backgroundColor =
[UIColor colorWithRed:10 / 255.0f green:130 / 255.0f blue:253 / 255.0f alpha:1.0f]; [UIColor colorWithRed:10 / 255.0f green:130 / 255.0f blue:253 / 255.0f alpha:1.0f];
_audioBubble.layer.cornerRadius = 18; audioBubble.layer.cornerRadius = 18;
_audioBubble.layer.masksToBounds = YES; audioBubble.layer.masksToBounds = YES;
_audioPlayPauseButton = [[UIButton alloc] initWithFrame:CGRectMake(3, 3, 30, 30)]; _audioPlayPauseButton = [[UIButton alloc] initWithFrame:CGRectMake(3, 3, 30, 30)];
[_audioPlayPauseButton setBackgroundImage:[UIImage imageNamed:@"audio_play_button"] [_audioPlayPauseButton setBackgroundImage:[UIImage imageNamed:@"audio_play_button"]
@ -166,7 +165,7 @@
_durationLabel.textColor = [UIColor whiteColor]; _durationLabel.textColor = [UIColor whiteColor];
if (_incoming) { if (_incoming) {
_audioBubble.backgroundColor = audioBubble.backgroundColor =
[UIColor colorWithRed:229 / 255.0f green:228 / 255.0f blue:234 / 255.0f alpha:1.0f]; [UIColor colorWithRed:229 / 255.0f green:228 / 255.0f blue:234 / 255.0f alpha:1.0f];
_waveform.normalColor = [UIColor whiteColor]; _waveform.normalColor = [UIColor whiteColor];
_waveform.progressColor = _waveform.progressColor =
@ -176,21 +175,21 @@
_durationLabel.textColor = [UIColor darkTextColor]; _durationLabel.textColor = [UIColor darkTextColor];
} }
[_audioBubble addSubview:_waveform]; [audioBubble addSubview:_waveform];
[_audioBubble addSubview:_audioPlayPauseButton]; [audioBubble addSubview:_audioPlayPauseButton];
[_audioBubble addSubview:_durationLabel]; [audioBubble addSubview:_durationLabel];
if (!_incoming) { if (!_incoming) {
__weak TSVideoAttachmentAdapter *weakSelf = self; __weak TSVideoAttachmentAdapter *weakSelf = self;
self.attachmentUploadView = [[AttachmentUploadView alloc] initWithAttachment:self.attachment self.attachmentUploadView = [[AttachmentUploadView alloc] initWithAttachment:self.attachment
superview:_audioBubble superview:audioBubble
attachmentStateCallback:^(BOOL isAttachmentReady) { attachmentStateCallback:^(BOOL isAttachmentReady) {
weakSelf.audioPlayPauseButton.enabled weakSelf.audioPlayPauseButton.enabled
= isAttachmentReady; = isAttachmentReady;
}]; }];
} }
return _audioBubble; return audioBubble;
} else { } else {
// Unknown media type. // Unknown media type.
OWSAssert(0); OWSAssert(0);
@ -280,3 +279,5 @@
} }
@end @end
NS_ASSUME_NONNULL_END

@ -21,7 +21,7 @@ class AttachmentApprovalViewController: UIViewController {
self.attachment = SignalAttachment.genericAttachment(data: nil, self.attachment = SignalAttachment.genericAttachment(data: nil,
dataUTI: kUTTypeContent as String) dataUTI: kUTTypeContent as String)
super.init(coder: aDecoder) super.init(coder: aDecoder)
assert(false) assertionFailure()
} }
required init(attachment: SignalAttachment, successCompletion : @escaping () -> Void) { required init(attachment: SignalAttachment, successCompletion : @escaping () -> Void) {

@ -116,7 +116,7 @@ class SignalAttachment: NSObject {
var errorName: String? { var errorName: String? {
guard let error = error else { guard let error = error else {
// This method should only be called if there is an error. // This method should only be called if there is an error.
assert(false) assertionFailure()
return nil return nil
} }
@ -126,7 +126,7 @@ class SignalAttachment: NSObject {
var localizedErrorDescription: String? { var localizedErrorDescription: String? {
guard let error = self.error else { guard let error = self.error else {
// This method should only be called if there is an error. // This method should only be called if there is an error.
assert(false) assertionFailure()
return nil return nil
} }
@ -158,8 +158,8 @@ class SignalAttachment: NSObject {
var fileExtension: String? { var fileExtension: String? {
if dataUTI == SignalAttachment.kOversizeTextAttachmentUTI || if dataUTI == SignalAttachment.kOversizeTextAttachmentUTI ||
dataUTI == SignalAttachment.kUnknownTestAttachmentUTI { dataUTI == SignalAttachment.kUnknownTestAttachmentUTI {
assert(false) assertionFailure()
return "" return nil
} }
guard let fileExtension = UTTypeCopyPreferredTagWithClass(dataUTI as CFString, guard let fileExtension = UTTypeCopyPreferredTagWithClass(dataUTI as CFString,

Loading…
Cancel
Save