@@ -20,7 +20,6 @@ package com.infomaniak.mail.ui
20
20
import android.app.Application
21
21
import androidx.lifecycle.*
22
22
import com.infomaniak.lib.core.models.ApiResponse
23
- import com.infomaniak.lib.core.networking.HttpUtils
24
23
import com.infomaniak.lib.core.networking.NetworkAvailability
25
24
import com.infomaniak.lib.core.utils.ApiErrorCode.Companion.translateError
26
25
import com.infomaniak.lib.core.utils.DownloadManagerUtils
@@ -30,7 +29,6 @@ import com.infomaniak.mail.MatomoMail.trackMultiSelectionEvent
30
29
import com.infomaniak.mail.R
31
30
import com.infomaniak.mail.data.LocalSettings
32
31
import com.infomaniak.mail.data.api.ApiRepository
33
- import com.infomaniak.mail.data.api.ApiRoutes
34
32
import com.infomaniak.mail.data.cache.RealmDatabase
35
33
import com.infomaniak.mail.data.cache.mailboxContent.FolderController
36
34
import com.infomaniak.mail.data.cache.mailboxContent.MessageController
@@ -60,6 +58,7 @@ import com.infomaniak.mail.utils.ContactUtils.getPhoneContacts
60
58
import com.infomaniak.mail.utils.ContactUtils.mergeApiContactsIntoPhoneContacts
61
59
import com.infomaniak.mail.utils.NotificationUtils.Companion.cancelNotification
62
60
import com.infomaniak.mail.utils.SharedUtils.Companion.updateSignatures
61
+ import com.infomaniak.mail.utils.Utils.EML_CONTENT_TYPE
63
62
import com.infomaniak.mail.utils.Utils.isPermanentDeleteFolder
64
63
import com.infomaniak.mail.utils.Utils.runCatchingRealm
65
64
import com.infomaniak.mail.utils.extensions.*
@@ -75,7 +74,6 @@ import io.sentry.Sentry
75
74
import io.sentry.SentryLevel
76
75
import kotlinx.coroutines.*
77
76
import kotlinx.coroutines.flow.*
78
- import okhttp3.Request
79
77
import java.util.Date
80
78
import java.util.UUID
81
79
import javax.inject.Inject
@@ -1019,29 +1017,19 @@ class MainViewModel @Inject constructor(
1019
1017
fun reportDisplayProblem (messageUid : String ) = viewModelScope.launch(ioCoroutineContext) {
1020
1018
1021
1019
val message = messageController.getMessage(messageUid) ? : return @launch
1022
-
1023
1020
val mailbox = currentMailbox.value ? : return @launch
1024
1021
1025
- val userApiToken = AccountUtils .getUserById(mailbox.userId)?.apiToken?.accessToken ? : return @launch
1026
- val headers = HttpUtils .getHeaders(contentType = null ).newBuilder()
1027
- .set(" Authorization" , " Bearer $userApiToken " )
1028
- .build()
1029
- val request = Request .Builder ().url(ApiRoutes .downloadMessage(mailbox.uuid, message.folderId, message.shortUid))
1030
- .headers(headers)
1031
- .get()
1032
- .build()
1033
-
1034
- val response = AccountUtils .getHttpClient(mailbox.userId).newCall(request).execute()
1022
+ val apiResponse = ApiRepository .getDownloadedMessage(mailbox.uuid, message.folderId, message.shortUid)
1035
1023
1036
- if (! response.isSuccessful || response. body == null ) {
1024
+ if (apiResponse. body == null || ! apiResponse.isSuccessful ) {
1037
1025
reportDisplayProblemTrigger.postValue(Unit )
1038
1026
snackbarManager.postValue(appContext.getString(RCore .string.anErrorHasOccurred))
1039
1027
1040
1028
return @launch
1041
1029
}
1042
1030
1043
1031
val filename = UUID .randomUUID().toString()
1044
- val emlAttachment = Attachment (response .body?.bytes(), filename, EML_CONTENT_TYPE )
1032
+ val emlAttachment = Attachment (apiResponse .body?.bytes(), filename, EML_CONTENT_TYPE )
1045
1033
Sentry .captureMessage(" Message display problem reported" , SentryLevel .ERROR ) { scope ->
1046
1034
scope.addAttachment(emlAttachment)
1047
1035
}
@@ -1191,7 +1179,7 @@ class MainViewModel @Inject constructor(
1191
1179
}
1192
1180
1193
1181
fun hasOtherExpeditors (threadUid : String ) = liveData(ioCoroutineContext) {
1194
- val hasOtherExpeditors = threadController.getThread(threadUid)?.messages?.flatMap { it.from }?.any { ! it.isMe() } ? : false
1182
+ val hasOtherExpeditors = threadController.getThread(threadUid)?.messages?.flatMap { it.from }?.any { ! it.isMe() } == true
1195
1183
emit(hasOtherExpeditors)
1196
1184
}
1197
1185
@@ -1312,6 +1300,5 @@ class MainViewModel @Inject constructor(
1312
1300
private val DEFAULT_SELECTED_FOLDER = FolderRole .INBOX
1313
1301
private const val REFRESH_DELAY = 2_000L // We add this delay because `etop` isn't always big enough.
1314
1302
private const val MAX_REFRESH_DELAY = 6_000L
1315
- private const val EML_CONTENT_TYPE = " message/rfc822"
1316
1303
}
1317
1304
}
0 commit comments