Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 90eebb3d7d
commit c0f5bda2be

@ -379,21 +379,18 @@
[ModalActivityIndicatorViewController [ModalActivityIndicatorViewController
presentFromViewController:self presentFromViewController:self
canCancel:NO canCancel:NO
presentCompletion:^(ModalActivityIndicatorViewController *modalActivityIndicator) { backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [TSAccountManager unregisterTextSecureWithSuccess:^{
[TSAccountManager unregisterTextSecureWithSuccess:^{ [Environment resetAppData];
[Environment resetAppData]; }
} failure:^(NSError *error) {
failure:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{ [modalActivityIndicator dismissWithCompletion:^{
[modalActivityIndicator dismissWithCompletion:^{ [OWSAlerts showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")];
[OWSAlerts }];
showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")]; });
}]; }];
}); }];
}];
});
}];
} }
#pragma mark - Socket Status Notifications #pragma mark - Socket Status Notifications

@ -3456,50 +3456,48 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
[ModalActivityIndicatorViewController [ModalActivityIndicatorViewController
presentFromViewController:self presentFromViewController:self
canCancel:YES canCancel:YES
presentCompletion:^(ModalActivityIndicatorViewController *modalActivityIndicator) { backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ AVAsset *video = [AVAsset assetWithURL:movieURL];
AVAsset *video = [AVAsset assetWithURL:movieURL]; AVAssetExportSession *exportSession =
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:video
[AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetMediumQuality];
presetName:AVAssetExportPresetMediumQuality]; exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.shouldOptimizeForNetworkUse = YES; exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.outputFileType = AVFileTypeMPEG4; NSURL *compressedVideoUrl = [[self videoTempFolder]
NSURL *compressedVideoUrl = [[self videoTempFolder] URLByAppendingPathComponent:[[[NSUUID UUID] UUIDString]
URLByAppendingPathComponent:[[[NSUUID UUID] UUIDString] stringByAppendingPathExtension:@"mp4"]];
stringByAppendingPathExtension:@"mp4"]]; exportSession.outputURL = compressedVideoUrl;
exportSession.outputURL = compressedVideoUrl; [exportSession exportAsynchronouslyWithCompletionHandler:^{
[exportSession exportAsynchronouslyWithCompletionHandler:^{ dispatch_async(dispatch_get_main_queue(), ^{
dispatch_async(dispatch_get_main_queue(), ^{ OWSAssert([NSThread isMainThread]);
OWSAssert([NSThread isMainThread]);
if (modalActivityIndicator.wasCancelled) {
if (modalActivityIndicator.wasCancelled) { return;
return; }
}
[modalActivityIndicator dismissWithCompletion:^{
[modalActivityIndicator dismissWithCompletion:^{ DataSource *_Nullable dataSource =
DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithURL:compressedVideoUrl];
[DataSourcePath dataSourceWithURL:compressedVideoUrl]; [dataSource setSourceFilename:filename];
[dataSource setSourceFilename:filename]; // Remove temporary file when complete.
// Remove temporary file when complete. [dataSource setShouldDeleteOnDeallocation];
[dataSource setShouldDeleteOnDeallocation]; SignalAttachment *attachment =
SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:(NSString *)kUTTypeMPEG4];
dataUTI:(NSString *)kUTTypeMPEG4]; if (!attachment || [attachment hasError]) {
if (!attachment || [attachment hasError]) { DDLogError(@"%@ %s Invalid attachment: %@.",
DDLogError(@"%@ %s Invalid attachment: %@.", self.tag,
self.tag, __PRETTY_FUNCTION__,
__PRETTY_FUNCTION__, attachment ? [attachment errorName] : @"Missing data");
attachment ? [attachment errorName] : @"Missing data"); [self showErrorAlertForAttachment:attachment];
[self showErrorAlertForAttachment:attachment]; } else {
} else { [self tryToSendAttachmentIfApproved:attachment
[self tryToSendAttachmentIfApproved:attachment skipApprovalDialog:skipApprovalDialog];
skipApprovalDialog:skipApprovalDialog]; }
} }];
}]; });
}); }];
}]; }];
});
}];
} }

