Rework and comment the code.

This commit is contained in:
Benoit Marty 2024-11-26 16:08:19 +01:00
parent a698c7673c
commit ac06eebd9e

View file

@ -82,9 +82,11 @@ class AttachmentsPreviewPresenter @AssistedInject constructor(
} }
LaunchedEffect(userSentAttachment.value, mediaUploadInfoState.value) { LaunchedEffect(userSentAttachment.value, mediaUploadInfoState.value) {
val mediaUploadInfo = mediaUploadInfoState.value if (userSentAttachment.value) {
if (userSentAttachment.value && mediaUploadInfo.isReady()) // User confirmed sending the attachment
if (mediaUploadInfo is AsyncData.Success) { when (val mediaUploadInfo = mediaUploadInfoState.value) {
is AsyncData.Success -> {
// Pre-processing is done, send the attachment
val caption = markdownTextEditorState.getMessageMarkdown(permalinkBuilder) val caption = markdownTextEditorState.getMessageMarkdown(permalinkBuilder)
.takeIf { it.isNotEmpty() } .takeIf { it.isNotEmpty() }
ongoingSendAttachmentJob.value = coroutineScope.launch { ongoingSendAttachmentJob.value = coroutineScope.launch {
@ -94,10 +96,17 @@ class AttachmentsPreviewPresenter @AssistedInject constructor(
sendActionState = sendActionState, sendActionState = sendActionState,
) )
} }
} else if (mediaUploadInfo is AsyncData.Failure) { }
is AsyncData.Failure -> {
// Pre-processing has failed, show the error
sendActionState.value = SendActionState.Failure(mediaUploadInfo.error) sendActionState.value = SendActionState.Failure(mediaUploadInfo.error)
} }
// else: cannot happen since we filtered with isReady() AsyncData.Uninitialized,
is AsyncData.Loading -> {
// Pre-processing is still in progress, do nothing
}
}
}
} }
fun handleEvents(attachmentsPreviewEvents: AttachmentsPreviewEvents) { fun handleEvents(attachmentsPreviewEvents: AttachmentsPreviewEvents) {