Make the profile mention match the profile color hashcode

This commit is contained in:
Kgothatso Ngako
2026-05-02 10:22:10 +02:00
parent a116e2de2c
commit f615724c9f
3 changed files with 30 additions and 7 deletions

View File

@@ -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()}")
}
}

View File

@@ -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) {

View File

@@ -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
)
}
}