From 96e1c93f38a056ffcdadc546f2c78ee5078f758b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 30 Jun 2026 11:50:58 +0200 Subject: [PATCH] Introduce derived state editedAttachments --- .../preview/AttachmentsPreviewPresenter.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewPresenter.kt index 5f7939f826..ef85141df1 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/attachments/preview/AttachmentsPreviewPresenter.kt @@ -11,6 +11,7 @@ package io.element.android.features.messages.impl.attachments.preview import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.MutableState +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf @@ -121,6 +122,12 @@ class AttachmentsPreviewPresenter( ) } + val editedAttachments by remember { + derivedStateOf { + attachmentsAndEdits.map { it.attachment }.toImmutableList() + } + } + var preprocessMediaJob by remember { mutableStateOf(null) } val firstMediaAttachment = attachments.first() as Attachment.Media @@ -148,7 +155,7 @@ class AttachmentsPreviewPresenter( preprocessMediaJob?.cancel() preprocessMediaJob = coroutineScope.launch(dispatchers.io) { preProcessAttachments( - attachments = attachmentsAndEdits.map { it.attachment }, + attachments = editedAttachments, mediaOptimizationConfig = config, displayProgress = false, sendActionState = sendActionState, @@ -206,7 +213,7 @@ class AttachmentsPreviewPresenter( ) preprocessMediaJob = coroutineScope.launch(dispatchers.io) { preProcessAttachments( - attachments = attachmentsAndEdits.map { it.attachment }, + attachments = editedAttachments, mediaOptimizationConfig = config, displayProgress = true, sendActionState = sendActionState, @@ -221,7 +228,7 @@ class AttachmentsPreviewPresenter( ) preprocessMediaJob = coroutineScope.launch(dispatchers.io) { preProcessAttachments( - attachments = attachmentsAndEdits.map { it.attachment }, + attachments = editedAttachments, mediaOptimizationConfig = config, displayProgress = true, sendActionState = sendActionState, @@ -273,7 +280,7 @@ class AttachmentsPreviewPresenter( // Dismiss the screen dismiss( - attachments = attachmentsAndEdits.map { it.attachment }, + attachments = editedAttachments, sendActionState = sendActionState, editedTempFiles = editedTempFiles, ) @@ -395,7 +402,7 @@ class AttachmentsPreviewPresenter( } return AttachmentsPreviewState( - attachments = attachmentsAndEdits.map { it.attachment }.toImmutableList(), + attachments = editedAttachments, imageEditorState = imageEditorState, canEditImage = canEditImage, isApplyingImageEdits = isApplyingImageEdits,