Skip to content

Commit

Permalink
refactor: Make sure that we always update the Attachment upload statu…
Browse files Browse the repository at this point in the history
…s if the API call succeeded
  • Loading branch information
LunarX authored and KevinBoulongne committed Mar 10, 2025
1 parent 8084b10 commit 58266a3
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak Mail - Android
* Copyright (C) 2023-2024 Infomaniak Network SA
* Copyright (C) 2023-2025 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -45,6 +45,8 @@ import com.infomaniak.mail.utils.WorkerUtils.UploadMissingLocalFileException
import com.infomaniak.mail.utils.extensions.AttachmentExtensions.AttachmentIntentType.OPEN_WITH
import com.infomaniak.mail.utils.extensions.AttachmentExtensions.AttachmentIntentType.SAVE_TO_DRIVE
import io.realm.kotlin.Realm
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Request
import okhttp3.RequestBody.Companion.asRequestBody
Expand Down Expand Up @@ -155,7 +157,9 @@ object AttachmentExtensions {

val apiResponse = ApiController.json.decodeFromString<ApiResponse<Attachment>>(response.body?.string() ?: "")
if (apiResponse.isSuccess() && apiResponse.data != null) {
updateLocalAttachment(draftLocalUuid, apiResponse.data!!, draftController, realm)
withContext(NonCancellable) {
updateLocalAttachment(draftLocalUuid, apiResponse.data!!, draftController, realm)
}
} else {
val baseMessage = "Upload failed for attachment $localUuid"
val errorMessage = "error : ${apiResponse.translatedError}"
Expand Down

0 comments on commit 58266a3

Please sign in to comment.