Fix SAE, limit max attachments

pull/1/head
Michael Kirk 6 years ago
parent f7e0448f1b
commit 1a5c47df2f

@ -90,8 +90,6 @@
@import Photos; @import Photos;
#define FEATURE_FLAG_ALBUM_SEND_ENABLED
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
static const CGFloat kLoadMoreHeaderHeight = 60.f; static const CGFloat kLoadMoreHeaderHeight = 60.f;
@ -2640,17 +2638,20 @@ typedef enum : NSUInteger {
return; return;
} }
#ifdef FEATURE_FLAG_ALBUM_SEND_ENABLED UIViewController *pickerModal;
OWSImagePickerGridController *picker = [OWSImagePickerGridController new]; if (SignalAttachment.isMultiSendEnabled) {
picker.delegate = self; OWSImagePickerGridController *picker = [OWSImagePickerGridController new];
picker.delegate = self;
OWSNavigationController *pickerModal = [[OWSNavigationController alloc] initWithRootViewController:picker]; pickerModal = [[OWSNavigationController alloc] initWithRootViewController:picker];
#else } else {
UIImagePickerController *pickerModal = [UIImagePickerController new]; UIImagePickerController *picker = [UIImagePickerController new];
pickerModal.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
pickerModal.delegate = self; picker.delegate = self;
pickerModal.mediaTypes = @[ (__bridge NSString *)kUTTypeImage, (__bridge NSString *)kUTTypeMovie ]; picker.mediaTypes = @[ (__bridge NSString *)kUTTypeImage, (__bridge NSString *)kUTTypeMovie ];
#endif
pickerModal = picker;
}
[self dismissKeyBoard]; [self dismissKeyBoard];
[self presentViewController:pickerModal animated:YES completion:nil]; [self presentViewController:pickerModal animated:YES completion:nil];
@ -2762,10 +2763,11 @@ typedef enum : NSUInteger {
}]; }];
} else { } else {
// Non-Video image picked from library // Non-Video image picked from library
#ifdef FEATURE_FLAG_ALBUM_SEND_ENABLED if (SignalAttachment.isMultiSendEnabled) {
OWSFailDebug( OWSFailDebug(@"Only use UIImagePicker for camera/video capture. Picking media from UIImagePicker is not "
@"Only use UIImagePicker for camera/video capture. Picking media from UIImagePicker is not supported. "); @"supported. ");
#endif }
// To avoid re-encoding GIF and PNG's as JPEG we have to get the raw data of // To avoid re-encoding GIF and PNG's as JPEG we have to get the raw data of
// the selected item vs. using the UIImagePickerControllerOriginalImage // the selected item vs. using the UIImagePickerControllerOriginalImage

@ -260,30 +260,33 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
#pragma mark - AttachmentApprovalViewControllerDelegate #pragma mark - AttachmentApprovalViewControllerDelegate
- (void)attachmentApproval:(AttachmentApprovalViewController *)approvalViewController - (void)attachmentApproval:(AttachmentApprovalViewController *_Nonnull)attachmentApproval
didApproveAttachments:(NSArray<SignalAttachment *> *)attachments didApproveAttachments:(NSArray<SignalAttachment *> *_Nonnull)attachments
messageText:(NSString *_Nullable)messageText
{ {
[ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:self.thread]; [ThreadUtil addThreadToProfileWhitelistIfEmptyContactThread:self.thread];
[self tryToSendMessageWithBlock:^(SendCompletionBlock sendCompletion) { [self
OWSAssertIsOnMainThread(); tryToSendMessageWithBlock:^(SendCompletionBlock sendCompletion) {
OWSAssertIsOnMainThread();
__block TSOutgoingMessage *outgoingMessage = nil;
// DURABLE CLEANUP - SAE uses non-durable sending to make sure the app is running long enough to complete __block TSOutgoingMessage *outgoingMessage = nil;
// the sending operation. Alternatively, we could use a durable send, but do more to make sure the // DURABLE CLEANUP - SAE uses non-durable sending to make sure the app is running long enough to complete
// SAE runs as long as it needs. // the sending operation. Alternatively, we could use a durable send, but do more to make sure the
// TODO ALBUMS - send album via SAE // SAE runs as long as it needs.
outgoingMessage = [ThreadUtil sendMessageNonDurablyWithAttachments:attachments // TODO ALBUMS - send album via SAE
inThread:self.thread outgoingMessage = [ThreadUtil sendMessageNonDurablyWithAttachments:attachments
quotedReplyModel:nil inThread:self.thread
messageSender:self.messageSender messageBody:messageText
completion:^(NSError *_Nullable error) { quotedReplyModel:nil
sendCompletion(error, outgoingMessage); messageSender:self.messageSender
}]; completion:^(NSError *_Nullable error) {
sendCompletion(error, outgoingMessage);
}];
// This is necessary to show progress. // This is necessary to show progress.
self.outgoingMessage = outgoingMessage; self.outgoingMessage = outgoingMessage;
} }
fromViewController:approvalViewController]; fromViewController:attachmentApproval];
} }
- (void)attachmentApproval:(AttachmentApprovalViewController *)attachmentApproval - (void)attachmentApproval:(AttachmentApprovalViewController *)attachmentApproval

@ -190,6 +190,16 @@ public class SignalAttachment: NSObject {
static let kMaxFileSizeAudio = OWSMediaUtils.kMaxFileSizeAudio static let kMaxFileSizeAudio = OWSMediaUtils.kMaxFileSizeAudio
static let kMaxFileSizeGeneric = OWSMediaUtils.kMaxFileSizeGeneric static let kMaxFileSizeGeneric = OWSMediaUtils.kMaxFileSizeGeneric
// MARK:
@objc
public static let isMultiSendEnabled = true
@objc
public static var maxAttachmentsAllowed: Int {
return isMultiSendEnabled ? 32 : 1
}
// MARK: Constructor // MARK: Constructor
// This method should not be called directly; use the factory // This method should not be called directly; use the factory

@ -74,6 +74,7 @@ NS_ASSUME_NONNULL_BEGIN
// Used by SAE, otherwise we should use the durable `enqueue` counterpart // Used by SAE, otherwise we should use the durable `enqueue` counterpart
+ (TSOutgoingMessage *)sendMessageNonDurablyWithAttachments:(NSArray<SignalAttachment *> *)attachments + (TSOutgoingMessage *)sendMessageNonDurablyWithAttachments:(NSArray<SignalAttachment *> *)attachments
inThread:(TSThread *)thread inThread:(TSThread *)thread
messageBody:(nullable NSString *)messageBody
quotedReplyModel:(nullable OWSQuotedReplyModel *)quotedReplyModel quotedReplyModel:(nullable OWSQuotedReplyModel *)quotedReplyModel
messageSender:(OWSMessageSender *)messageSender messageSender:(OWSMessageSender *)messageSender
completion:(void (^_Nullable)(NSError *_Nullable error))completion; completion:(void (^_Nullable)(NSError *_Nullable error))completion;

@ -215,6 +215,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (TSOutgoingMessage *)sendMessageNonDurablyWithAttachments:(NSArray<SignalAttachment *> *)attachments + (TSOutgoingMessage *)sendMessageNonDurablyWithAttachments:(NSArray<SignalAttachment *> *)attachments
inThread:(TSThread *)thread inThread:(TSThread *)thread
messageBody:(nullable NSString *)messageBody
quotedReplyModel:(nullable OWSQuotedReplyModel *)quotedReplyModel quotedReplyModel:(nullable OWSQuotedReplyModel *)quotedReplyModel
messageSender:(OWSMessageSender *)messageSender messageSender:(OWSMessageSender *)messageSender
completion:(void (^_Nullable)(NSError *_Nullable error))completion completion:(void (^_Nullable)(NSError *_Nullable error))completion
@ -229,7 +230,6 @@ NS_ASSUME_NONNULL_BEGIN
uint32_t expiresInSeconds = (configuration.isEnabled ? configuration.durationSeconds : 0); uint32_t expiresInSeconds = (configuration.isEnabled ? configuration.durationSeconds : 0);
BOOL isVoiceMessage = (attachments.count == 1 && attachments.firstObject.isVoiceMessage); BOOL isVoiceMessage = (attachments.count == 1 && attachments.firstObject.isVoiceMessage);
NSString *_Nullable messageBody = (attachments.count == 1 ? attachments.firstObject.captionText : nil);
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp] [[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread inThread:thread

@ -966,14 +966,15 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
} }
private func buildAttachments() -> Promise<[SignalAttachment]> { private func buildAttachments() -> Promise<[SignalAttachment]> {
let promise = selectItemProviders().then { [weak self] (itemProviders) -> Promise<[SignalAttachment]> in return selectItemProviders().then { [weak self] (itemProviders) -> Promise<[SignalAttachment]> in
guard let strongSelf = self else { guard let strongSelf = self else {
let error = ShareViewControllerError.assertionError(description: "expired") let error = ShareViewControllerError.assertionError(description: "expired")
return Promise(error: error) return Promise(error: error)
} }
var loadPromises = [Promise<SignalAttachment>]() var loadPromises = [Promise<SignalAttachment>]()
for itemProvider in itemProviders {
for itemProvider in itemProviders.prefix(SignalAttachment.maxAttachmentsAllowed) {
let loadPromise = strongSelf.loadItemProvider(itemProvider: itemProvider) let loadPromise = strongSelf.loadItemProvider(itemProvider: itemProvider)
.then({ (loadedItem) -> Promise<SignalAttachment> in .then({ (loadedItem) -> Promise<SignalAttachment> in
return strongSelf.buildAttachment(forLoadedItem: loadedItem) return strongSelf.buildAttachment(forLoadedItem: loadedItem)
@ -982,15 +983,13 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
loadPromises.append(loadPromise) loadPromises.append(loadPromise)
} }
return when(fulfilled: loadPromises) return when(fulfilled: loadPromises)
}.map { (signalAttachments) -> [SignalAttachment] in }.map { (signalAttachments) -> [SignalAttachment] in
guard signalAttachments.count > 0 else { guard signalAttachments.count > 0 else {
let error = ShareViewControllerError.assertionError(description: "no valid attachments") let error = ShareViewControllerError.assertionError(description: "no valid attachments")
throw error throw error
}
return signalAttachments
} }
promise.retainUntilComplete() return signalAttachments
return promise }
} }
// Some host apps (e.g. iOS Photos.app) sometimes auto-converts some video formats (e.g. com.apple.quicktime-movie) // Some host apps (e.g. iOS Photos.app) sometimes auto-converts some video formats (e.g. com.apple.quicktime-movie)

Loading…
Cancel
Save