diff --git a/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.h b/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.h index 465e20e16..b5dbffaf0 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.h +++ b/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.h @@ -5,6 +5,8 @@ #import "OWSMessageEditing.h" #import +NS_ASSUME_NONNULL_BEGIN + @class TSAttachmentStream; @interface TSAnimatedAdapter : JSQMediaItem @@ -15,3 +17,5 @@ @property NSData *fileData; @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m index a74896ead..c5a88879e 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m @@ -11,16 +11,20 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + @interface TSAnimatedAdapter () -@property (nonatomic) UIImageView *cachedImageView; +@property (nonatomic, nullable) UIImageView *cachedImageView; @property (nonatomic) UIImage *image; @property (nonatomic) TSAttachmentStream *attachment; -@property (nonatomic) AttachmentUploadView *attachmentUploadView; +@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView; @property (nonatomic) BOOL incoming; @end +#pragma mark - + @implementation TSAnimatedAdapter - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming @@ -124,3 +128,5 @@ } @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.h b/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.h index 947a66d0b..8e8af3a39 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.h +++ b/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.h @@ -5,6 +5,8 @@ #import "OWSMessageEditing.h" #import +NS_ASSUME_NONNULL_BEGIN + @class TSAttachmentStream; @interface TSGenericAttachmentAdapter : JSQMediaItem @@ -12,3 +14,5 @@ - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming; @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.m index 3627ef66e..71942fbfc 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSGenericAttachmentAdapter.m @@ -13,16 +13,19 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + @interface TSGenericAttachmentAdapter () -@property (nonatomic) UIView *cachedMediaView; +@property (nonatomic, nullable) UIView *cachedMediaView; @property (nonatomic) TSAttachmentStream *attachment; -@property (nonatomic) AttachmentUploadView *attachmentUploadView; +@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView; @property (nonatomic) BOOL incoming; -@property (nonatomic) NSString *attachmentId; @end +#pragma mark - + @implementation TSGenericAttachmentAdapter - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming @@ -31,13 +34,17 @@ if (self) { _attachment = attachment; - _attachmentId = attachment.uniqueId; _incoming = incoming; } return self; } +- (NSString *)attachmentId +{ + return self.attachment.uniqueId; +} + - (void)clearCachedMediaViews { [super clearCachedMediaViews]; @@ -194,3 +201,5 @@ } @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/Models/TSMessageAdapaters/TSMessageAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSMessageAdapter.m index 9e8105094..9ca47dd0f 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSMessageAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSMessageAdapter.m @@ -18,6 +18,8 @@ #import "TSOutgoingMessage.h" #import +NS_ASSUME_NONNULL_BEGIN + @interface TSMessageAdapter () // --- @@ -60,6 +62,7 @@ @end +#pragma mark - @implementation TSMessageAdapter @@ -134,8 +137,8 @@ if ([attachment.contentType isEqualToString:OWSMimeTypeOversizeTextMessage]) { NSData *textData = [NSData dataWithContentsOfURL:stream.mediaURL]; NSString *fullText = [[NSString alloc] initWithData:textData encoding:NSUTF8StringEncoding]; - // TODO: Tune this value. - const NSUInteger kMaxTextDisplayLength = 256; + // Only show up to 2kb of text. + const NSUInteger kMaxTextDisplayLength = 2 * 1024; NSString *displayText = [[DisplayableTextFilter new] displayableText:fullText]; if (displayText.length > kMaxTextDisplayLength) { // Trim whitespace before _AND_ after slicing the snipper from the string. @@ -152,27 +155,24 @@ } else if ([stream isAnimated]) { adapter.mediaItem = [[TSAnimatedAdapter alloc] initWithAttachment:stream incoming:isIncomingAttachment]; - adapter.mediaItem.appliesMediaViewMaskAsOutgoing = - [interaction isKindOfClass:[TSOutgoingMessage class]]; + adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment; break; } else if ([stream isImage]) { adapter.mediaItem = [[TSPhotoAdapter alloc] initWithAttachment:stream incoming:isIncomingAttachment]; - adapter.mediaItem.appliesMediaViewMaskAsOutgoing = - [interaction isKindOfClass:[TSOutgoingMessage class]]; + adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment; break; } else if ([stream isVideo]) { adapter.mediaItem = [[TSVideoAttachmentAdapter alloc] initWithAttachment:stream incoming:[interaction isKindOfClass:[TSIncomingMessage class]]]; - adapter.mediaItem.appliesMediaViewMaskAsOutgoing = - [interaction isKindOfClass:[TSOutgoingMessage class]]; + adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment; break; } else { adapter.mediaItem = [[TSGenericAttachmentAdapter alloc] initWithAttachment:stream incoming:[interaction isKindOfClass:[TSIncomingMessage class]]]; - adapter.mediaItem.appliesMediaViewMaskAsOutgoing = YES; + adapter.mediaItem.appliesMediaViewMaskAsOutgoing = !isIncomingAttachment; break; } } else if ([attachment isKindOfClass:[TSAttachmentPointer class]]) { @@ -402,3 +402,5 @@ } @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.h b/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.h index b824c2a8c..5c44c5110 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.h +++ b/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.h @@ -5,6 +5,8 @@ #import "OWSMessageEditing.h" #import +NS_ASSUME_NONNULL_BEGIN + @class TSAttachmentStream; @interface TSPhotoAdapter : JSQPhotoMediaItem @@ -15,3 +17,5 @@ @property NSString *attachmentId; @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.m index 71dcb51e2..0788b35d9 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSPhotoAdapter.m @@ -9,14 +9,18 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + @interface TSPhotoAdapter () -@property (nonatomic) UIImageView *cachedImageView; -@property (nonatomic) AttachmentUploadView *attachmentUploadView; +@property (nonatomic, nullable) UIImageView *cachedImageView; +@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView; @property (nonatomic) BOOL incoming; @end +#pragma mark - + @implementation TSPhotoAdapter - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming @@ -126,3 +130,5 @@ } @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.h b/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.h index 0829cdd0a..e735d9bfd 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.h +++ b/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.h @@ -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 +NS_ASSUME_NONNULL_BEGIN + @class TSAttachmentStream; @interface TSVideoAttachmentAdapter : JSQVideoMediaItem @@ -24,3 +27,5 @@ - (void)resetAudioDuration; @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m index 93b7b60e8..c5db763e3 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSVideoAttachmentAdapter.m @@ -14,22 +14,23 @@ #import #define AUDIO_BAR_HEIGHT 36 +NS_ASSUME_NONNULL_BEGIN + @interface TSVideoAttachmentAdapter () @property (nonatomic) UIImage *image; -@property (nonatomic) UIImageView *cachedImageView; -@property (nonatomic) UIImageView *videoPlayButton; +@property (nonatomic, nullable) UIImageView *cachedImageView; @property (nonatomic) TSAttachmentStream *attachment; -@property (nonatomic) UIProgressView *audioProgress; -@property (nonatomic) SCWaveformView *waveform; -@property (nonatomic) UIButton *audioPlayPauseButton; -@property (nonatomic) UILabel *durationLabel; -@property (nonatomic) UIView *audioBubble; +@property (nonatomic, nullable) SCWaveformView *waveform; +@property (nonatomic, nullable) UIButton *audioPlayPauseButton; +@property (nonatomic, nullable) UILabel *durationLabel; @property (nonatomic) BOOL incoming; -@property (nonatomic) AttachmentUploadView *attachmentUploadView; +@property (nonatomic, nullable) AttachmentUploadView *attachmentUploadView; @end +#pragma mark - + @implementation TSVideoAttachmentAdapter - (instancetype)initWithAttachment:(TSAttachmentStream *)attachment incoming:(BOOL)incoming { @@ -113,17 +114,15 @@ isOutgoing:self.appliesMediaViewMaskAsOutgoing]; self.cachedImageView = imageView; UIImage *img = [UIImage imageNamed:@"play_button"]; - _videoPlayButton = [[UIImageView alloc] initWithImage:img]; - _videoPlayButton.frame = CGRectMake((size.width / 2) - 18, (size.height / 2) - 18, 37, 37); - [self.cachedImageView addSubview:_videoPlayButton]; + UIImageView *videoPlayButton = [[UIImageView alloc] initWithImage:img]; + videoPlayButton.frame = CGRectMake((size.width / 2) - 18, (size.height / 2) - 18, 37, 37); + [self.cachedImageView addSubview:videoPlayButton]; if (!_incoming) { - __weak TSVideoAttachmentAdapter *weakSelf = self; self.attachmentUploadView = [[AttachmentUploadView alloc] initWithAttachment:self.attachment superview:imageView attachmentStateCallback:^(BOOL isAttachmentReady) { - weakSelf.videoPlayButton.hidden - = !isAttachmentReady; + videoPlayButton.hidden = !isAttachmentReady; }]; } } @@ -143,11 +142,11 @@ self.waveform.progress = 0.0; } - _audioBubble = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, size.width, size.height)]; - _audioBubble.backgroundColor = + UIView *audioBubble = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, size.width, size.height)]; + audioBubble.backgroundColor = [UIColor colorWithRed:10 / 255.0f green:130 / 255.0f blue:253 / 255.0f alpha:1.0f]; - _audioBubble.layer.cornerRadius = 18; - _audioBubble.layer.masksToBounds = YES; + audioBubble.layer.cornerRadius = 18; + audioBubble.layer.masksToBounds = YES; _audioPlayPauseButton = [[UIButton alloc] initWithFrame:CGRectMake(3, 3, 30, 30)]; [_audioPlayPauseButton setBackgroundImage:[UIImage imageNamed:@"audio_play_button"] @@ -166,7 +165,7 @@ _durationLabel.textColor = [UIColor whiteColor]; if (_incoming) { - _audioBubble.backgroundColor = + audioBubble.backgroundColor = [UIColor colorWithRed:229 / 255.0f green:228 / 255.0f blue:234 / 255.0f alpha:1.0f]; _waveform.normalColor = [UIColor whiteColor]; _waveform.progressColor = @@ -176,21 +175,21 @@ _durationLabel.textColor = [UIColor darkTextColor]; } - [_audioBubble addSubview:_waveform]; - [_audioBubble addSubview:_audioPlayPauseButton]; - [_audioBubble addSubview:_durationLabel]; + [audioBubble addSubview:_waveform]; + [audioBubble addSubview:_audioPlayPauseButton]; + [audioBubble addSubview:_durationLabel]; if (!_incoming) { __weak TSVideoAttachmentAdapter *weakSelf = self; self.attachmentUploadView = [[AttachmentUploadView alloc] initWithAttachment:self.attachment - superview:_audioBubble + superview:audioBubble attachmentStateCallback:^(BOOL isAttachmentReady) { weakSelf.audioPlayPauseButton.enabled = isAttachmentReady; }]; } - return _audioBubble; + return audioBubble; } else { // Unknown media type. OWSAssert(0); @@ -280,3 +279,5 @@ } @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/view controllers/AttachmentApprovalViewController.swift b/Signal/src/view controllers/AttachmentApprovalViewController.swift index db57b8f1b..b6df468b5 100644 --- a/Signal/src/view controllers/AttachmentApprovalViewController.swift +++ b/Signal/src/view controllers/AttachmentApprovalViewController.swift @@ -21,7 +21,7 @@ class AttachmentApprovalViewController: UIViewController { self.attachment = SignalAttachment.genericAttachment(data: nil, dataUTI: kUTTypeContent as String) super.init(coder: aDecoder) - assert(false) + assertionFailure() } required init(attachment: SignalAttachment, successCompletion : @escaping () -> Void) { diff --git a/Signal/src/view controllers/SignalAttachment.swift b/Signal/src/view controllers/SignalAttachment.swift index 57f6265f5..30421e9fb 100644 --- a/Signal/src/view controllers/SignalAttachment.swift +++ b/Signal/src/view controllers/SignalAttachment.swift @@ -116,7 +116,7 @@ class SignalAttachment: NSObject { var errorName: String? { guard let error = error else { // This method should only be called if there is an error. - assert(false) + assertionFailure() return nil } @@ -126,7 +126,7 @@ class SignalAttachment: NSObject { var localizedErrorDescription: String? { guard let error = self.error else { // This method should only be called if there is an error. - assert(false) + assertionFailure() return nil } @@ -158,8 +158,8 @@ class SignalAttachment: NSObject { var fileExtension: String? { if dataUTI == SignalAttachment.kOversizeTextAttachmentUTI || dataUTI == SignalAttachment.kUnknownTestAttachmentUTI { - assert(false) - return "" + assertionFailure() + return nil } guard let fileExtension = UTTypeCopyPreferredTagWithClass(dataUTI as CFString,