Show attachment approval dialog for all attachments.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 255b3023f5
commit 660e4dd4c4

@ -2186,7 +2186,7 @@ typedef enum : NSUInteger {
[self showErrorAlertForAttachment:attachment]; [self showErrorAlertForAttachment:attachment];
failedToPickAttachment(nil); failedToPickAttachment(nil);
} else { } else {
[self sendMessageAttachment:attachment]; [self tryToSendAttachmentIfApproved:attachment];
} }
} else { } else {
failedToPickAttachment(nil); failedToPickAttachment(nil);
@ -2233,7 +2233,7 @@ typedef enum : NSUInteger {
[self showErrorAlertForAttachment:attachment]; [self showErrorAlertForAttachment:attachment];
failedToPickAttachment(nil); failedToPickAttachment(nil);
} else { } else {
[self sendMessageAttachment:attachment]; [self tryToSendAttachmentIfApproved:attachment];
} }
}]; }];
}]; }];
@ -2242,18 +2242,16 @@ typedef enum : NSUInteger {
- (void)sendMessageAttachment:(SignalAttachment *)attachment - (void)sendMessageAttachment:(SignalAttachment *)attachment
{ {
OWSAssert([NSThread isMainThread]);
// TODO: Should we assume non-nil or should we check for non-nil? // TODO: Should we assume non-nil or should we check for non-nil?
OWSAssert(attachment != nil); OWSAssert(attachment != nil);
OWSAssert(![attachment hasError]); OWSAssert(![attachment hasError]);
OWSAssert([attachment mimeType].length > 0); OWSAssert([attachment mimeType].length > 0);
DispatchMainThreadSafe(^{
DDLogVerbose(@"Sending attachment. Size in bytes: %lu, contentType: %@", DDLogVerbose(@"Sending attachment. Size in bytes: %lu, contentType: %@",
(unsigned long)attachment.data.length, (unsigned long)attachment.data.length,
[attachment mimeType]); [attachment mimeType]);
[ThreadUtil sendMessageWithAttachment:attachment [ThreadUtil sendMessageWithAttachment:attachment inThread:self.thread messageSender:self.messageSender];
inThread:self.thread
messageSender:self.messageSender];
TSOutgoingMessage *message; TSOutgoingMessage *message;
OWSDisappearingMessagesConfiguration *configuration = OWSDisappearingMessagesConfiguration *configuration =
@ -2270,7 +2268,6 @@ typedef enum : NSUInteger {
messageBody:nil messageBody:nil
attachmentIds:[NSMutableArray new]]; attachmentIds:[NSMutableArray new]];
} }
});
} }
- (NSURL *)videoTempFolder { - (NSURL *)videoTempFolder {
@ -2311,7 +2308,7 @@ typedef enum : NSUInteger {
attachment ? [attachment errorName] : @"Missing data"); attachment ? [attachment errorName] : @"Missing data");
[self showErrorAlertForAttachment:attachment]; [self showErrorAlertForAttachment:attachment];
} else { } else {
[self sendMessageAttachment:attachment]; [self tryToSendAttachmentIfApproved:attachment];
} }
NSError *error; NSError *error;
@ -2551,7 +2548,7 @@ typedef enum : NSUInteger {
attachment ? [attachment errorName] : @"Missing data"); attachment ? [attachment errorName] : @"Missing data");
[self showErrorAlertForAttachment:attachment]; [self showErrorAlertForAttachment:attachment];
} else { } else {
[self sendMessageAttachment:attachment]; [self tryToSendAttachmentIfApproved:attachment];
} }
} }
} }
@ -2772,6 +2769,14 @@ typedef enum : NSUInteger {
self.tag, self.tag,
__PRETTY_FUNCTION__); __PRETTY_FUNCTION__);
[self tryToSendAttachmentIfApproved:attachment];
}
- (void)tryToSendAttachmentIfApproved:(SignalAttachment *_Nullable)attachment
{
DDLogError(@"%@ %s", self.tag, __PRETTY_FUNCTION__);
DispatchMainThreadSafe(^{
if ([self isBlockedContactConversation]) { if ([self isBlockedContactConversation]) {
__weak MessagesViewController *weakSelf = self; __weak MessagesViewController *weakSelf = self;
[self showUnblockContactUI:^(BOOL isBlocked) { [self showUnblockContactUI:^(BOOL isBlocked) {
@ -2782,8 +2787,7 @@ typedef enum : NSUInteger {
return; return;
} }
if (attachment == nil || if (attachment == nil || [attachment hasError]) {
[attachment hasError]) {
DDLogWarn(@"%@ %s Invalid attachment: %@.", DDLogWarn(@"%@ %s Invalid attachment: %@.",
self.tag, self.tag,
__PRETTY_FUNCTION__, __PRETTY_FUNCTION__,
@ -2791,15 +2795,16 @@ typedef enum : NSUInteger {
[self showErrorAlertForAttachment:attachment]; [self showErrorAlertForAttachment:attachment];
} else { } else {
__weak MessagesViewController *weakSelf = self; __weak MessagesViewController *weakSelf = self;
UIViewController *viewController = [[AttachmentApprovalViewController alloc] initWithAttachment:attachment UIViewController *viewController =
[[AttachmentApprovalViewController alloc] initWithAttachment:attachment
successCompletion:^{ successCompletion:^{
[weakSelf sendMessageAttachment:attachment]; [weakSelf sendMessageAttachment:attachment];
}]; }];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; UINavigationController *navigationController =
[self.navigationController presentViewController:navigationController [[UINavigationController alloc] initWithRootViewController:viewController];
animated:YES [self.navigationController presentViewController:navigationController animated:YES completion:nil];
completion:nil];
} }
});
} }
- (void)showErrorAlertForAttachment:(SignalAttachment * _Nullable)attachment { - (void)showErrorAlertForAttachment:(SignalAttachment * _Nullable)attachment {

Loading…
Cancel
Save