@ -36,7 +36,7 @@ class ModalActivityIndicatorViewController: OWSViewController {
} }
public class func present(fromViewController: UIViewController, public class func present(fromViewController: UIViewController,
canCancel: Bool, presentCompletion : @escaping (ModalActivityIndicatorViewController) -> Void) { canCancel: Bool, backgroundBlock : @escaping (ModalActivityIndicatorViewController) -> Void) {
AssertIsOnMainThread() AssertIsOnMainThread()
let view = ModalActivityIndicatorViewController(canCancel:canCancel) let view = ModalActivityIndicatorViewController(canCancel:canCancel)
@ -44,7 +44,9 @@ class ModalActivityIndicatorViewController: OWSViewController {
view.modalPresentationStyle = .overFullScreen view.modalPresentationStyle = .overFullScreen
fromViewController.present(view, fromViewController.present(view,
animated: false) { animated: false) {
presentCompletion(view) DispatchQueue.global().async {
backgroundBlock(view)
}
} }
} }

@ -486,29 +486,31 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
[ModalActivityIndicatorViewController [ModalActivityIndicatorViewController
presentFromViewController:self presentFromViewController:self
canCancel:NO canCancel:NO
presentCompletion:^(ModalActivityIndicatorViewController *modalActivityIndicator) { backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
TSOutgoingMessage *message = TSOutgoingMessage *message =
[[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread inThread:thread
groupMetaMessage:TSGroupMessageNew]; groupMetaMessage:TSGroupMessageNew];
// This will save the message. // This will save the message.
[message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)]; [message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)];
if (model.groupImage) { dispatch_async(dispatch_get_main_queue(), ^{
NSData *data = UIImagePNGRepresentation(model.groupImage); if (model.groupImage) {
DataSource *_Nullable dataSource = NSData *data = UIImagePNGRepresentation(model.groupImage);
[DataSourceValue dataSourceWithData:data fileExtension:@"png"]; DataSource *_Nullable dataSource =
[self.messageSender sendAttachmentData:dataSource [DataSourceValue dataSourceWithData:data fileExtension:@"png"];
contentType:OWSMimeTypeImagePng [self.messageSender sendAttachmentData:dataSource
sourceFilename:nil contentType:OWSMimeTypeImagePng
inMessage:message sourceFilename:nil
success:successHandler inMessage:message
failure:failureHandler]; success:successHandler
} else { failure:failureHandler];
[self.messageSender sendMessage:message success:successHandler failure:failureHandler]; } else {
} [self.messageSender sendMessage:message success:successHandler failure:failureHandler];
}]; }
});
}];
} }
- (TSGroupModel *)makeGroup - (TSGroupModel *)makeGroup

@ -310,41 +310,38 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
[ModalActivityIndicatorViewController [ModalActivityIndicatorViewController
presentFromViewController:self presentFromViewController:self
canCancel:YES canCancel:YES
presentCompletion:^(ModalActivityIndicatorViewController *modalActivityIndicator) { backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [[ContactsUpdater sharedUpdater] lookupIdentifiers:possiblePhoneNumbers
[[ContactsUpdater sharedUpdater] lookupIdentifiers:possiblePhoneNumbers success:^(NSArray<SignalRecipient *> *recipients) {
success:^(NSArray<SignalRecipient *> *recipients) { OWSAssert([NSThread isMainThread]);
OWSAssert([NSThread isMainThread]); OWSAssert(recipients.count > 0);
OWSAssert(recipients.count > 0);
if (modalActivityIndicator.wasCancelled) {
if (modalActivityIndicator.wasCancelled) { return;
return; }
}
NSString *recipientId = recipients[0].uniqueId;
NSString *recipientId = recipients[0].uniqueId; [modalActivityIndicator
[modalActivityIndicator dismissViewControllerAnimated:NO
dismissViewControllerAnimated:NO completion:^{
completion:^{ [weakSelf.delegate phoneNumberWasSelected:recipientId];
[weakSelf.delegate phoneNumberWasSelected:recipientId]; }];
}]; }
} failure:^(NSError *error) {
failure:^(NSError *error) { OWSAssert([NSThread isMainThread]);
OWSAssert([NSThread isMainThread]); if (modalActivityIndicator.wasCancelled) {
if (modalActivityIndicator.wasCancelled) { return;
return; }
} [modalActivityIndicator
[modalActivityIndicator dismissViewControllerAnimated:NO
dismissViewControllerAnimated:NO completion:^{
completion:^{ [OWSAlerts showAlertWithTitle:
[OWSAlerts NSLocalizedString(@"ALERT_ERROR_TITLE",
showAlertWithTitle: @"Title for a generic error alert.")
NSLocalizedString(@"ALERT_ERROR_TITLE", message:error.localizedDescription];
@"Title for a generic error alert.") }];
message:error.localizedDescription]; }];
}]; }];
}];
});
}];
} else { } else {
NSString *recipientId = possiblePhoneNumbers[0]; NSString *recipientId = possiblePhoneNumbers[0];
[self.delegate phoneNumberWasSelected:recipientId]; [self.delegate phoneNumberWasSelected:recipientId];

Loading…
Cancel
Save