@ -1,6 +1,8 @@
import UIKit
import CoreServices
import CoreServices
import Photos
import Photos
import PhotosUI
import PhotosUI
import SignalUtilitiesKit
extension ConversationVC : InputViewDelegate , MessageCellDelegate , ContextMenuActionDelegate , ScrollToBottomButtonDelegate ,
extension ConversationVC : InputViewDelegate , MessageCellDelegate , ContextMenuActionDelegate , ScrollToBottomButtonDelegate ,
SendMediaNavDelegate , UIDocumentPickerDelegate , AttachmentApprovalViewControllerDelegate , GifPickerViewControllerDelegate ,
SendMediaNavDelegate , UIDocumentPickerDelegate , AttachmentApprovalViewControllerDelegate , GifPickerViewControllerDelegate ,
@ -79,11 +81,13 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
}
}
func attachmentApproval ( _ attachmentApproval : AttachmentApprovalViewController , didApproveAttachments attachments : [ SignalAttachment ] , messageText : String ? ) {
func attachmentApproval ( _ attachmentApproval : AttachmentApprovalViewController , didApproveAttachments attachments : [ SignalAttachment ] , messageText : String ? ) {
sendAttachments ( attachments , with : messageText ? ? " " )
sendAttachments ( attachments , with : messageText ? ? " " ) { [ weak self ] in
self ? . dismiss ( animated : true , completion : nil )
}
scrollToBottom ( isAnimated : false )
scrollToBottom ( isAnimated : false )
resetMentions ( )
resetMentions ( )
self . snInputView . text = " "
self . snInputView . text = " "
dismiss ( animated : true ) { }
}
}
func attachmentApprovalDidCancel ( _ attachmentApproval : AttachmentApprovalViewController ) {
func attachmentApprovalDidCancel ( _ attachmentApproval : AttachmentApprovalViewController ) {
@ -198,7 +202,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
if ! attachment . hasError {
if ! attachment . hasError {
self ? . showAttachmentApprovalDialog ( for : [ attachment ] )
self ? . showAttachmentApprovalDialog ( for : [ attachment ] )
} else {
} else {
self ? . showErrorAlert ( for : attachment )
self ? . showErrorAlert ( for : attachment , onDismiss : nil )
}
}
}
}
} . retainUntilComplete ( )
} . retainUntilComplete ( )
@ -248,11 +252,11 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
} )
} )
}
}
func sendAttachments ( _ attachments : [ SignalAttachment ] , with text : String ) {
func sendAttachments ( _ attachments : [ SignalAttachment ] , with text : String , onComplete : ( ( ) -> ( ) ) ? = nil ) {
guard ! showBlockedModalIfNeeded ( ) else { return }
guard ! showBlockedModalIfNeeded ( ) else { return }
for attachment in attachments {
for attachment in attachments {
if attachment . hasError {
if attachment . hasError {
return showErrorAlert ( for : attachment )
return showErrorAlert ( for : attachment , onDismiss : onComplete )
}
}
}
}
let thread = self . thread
let thread = self . thread
@ -272,6 +276,9 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
self ? . scrollToBottom ( isAnimated : false )
self ? . scrollToBottom ( isAnimated : false )
} )
} )
self ? . handleMessageSent ( )
self ? . handleMessageSent ( )
// A t t a c h m e n t s u c c e s s f u l l y s e n t - d i s m i s s t h e s c r e e n
onComplete ? ( )
} )
} )
}
}
@ -849,7 +856,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
dataSource . sourceFilename = fileName
dataSource . sourceFilename = fileName
let attachment = SignalAttachment . voiceMessageAttachment ( dataSource : dataSource , dataUTI : kUTTypeMPEG4Audio as String )
let attachment = SignalAttachment . voiceMessageAttachment ( dataSource : dataSource , dataUTI : kUTTypeMPEG4Audio as String )
guard ! attachment . hasError else {
guard ! attachment . hasError else {
return showErrorAlert ( for : attachment )
return showErrorAlert ( for : attachment , onDismiss : nil )
}
}
// S e n d a t t a c h m e n t
// S e n d a t t a c h m e n t
sendAttachments ( [ attachment ] , with : " " )
sendAttachments ( [ attachment ] , with : " " )
@ -974,10 +981,14 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
}
}
}
}
// MARK: C o n v e n i e n c e
// MARK: - C o n v e n i e n c e
func showErrorAlert ( for attachment : SignalAttachment ) {
func showErrorAlert ( for attachment : SignalAttachment , onDismiss : ( ( ) -> ( ) ) ? ) {
let title = NSLocalizedString ( " ATTACHMENT_ERROR_ALERT_TITLE " , comment : " " )
let title = NSLocalizedString ( " ATTACHMENT_ERROR_ALERT_TITLE " , comment : " " )
let message = attachment . localizedErrorDescription ? ? SignalAttachment . missingDataErrorMessage
let message = attachment . localizedErrorDescription ? ? SignalAttachment . missingDataErrorMessage
OWSAlerts . showAlert ( title : title , message : message )
OWSAlerts . showAlert ( title : title , message : message , buttonTitle : nil ) { _ in
onDismiss ? ( )
}
}
}
}
}