From 7ba7bbdfa744c2cae4fc0f321619178a239c206b Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sat, 2 May 2026 20:46:36 +0200 Subject: [PATCH] Make the profile usage a lot easier. --- .../ui/composable/WriteNewNoteScreen.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/WriteNewNoteScreen.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/WriteNewNoteScreen.kt index 141cc2fd..36d74b09 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/WriteNewNoteScreen.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/WriteNewNoteScreen.kt @@ -11,6 +11,7 @@ import ac.cord.auxiliary.compose.ui.composable.widgets.LoadingDataIndicator import ac.cord.auxiliary.compose.ui.composable.widgets.content.ContentParser import ac.cord.auxiliary.compose.ui.composable.widgets.content.ContentSegment import ac.cord.auxiliary.compose.ui.composable.widgets.profile.ProfileAvatar +import ac.cord.auxiliary.compose.ui.composable.widgets.profile.ProfileColor import ac.cord.auxiliary.compose.ui.theme.AuxTheme import ac.cord.auxiliary.compose.ui.view.model.WriteNewNoteViewModel import ac.cord.auxiliary.compose.ui.view.state.WriteNewNoteUIState @@ -43,6 +44,7 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.key import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview @@ -123,7 +125,7 @@ fun WriteNewNoteScreen( ) } - val mentionedProfiles: List = emptyList() + val mentionedProfiles: List = emptyList() TextField( modifier = Modifier.fillMaxWidth(), @@ -174,13 +176,21 @@ fun WriteNewNoteScreen( if (mentionedProfiles.isNotEmpty()) { for (nostrProfile in nostrProfiles) { - mentionedProfiles.find { mentionedProfile -> mentionedProfile.profile?.publicKey == nostrProfile.pubkey }?.let { mentionedProfile -> - val profileMention = mentionedProfile.profile?.humanReadableNameOrPubkey() ?: "${nostrProfile.pubkey.take(8)}...${nostrProfile.pubkey.takeLast(4)}" + mentionedProfiles.find { mentionedProfile -> mentionedProfile.publicKey == nostrProfile.pubkey }?.let { mentionedProfile -> + val profileMention = "@${mentionedProfile.humanReadableNameOrPubkey()}" replace( start = nostrProfile.startIndex, end = nostrProfile.endIndex, - text = "@$profileMention" + text = profileMention + ) + + addStyle( + SpanStyle( + color = ProfileColor.fromPublicKey(mentionedProfile.publicKey) + ), + nostrProfile.startIndex, + profileMention.length ) } }