Fixed an issue with attching files when the max capacity per email exceeded. by jorgeblacio · Pull Request #546 · Criptext/Android-Email-Client · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,11 @@ class ComposerController(private val storage: KeyValueStorage,
is ComposerResult.UploadFile.Success -> {
val composerAttachment = getAttachmentByUUID(result.uuid)
composerAttachment?.uploadProgress = 100
model.isUploadingAttachments = false
model.filesSize = result.filesSize
handleNextUpload()
}
is ComposerResult.UploadFile.Failure -> {
removeAttachmentByPath(result.filepath)
removeAttachmentByUUID(result.uuid)
scene.showAttachmentErrorDialog(result.filepath)
handleNextUpload()
}
Expand All @@ -319,12 +318,13 @@ class ComposerController(private val storage: KeyValueStorage,
scene.showConfirmPasswordDialog(observer)
}
is ComposerResult.UploadFile.MaxFilesExceeds -> {
removeAttachmentByPath(result.filepath)
removeAttachmentByUUID(result.uuid, true)
model.filesExceedingMaxEmailSize.add(FileUtils.getName(result.filepath))
scene.showMaxFilesExceedsDialog()
handleNextUpload()
}
is ComposerResult.UploadFile.PayloadTooLarge -> {
removeAttachmentByPath(result.filepath)
removeAttachmentByUUID(result.uuid)
scene.showPayloadTooLargeDialog(result.filepath, result.headers.getLong("Max-Size"))
handleNextUpload()
}
Expand All @@ -339,8 +339,14 @@ class ComposerController(private val storage: KeyValueStorage,
return model.attachments.firstOrNull{it.uuid == uuid}
}

private fun removeAttachmentByPath(filepath: String) {
model.attachments.removeAll{it.filepath == filepath}
private fun removeAttachmentByUUID(uuid: String, removeRemaining: Boolean = false) {
if(!removeRemaining) {
model.attachments.removeAll { it.uuid == uuid }
} else {
val attachment = model.attachments.firstOrNull { it.uuid == uuid } ?: return
model.attachments.remove(attachment)
model.attachments.removeAll(model.attachments.filter { it.uploadProgress == -1 })
}
}

private fun onEmailSavesAsDraft(result: ComposerResult.SaveEmail) {
Expand Down Expand Up @@ -466,7 +472,6 @@ class ComposerController(private val storage: KeyValueStorage,
private fun isReadyForSending() = (model.to.isNotEmpty() || model.cc.isNotEmpty() || model.bcc.isNotEmpty())

private fun uploadSelectedFile(filepath: String, fileKey: String, uuid: String){
model.isUploadingAttachments = true
scene.dismissPreparingFileDialog()
dataSource.submitRequest(ComposerRequest.UploadAttachment(
filepath = filepath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ class ComposerModel(val type: ComposerType, val currentLabel: Label): SceneModel
val filesExceedingMaxEmailSize = mutableListOf<String>()
val filesExceedingMaxFileSize = mutableListOf<Pair<String, String>>()

var isUploadingAttachments = false
val isUploadingAttachments = when {
attachments.isEmpty() -> false
attachments.any { it.uploadProgress == -1 } -> true
attachments.any { it.uploadProgress in 0..99 } -> true
else -> false
}

var to = LinkedList<Contact>()
var cc = LinkedList<Contact>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ sealed class ComposerResult {
data class Success(val filepath: String, val filesSize: Long, val uuid: String): UploadFile()
data class Register(val filepath: String, val filetoken: String, val uuid: String): UploadFile()
data class Progress(val filepath: String, val percentage: Int, val uuid: String): UploadFile()
data class MaxFilesExceeds(val filepath: String): UploadFile()
data class PayloadTooLarge(val filepath: String, val headers: ResultHeaders): UploadFile()
data class Failure(val filepath: String, val message: UIMessage): UploadFile()
data class MaxFilesExceeds(val filepath: String, val uuid: String): UploadFile()
data class PayloadTooLarge(val filepath: String, val headers: ResultHeaders, val uuid: String): UploadFile()
data class Failure(val filepath: String, val message: UIMessage, val uuid: String): UploadFile()
data class Unauthorized(val message: UIMessage): UploadFile()
class Forbidden: UploadFile()
class EnterpriseSuspended(): UploadFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class UploadAttachmentWorker(private val filesSize: Long,
ex.errorCode == ServerCodes.Forbidden ->
ComposerResult.UploadFile.Forbidden()
ex.errorCode == ServerCodes.PayloadTooLarge ->
ComposerResult.UploadFile.PayloadTooLarge(filepath, ex.headers!!)
else -> ComposerResult.UploadFile.Failure(filepath, createErrorMessage(ex))
ComposerResult.UploadFile.PayloadTooLarge(filepath, ex.headers!!, uuid)
else -> ComposerResult.UploadFile.Failure(filepath, createErrorMessage(ex), uuid)
}
}
else ComposerResult.UploadFile.Failure(filepath, createErrorMessage(ex))
else ComposerResult.UploadFile.Failure(filepath, createErrorMessage(ex), uuid)


private fun MaxFilesExceeds(): ComposerResult.UploadFile =
ComposerResult.UploadFile.MaxFilesExceeds(filepath)
ComposerResult.UploadFile.MaxFilesExceeds(filepath, uuid)


private fun uploadFile(file: File, reporter: ProgressReporter<ComposerResult.UploadFile>): (String) -> Result<Unit, Exception> = { fileToken ->
Expand Down