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,35 +2242,32 @@ 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 inThread:self.thread messageSender:self.messageSender];
[ThreadUtil sendMessageWithAttachment:attachment
inThread:self.thread TSOutgoingMessage *message;
messageSender:self.messageSender]; OWSDisappearingMessagesConfiguration *configuration =
TSOutgoingMessage *message;
OWSDisappearingMessagesConfiguration *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId]; [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId];
if (configuration.isEnabled) { if (configuration.isEnabled) {
message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:self.thread inThread:self.thread
messageBody:nil messageBody:nil
attachmentIds:[NSMutableArray new] attachmentIds:[NSMutableArray new]
expiresInSeconds:configuration.durationSeconds]; expiresInSeconds:configuration.durationSeconds];
} else { } else {
message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:self.thread inThread:self.thread
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,34 +2769,42 @@ typedef enum : NSUInteger {
self.tag, self.tag,
__PRETTY_FUNCTION__); __PRETTY_FUNCTION__);
if ([self isBlockedContactConversation]) { [self tryToSendAttachmentIfApproved:attachment];
__weak MessagesViewController *weakSelf = self; }
[self showUnblockContactUI:^(BOOL isBlocked) {
if (!isBlocked) {
[weakSelf didPasteAttachment:attachment];
}
}];
return;
}
if (attachment == nil || - (void)tryToSendAttachmentIfApproved:(SignalAttachment *_Nullable)attachment
[attachment hasError]) { {
DDLogWarn(@"%@ %s Invalid attachment: %@.", DDLogError(@"%@ %s", self.tag, __PRETTY_FUNCTION__);
self.tag,
__PRETTY_FUNCTION__, DispatchMainThreadSafe(^{
attachment ? [attachment errorName] : @"Missing data"); if ([self isBlockedContactConversation]) {
[self showErrorAlertForAttachment:attachment]; __weak MessagesViewController *weakSelf = self;
} else { [self showUnblockContactUI:^(BOOL isBlocked) {
__weak MessagesViewController *weakSelf = self; if (!isBlocked) {
UIViewController *viewController = [[AttachmentApprovalViewController alloc] initWithAttachment:attachment [weakSelf didPasteAttachment:attachment];
successCompletion:^{ }
[weakSelf sendMessageAttachment:attachment]; }];
}]; return;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; }
[self.navigationController presentViewController:navigationController
animated:YES if (attachment == nil || [attachment hasError]) {
completion:nil]; DDLogWarn(@"%@ %s Invalid attachment: %@.",
} self.tag,
__PRETTY_FUNCTION__,
attachment ? [attachment errorName] : @"Missing data");
[self showErrorAlertForAttachment:attachment];
} else {
__weak MessagesViewController *weakSelf = self;
UIViewController *viewController =
[[AttachmentApprovalViewController alloc] initWithAttachment:attachment
successCompletion:^{
[weakSelf sendMessageAttachment:attachment];
}];
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:viewController];
[self.navigationController presentViewController:navigationController animated:YES completion:nil];
}
});
} }
- (void)showErrorAlertForAttachment:(SignalAttachment * _Nullable)attachment { - (void)showErrorAlertForAttachment:(SignalAttachment * _Nullable)attachment {

Loading…
Cancel
Save