diff --git a/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/state/MessageComposerStateHolder.kt b/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/state/MessageComposerStateHolder.kt index 0ea6534dc7..02b0152216 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/state/MessageComposerStateHolder.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/state/MessageComposerStateHolder.kt @@ -55,15 +55,6 @@ fun rememberMessageComposerStateHolder( val messageTextFieldValue = remember { mutableStateOf(TextFieldValue()) } - LaunchedEffect(draftMessageComposition.draftText) { - if (draftMessageComposition.draftText.isNotBlank()) { - messageTextFieldValue.value = messageTextFieldValue.value.copy( - text = draftMessageComposition.draftText, - selection = TextRange(draftMessageComposition.draftText.length) // Place cursor at the end of the new text - ) - } - } - val messageCompositionHolder = remember { mutableStateOf( MessageCompositionHolder( @@ -77,6 +68,23 @@ fun rememberMessageComposerStateHolder( ) ) } + + LaunchedEffect(draftMessageComposition.draftText) { + if (draftMessageComposition.draftText.isNotBlank()) { + messageTextFieldValue.value = messageTextFieldValue.value.copy( + text = draftMessageComposition.draftText, + selection = TextRange(draftMessageComposition.draftText.length) // Place cursor at the end of the new text + ) + } + + if (draftMessageComposition.selectedMentions.isNotEmpty()) { + messageCompositionHolder.value.setMentions( + draftMessageComposition.draftText, + draftMessageComposition.selectedMentions.map { it.intoMessageMention() } + ) + } + } + LaunchedEffect(Unit) { messageCompositionHolder.value.handleMessageTextUpdates() } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/state/MessageCompositionHolder.kt b/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/state/MessageCompositionHolder.kt index 9c0b29b89f..9b5590244c 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/state/MessageCompositionHolder.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/state/MessageCompositionHolder.kt @@ -241,13 +241,20 @@ class MessageCompositionHolder( ) messageComposition.update { it.copy( - selectedMentions = mentions.mapNotNull { it.toUiMention(editMessageText) }, + selectedMentions = mentions.mapNotNull { mention -> mention.toUiMention(editMessageText) }, editMessageId = messageId ) } onSaveDraft(messageComposition.value.toDraft(editMessageText)) } + fun setMentions(editMessageText: String, mentions: List) { + messageComposition.update { + it.copy(selectedMentions = mentions.mapNotNull { mention -> mention.toUiMention(editMessageText) }) + } + onSaveDraft(messageComposition.value.toDraft(editMessageText)) + } + fun addOrRemoveMessageMarkdown( markdown: RichTextMarkdown, ) {