mirror of
https://github.com/ProtonMail/android-mail.git
synced 2026-06-14 09:54:47 +00:00
Fix crash when navigating back from the details screen before embedded images load
When navigating back coroutines are cancelled and a CancellationException is thrown. This exception needs to be swallowed and doesn't need to be handled in a specific way. MAILANDR-729
This commit is contained in:
+4
-5
@@ -67,7 +67,6 @@ import com.google.accompanist.web.WebView
|
||||
import com.google.accompanist.web.rememberWebViewStateWithHTMLData
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import me.proton.core.compose.component.ProtonSolidButton
|
||||
import me.proton.core.compose.theme.ProtonDimens
|
||||
import me.proton.core.compose.theme.ProtonTheme
|
||||
@@ -128,9 +127,9 @@ internal fun MessageBodyWebView(
|
||||
return if (!messageBodyUiModel.shouldShowRemoteContent && request?.isRemoteContent() == true) {
|
||||
WebResourceResponse("", "", null)
|
||||
} else if (messageBodyUiModel.shouldShowEmbeddedImages && request?.isEmbeddedImage() == true) {
|
||||
runBlocking {
|
||||
actions.loadEmbeddedImage(messageId, "<${request.url.schemeSpecificPart}>")
|
||||
}?.let { WebResourceResponse(it.mimeType, "", ByteArrayInputStream(it.data)) }
|
||||
actions.loadEmbeddedImage(messageId, "<${request.url.schemeSpecificPart}>")?.let {
|
||||
WebResourceResponse(it.mimeType, "", ByteArrayInputStream(it.data))
|
||||
}
|
||||
} else {
|
||||
super.shouldInterceptRequest(view, request)
|
||||
}
|
||||
@@ -264,7 +263,7 @@ object MessageBody {
|
||||
val onMessageBodyLinkClicked: (uri: Uri) -> Unit,
|
||||
val onShowAllAttachments: () -> Unit,
|
||||
val onAttachmentClicked: (attachmentId: AttachmentId) -> Unit,
|
||||
val loadEmbeddedImage: suspend (messageId: MessageId?, contentId: String) -> GetEmbeddedImageResult?
|
||||
val loadEmbeddedImage: (messageId: MessageId?, contentId: String) -> GetEmbeddedImageResult?
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -349,7 +349,7 @@ object MessageDetailScreen {
|
||||
val onAttachmentClicked: (attachmentId: AttachmentId) -> Unit,
|
||||
val openAttachment: (values: OpenAttachmentIntentValues) -> Unit,
|
||||
val showFeatureMissingSnackbar: () -> Unit,
|
||||
val loadEmbeddedImage: suspend (contentId: String) -> GetEmbeddedImageResult?
|
||||
val loadEmbeddedImage: (contentId: String) -> GetEmbeddedImageResult?
|
||||
) {
|
||||
|
||||
companion object {
|
||||
@@ -386,7 +386,7 @@ object MessageDetailContent {
|
||||
val onShowAllAttachmentsClicked: () -> Unit,
|
||||
val onAttachmentClicked: (attachmentId: AttachmentId) -> Unit,
|
||||
val showFeatureMissingSnackbar: () -> Unit,
|
||||
val loadEmbeddedImage: suspend (contentId: String) -> GetEmbeddedImageResult?
|
||||
val loadEmbeddedImage: (contentId: String) -> GetEmbeddedImageResult?
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+11
-9
@@ -39,13 +39,15 @@ class GetEmbeddedImageAvoidDuplicatedExecution @Inject constructor(
|
||||
messageId: MessageId,
|
||||
contentId: String,
|
||||
coroutineContext: CoroutineContext
|
||||
): GetEmbeddedImageResult? = withContext(coroutineContext) {
|
||||
if (loadEmbeddedImageJobMap[contentId]?.isActive == true) {
|
||||
loadEmbeddedImageJobMap[contentId]
|
||||
} else {
|
||||
async { getEmbeddedImage(userId, messageId, contentId).getOrNull() }.apply {
|
||||
loadEmbeddedImageJobMap[contentId] = this
|
||||
}
|
||||
}?.await()
|
||||
}
|
||||
): GetEmbeddedImageResult? = runCatching {
|
||||
withContext(coroutineContext) {
|
||||
if (loadEmbeddedImageJobMap[contentId]?.isActive == true) {
|
||||
loadEmbeddedImageJobMap[contentId]
|
||||
} else {
|
||||
async { getEmbeddedImage(userId, messageId, contentId).getOrNull() }.apply {
|
||||
loadEmbeddedImageJobMap[contentId] = this
|
||||
}
|
||||
}?.await()
|
||||
}
|
||||
}.getOrNull()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user