diff --git a/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/ui/MessageBody.kt b/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/ui/MessageBody.kt index 8eff110c5d..18f4e034b5 100644 --- a/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/ui/MessageBody.kt +++ b/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/ui/MessageBody.kt @@ -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? ) } diff --git a/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/ui/MessageDetailScreen.kt b/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/ui/MessageDetailScreen.kt index ea5643eddc..25b669530b 100644 --- a/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/ui/MessageDetailScreen.kt +++ b/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/ui/MessageDetailScreen.kt @@ -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? ) } diff --git a/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/usecase/GetEmbeddedImageAvoidDuplicatedExecution.kt b/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/usecase/GetEmbeddedImageAvoidDuplicatedExecution.kt index 5fa1c43a5f..622e41aedc 100644 --- a/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/usecase/GetEmbeddedImageAvoidDuplicatedExecution.kt +++ b/mail-detail/presentation/src/main/kotlin/ch/protonmail/android/maildetail/presentation/usecase/GetEmbeddedImageAvoidDuplicatedExecution.kt @@ -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() }