Merge branch 'charlesmchen/modalActivityIndicatorCR'
This commit is contained in:
commit
8ceca76453
@ -379,21 +379,18 @@
|
||||
[ModalActivityIndicatorViewController
|
||||
presentFromViewController:self
|
||||
canCancel:NO
|
||||
presentCompletion:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[TSAccountManager unregisterTextSecureWithSuccess:^{
|
||||
[Environment resetAppData];
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[modalActivityIndicator dismissWithCompletion:^{
|
||||
[OWSAlerts
|
||||
showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")];
|
||||
}];
|
||||
});
|
||||
}];
|
||||
});
|
||||
}];
|
||||
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
|
||||
[TSAccountManager unregisterTextSecureWithSuccess:^{
|
||||
[Environment resetAppData];
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[modalActivityIndicator dismissWithCompletion:^{
|
||||
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"UNREGISTER_SIGNAL_FAIL", @"")];
|
||||
}];
|
||||
});
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Socket Status Notifications
|
||||
|
||||
@ -3456,50 +3456,48 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
|
||||
[ModalActivityIndicatorViewController
|
||||
presentFromViewController:self
|
||||
canCancel:YES
|
||||
presentCompletion:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
AVAsset *video = [AVAsset assetWithURL:movieURL];
|
||||
AVAssetExportSession *exportSession =
|
||||
[AVAssetExportSession exportSessionWithAsset:video
|
||||
presetName:AVAssetExportPresetMediumQuality];
|
||||
exportSession.shouldOptimizeForNetworkUse = YES;
|
||||
exportSession.outputFileType = AVFileTypeMPEG4;
|
||||
NSURL *compressedVideoUrl = [[self videoTempFolder]
|
||||
URLByAppendingPathComponent:[[[NSUUID UUID] UUIDString]
|
||||
stringByAppendingPathExtension:@"mp4"]];
|
||||
exportSession.outputURL = compressedVideoUrl;
|
||||
[exportSession exportAsynchronouslyWithCompletionHandler:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
|
||||
AVAsset *video = [AVAsset assetWithURL:movieURL];
|
||||
AVAssetExportSession *exportSession =
|
||||
[AVAssetExportSession exportSessionWithAsset:video
|
||||
presetName:AVAssetExportPresetMediumQuality];
|
||||
exportSession.shouldOptimizeForNetworkUse = YES;
|
||||
exportSession.outputFileType = AVFileTypeMPEG4;
|
||||
NSURL *compressedVideoUrl = [[self videoTempFolder]
|
||||
URLByAppendingPathComponent:[[[NSUUID UUID] UUIDString]
|
||||
stringByAppendingPathExtension:@"mp4"]];
|
||||
exportSession.outputURL = compressedVideoUrl;
|
||||
[exportSession exportAsynchronouslyWithCompletionHandler:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
|
||||
if (modalActivityIndicator.wasCancelled) {
|
||||
return;
|
||||
}
|
||||
if (modalActivityIndicator.wasCancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
[modalActivityIndicator dismissWithCompletion:^{
|
||||
DataSource *_Nullable dataSource =
|
||||
[DataSourcePath dataSourceWithURL:compressedVideoUrl];
|
||||
[dataSource setSourceFilename:filename];
|
||||
// Remove temporary file when complete.
|
||||
[dataSource setShouldDeleteOnDeallocation];
|
||||
SignalAttachment *attachment =
|
||||
[SignalAttachment attachmentWithDataSource:dataSource
|
||||
dataUTI:(NSString *)kUTTypeMPEG4];
|
||||
if (!attachment || [attachment hasError]) {
|
||||
DDLogError(@"%@ %s Invalid attachment: %@.",
|
||||
self.tag,
|
||||
__PRETTY_FUNCTION__,
|
||||
attachment ? [attachment errorName] : @"Missing data");
|
||||
[self showErrorAlertForAttachment:attachment];
|
||||
} else {
|
||||
[self tryToSendAttachmentIfApproved:attachment
|
||||
skipApprovalDialog:skipApprovalDialog];
|
||||
}
|
||||
}];
|
||||
});
|
||||
}];
|
||||
});
|
||||
}];
|
||||
[modalActivityIndicator dismissWithCompletion:^{
|
||||
DataSource *_Nullable dataSource =
|
||||
[DataSourcePath dataSourceWithURL:compressedVideoUrl];
|
||||
[dataSource setSourceFilename:filename];
|
||||
// Remove temporary file when complete.
|
||||
[dataSource setShouldDeleteOnDeallocation];
|
||||
SignalAttachment *attachment =
|
||||
[SignalAttachment attachmentWithDataSource:dataSource
|
||||
dataUTI:(NSString *)kUTTypeMPEG4];
|
||||
if (!attachment || [attachment hasError]) {
|
||||
DDLogError(@"%@ %s Invalid attachment: %@.",
|
||||
self.tag,
|
||||
__PRETTY_FUNCTION__,
|
||||
attachment ? [attachment errorName] : @"Missing data");
|
||||
[self showErrorAlertForAttachment:attachment];
|
||||
} else {
|
||||
[self tryToSendAttachmentIfApproved:attachment
|
||||
skipApprovalDialog:skipApprovalDialog];
|
||||
}
|
||||
}];
|
||||
});
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ class ModalActivityIndicatorViewController: OWSViewController {
|
||||
}
|
||||
|
||||
public class func present(fromViewController: UIViewController,
|
||||
canCancel: Bool, presentCompletion : @escaping (ModalActivityIndicatorViewController) -> Void) {
|
||||
canCancel: Bool, backgroundBlock : @escaping (ModalActivityIndicatorViewController) -> Void) {
|
||||
AssertIsOnMainThread()
|
||||
|
||||
let view = ModalActivityIndicatorViewController(canCancel:canCancel)
|
||||
@ -44,7 +44,9 @@ class ModalActivityIndicatorViewController: OWSViewController {
|
||||
view.modalPresentationStyle = .overFullScreen
|
||||
fromViewController.present(view,
|
||||
animated: false) {
|
||||
presentCompletion(view)
|
||||
DispatchQueue.global().async {
|
||||
backgroundBlock(view)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -486,29 +486,31 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68;
|
||||
[ModalActivityIndicatorViewController
|
||||
presentFromViewController:self
|
||||
canCancel:NO
|
||||
presentCompletion:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
|
||||
TSOutgoingMessage *message =
|
||||
[[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
||||
inThread:thread
|
||||
groupMetaMessage:TSGroupMessageNew];
|
||||
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
|
||||
TSOutgoingMessage *message =
|
||||
[[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
||||
inThread:thread
|
||||
groupMetaMessage:TSGroupMessageNew];
|
||||
|
||||
// This will save the message.
|
||||
[message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)];
|
||||
// This will save the message.
|
||||
[message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)];
|
||||
|
||||
if (model.groupImage) {
|
||||
NSData *data = UIImagePNGRepresentation(model.groupImage);
|
||||
DataSource *_Nullable dataSource =
|
||||
[DataSourceValue dataSourceWithData:data fileExtension:@"png"];
|
||||
[self.messageSender sendAttachmentData:dataSource
|
||||
contentType:OWSMimeTypeImagePng
|
||||
sourceFilename:nil
|
||||
inMessage:message
|
||||
success:successHandler
|
||||
failure:failureHandler];
|
||||
} else {
|
||||
[self.messageSender sendMessage:message success:successHandler failure:failureHandler];
|
||||
}
|
||||
}];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (model.groupImage) {
|
||||
NSData *data = UIImagePNGRepresentation(model.groupImage);
|
||||
DataSource *_Nullable dataSource =
|
||||
[DataSourceValue dataSourceWithData:data fileExtension:@"png"];
|
||||
[self.messageSender sendAttachmentData:dataSource
|
||||
contentType:OWSMimeTypeImagePng
|
||||
sourceFilename:nil
|
||||
inMessage:message
|
||||
success:successHandler
|
||||
failure:failureHandler];
|
||||
} else {
|
||||
[self.messageSender sendMessage:message success:successHandler failure:failureHandler];
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (TSGroupModel *)makeGroup
|
||||
|
||||
@ -310,41 +310,38 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
|
||||
[ModalActivityIndicatorViewController
|
||||
presentFromViewController:self
|
||||
canCancel:YES
|
||||
presentCompletion:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[[ContactsUpdater sharedUpdater] lookupIdentifiers:possiblePhoneNumbers
|
||||
success:^(NSArray<SignalRecipient *> *recipients) {
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
OWSAssert(recipients.count > 0);
|
||||
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
|
||||
[[ContactsUpdater sharedUpdater] lookupIdentifiers:possiblePhoneNumbers
|
||||
success:^(NSArray<SignalRecipient *> *recipients) {
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
OWSAssert(recipients.count > 0);
|
||||
|
||||
if (modalActivityIndicator.wasCancelled) {
|
||||
return;
|
||||
}
|
||||
if (modalActivityIndicator.wasCancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *recipientId = recipients[0].uniqueId;
|
||||
[modalActivityIndicator
|
||||
dismissViewControllerAnimated:NO
|
||||
completion:^{
|
||||
[weakSelf.delegate phoneNumberWasSelected:recipientId];
|
||||
}];
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
if (modalActivityIndicator.wasCancelled) {
|
||||
return;
|
||||
}
|
||||
[modalActivityIndicator
|
||||
dismissViewControllerAnimated:NO
|
||||
completion:^{
|
||||
[OWSAlerts
|
||||
showAlertWithTitle:
|
||||
NSLocalizedString(@"ALERT_ERROR_TITLE",
|
||||
@"Title for a generic error alert.")
|
||||
message:error.localizedDescription];
|
||||
}];
|
||||
}];
|
||||
});
|
||||
}];
|
||||
NSString *recipientId = recipients[0].uniqueId;
|
||||
[modalActivityIndicator
|
||||
dismissViewControllerAnimated:NO
|
||||
completion:^{
|
||||
[weakSelf.delegate phoneNumberWasSelected:recipientId];
|
||||
}];
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
OWSAssert([NSThread isMainThread]);
|
||||
if (modalActivityIndicator.wasCancelled) {
|
||||
return;
|
||||
}
|
||||
[modalActivityIndicator
|
||||
dismissViewControllerAnimated:NO
|
||||
completion:^{
|
||||
[OWSAlerts showAlertWithTitle:
|
||||
NSLocalizedString(@"ALERT_ERROR_TITLE",
|
||||
@"Title for a generic error alert.")
|
||||
message:error.localizedDescription];
|
||||
}];
|
||||
}];
|
||||
}];
|
||||
} else {
|
||||
NSString *recipientId = possiblePhoneNumbers[0];
|
||||
[self.delegate phoneNumberWasSelected:recipientId];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user