Skip to content

Commit 58266a3

Browse files
LunarXKevinBoulongne
authored andcommitted
refactor: Make sure that we always update the Attachment upload status if the API call succeeded
1 parent 8084b10 commit 58266a3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/src/main/java/com/infomaniak/mail/utils/extensions/AttachmentExtensions.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Infomaniak Mail - Android
3-
* Copyright (C) 2023-2024 Infomaniak Network SA
3+
* Copyright (C) 2023-2025 Infomaniak Network SA
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -45,6 +45,8 @@ import com.infomaniak.mail.utils.WorkerUtils.UploadMissingLocalFileException
4545
import com.infomaniak.mail.utils.extensions.AttachmentExtensions.AttachmentIntentType.OPEN_WITH
4646
import com.infomaniak.mail.utils.extensions.AttachmentExtensions.AttachmentIntentType.SAVE_TO_DRIVE
4747
import io.realm.kotlin.Realm
48+
import kotlinx.coroutines.NonCancellable
49+
import kotlinx.coroutines.withContext
4850
import okhttp3.MediaType.Companion.toMediaType
4951
import okhttp3.Request
5052
import okhttp3.RequestBody.Companion.asRequestBody
@@ -155,7 +157,9 @@ object AttachmentExtensions {
155157

156158
val apiResponse = ApiController.json.decodeFromString<ApiResponse<Attachment>>(response.body?.string() ?: "")
157159
if (apiResponse.isSuccess() && apiResponse.data != null) {
158-
updateLocalAttachment(draftLocalUuid, apiResponse.data!!, draftController, realm)
160+
withContext(NonCancellable) {
161+
updateLocalAttachment(draftLocalUuid, apiResponse.data!!, draftController, realm)
162+
}
159163
} else {
160164
val baseMessage = "Upload failed for attachment $localUuid"
161165
val errorMessage = "error : ${apiResponse.translatedError}"

0 commit comments

Comments
 (0)