From 9e754462355b88fee7930bd2e3a43a3df8463ffc Mon Sep 17 00:00:00 2001 From: boris Date: Fri, 13 Dec 2024 11:20:25 +0200 Subject: [PATCH] feat: Add Mentions to draft messages #WPB-12062 (#3687) Co-authored-by: Yamil Medina --- .../state/MessageComposerStateHolder.kt | 26 ++++++++++++------- .../state/MessageCompositionHolder.kt | 9 ++++++- 2 files changed, 25 insertions(+), 10 deletions(-) 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 0ea6534dc7d..02b0152216f 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 9c0b29b89fb..9b5590244c3 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, ) {