@ -36,6 +36,7 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
override fun execute ( ) {
override fun execute ( ) {
val messageDataProvider = MessagingModuleConfiguration . shared . messageDataProvider
val messageDataProvider = MessagingModuleConfiguration . shared . messageDataProvider
val message = message as ? VisibleMessage
val message = message as ? VisibleMessage
val storage = MessagingModuleConfiguration . shared . storage
if ( message != null ) {
if ( message != null ) {
if ( ! messageDataProvider . isOutgoingMessage ( message . sentTimestamp !! ) ) return // The message has been deleted
if ( ! messageDataProvider . isOutgoingMessage ( message . sentTimestamp !! ) ) return // The message has been deleted
val attachmentIDs = mutableListOf < Long > ( )
val attachmentIDs = mutableListOf < Long > ( )
@ -45,7 +46,7 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
val attachments = attachmentIDs . mapNotNull { messageDataProvider . getDatabaseAttachment ( it ) }
val attachments = attachmentIDs . mapNotNull { messageDataProvider . getDatabaseAttachment ( it ) }
val attachmentsToUpload = attachments . filter { it . url . isNullOrEmpty ( ) }
val attachmentsToUpload = attachments . filter { it . url . isNullOrEmpty ( ) }
attachmentsToUpload . forEach {
attachmentsToUpload . forEach {
if ( MessagingModuleConfiguration . shared . storage . getAttachmentUploadJob ( it . attachmentId . rowId ) != null ) {
if ( storage . getAttachmentUploadJob ( it . attachmentId . rowId ) != null ) {
// Wait for it to finish
// Wait for it to finish
} else {
} else {
val job = AttachmentUploadJob ( it . attachmentId . rowId , message . threadID !! . toString ( ) , message , id !! )
val job = AttachmentUploadJob ( it . attachmentId . rowId , message . threadID !! . toString ( ) , message , id !! )
@ -57,6 +58,11 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
return
return
} // Wait for all attachments to upload before continuing
} // Wait for all attachments to upload before continuing
}
}
val sentTimestamp = this . message . sentTimestamp
val sender = storage . getUserPublicKey ( )
if ( sentTimestamp != null && sender != null ) {
storage . markAsSending ( sentTimestamp , sender )
}
val promise = MessageSender . send ( this . message , this . destination ) . success {
val promise = MessageSender . send ( this . message , this . destination ) . success {
this . handleSuccess ( )
this . handleSuccess ( )
} . fail { exception ->
} . fail { exception ->