diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt index 1549a728..54991828 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/content/RichContent.kt @@ -1,10 +1,12 @@ package ac.cord.auxiliary.compose.ui.composable.widgets.content import ac.cord.auxiliary.compose.database.model.NostrEvent +import ac.cord.auxiliary.compose.database.model.Profile import ac.cord.auxiliary.compose.database.model.intermdiate.LocalMention import ac.cord.auxiliary.compose.database.model.intermdiate.LocalNostrEvent import ac.cord.auxiliary.compose.database.model.intermdiate.LocalQuotedNostrEvent import ac.cord.auxiliary.compose.ui.composable.widgets.content.Constants.INLINE_CONTENT_TAG +import ac.cord.auxiliary.compose.ui.composable.widgets.profile.ProfileColor import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.text.InlineTextContent @@ -195,12 +197,13 @@ fun RichContent( Logger.withTag("RichContent").d("NostrProfileSegment: $seg") val pubkey = seg.pubkey val displayName = profileNames[seg.pubkey] ?: seg.pubkey.take(8) + withLink( LinkAnnotation.Clickable("profile") { onProfileClick?.invoke(pubkey) } ) { - withStyle(SpanStyle(color = effectiveLinkColor, textDecoration = linkDecoration)) { + withStyle(SpanStyle(color = ProfileColor.fromPublicKey(seg.pubkey), textDecoration = linkDecoration)) { append("@${displayName.trimEnd()}") } } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileAvatar.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileAvatar.kt index 1c643843..d66ec970 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileAvatar.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileAvatar.kt @@ -49,12 +49,8 @@ fun ProfileAvatar( ) { val modifier = Modifier.size(size).clip(shape = shape) - val tintColor = Color.hsl( - hue = abs( - publicKey.hashCode() - ).mod(360).toFloat(), - saturation = 0.55f, - lightness = 0.45f + val tintColor = ProfileColor.fromPublicKey( + publicKey ) if (profile?.picture == null) { diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileColor.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileColor.kt new file mode 100644 index 00000000..869de8ac --- /dev/null +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/profile/ProfileColor.kt @@ -0,0 +1,24 @@ +package ac.cord.auxiliary.compose.ui.composable.widgets.profile + +import ac.cord.auxiliary.compose.database.model.Profile +import androidx.compose.ui.graphics.Color +import com.vitorpamplona.quartz.nip01Core.core.HexKey +import kotlin.math.abs + +object ProfileColor { + fun fromPublicKey(publicKey: HexKey): Color { + return Color.hsl( + hue = abs( + publicKey.hashCode() + ).mod(360).toFloat(), + saturation = 0.55f, + lightness = 0.45f + ) + } + + fun fromProfile(profile: Profile): Color { + return fromPublicKey( + profile.publicKey + ) + } +} \ No newline at end of file