Rework and comment the code.
This commit is contained in:
parent
a698c7673c
commit
ac06eebd9e
1 changed files with 23 additions and 14 deletions
|
|
@ -82,22 +82,31 @@ 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) {
|
||||||
val caption = markdownTextEditorState.getMessageMarkdown(permalinkBuilder)
|
is AsyncData.Success -> {
|
||||||
.takeIf { it.isNotEmpty() }
|
// Pre-processing is done, send the attachment
|
||||||
ongoingSendAttachmentJob.value = coroutineScope.launch {
|
val caption = markdownTextEditorState.getMessageMarkdown(permalinkBuilder)
|
||||||
sendPreProcessedMedia(
|
.takeIf { it.isNotEmpty() }
|
||||||
mediaUploadInfo = mediaUploadInfo.data,
|
ongoingSendAttachmentJob.value = coroutineScope.launch {
|
||||||
caption = caption,
|
sendPreProcessedMedia(
|
||||||
sendActionState = sendActionState,
|
mediaUploadInfo = mediaUploadInfo.data,
|
||||||
)
|
caption = caption,
|
||||||
|
sendActionState = sendActionState,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is AsyncData.Failure -> {
|
||||||
|
// Pre-processing has failed, show the error
|
||||||
|
sendActionState.value = SendActionState.Failure(mediaUploadInfo.error)
|
||||||
|
}
|
||||||
|
AsyncData.Uninitialized,
|
||||||
|
is AsyncData.Loading -> {
|
||||||
|
// Pre-processing is still in progress, do nothing
|
||||||
}
|
}
|
||||||
} else if (mediaUploadInfo is AsyncData.Failure) {
|
|
||||||
sendActionState.value = SendActionState.Failure(mediaUploadInfo.error)
|
|
||||||
}
|
}
|
||||||
// else: cannot happen since we filtered with isReady()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleEvents(attachmentsPreviewEvents: AttachmentsPreviewEvents) {
|
fun handleEvents(attachmentsPreviewEvents: AttachmentsPreviewEvents) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue