Merge branch 'vitorpamplona:main' into profiles-list-management

This commit is contained in:
KotlinGeekDev
2025-08-07 19:52:15 +00:00
committed by GitHub
28 changed files with 495 additions and 73 deletions
@@ -28,6 +28,7 @@ import com.vitorpamplona.quartz.nip01Core.core.any
import com.vitorpamplona.quartz.nip01Core.hints.PubKeyHintProvider
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip10Notes.BaseNoteEvent
import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile
import com.vitorpamplona.quartz.nip19Bech32.pubKeyHints
import com.vitorpamplona.quartz.nip19Bech32.pubKeys
import com.vitorpamplona.quartz.nip31Alts.alt
@@ -59,6 +60,19 @@ class PublicMessageEvent(
fun groupKeySet() = tags.mapNotNullTo(mutableSetOf(this.pubKey), ReceiverTag::parseKey)
fun groupKeySetWithoutOwner() = tags.mapNotNullTo(mutableSetOf(), ReceiverTag::parseKey) - this.pubKey
fun groupAsNProfileList() =
tags
.mapNotNull(ReceiverTag::parse)
.joinToString {
"nostr:" + NProfile.create(it.pubKey, it.relayHint)
}
fun chatroomKey(user: HexKey) = groupKeySet() - user
fun peopleAndContent() = groupAsNProfileList() + " " + content
companion object {
const val KIND = 24
const val ALT_DESCRIPTION = "Public Message"
@@ -51,6 +51,19 @@ data class NProfile(
return NProfile(hex, relay.mapNotNull { RelayUrlNormalizer.normalizeOrNull(it) })
}
fun create(
authorPubKeyHex: String,
relay: NormalizedRelayUrl?,
): String =
TlvBuilder()
.apply {
addHex(TlvTypes.SPECIAL, authorPubKeyHex)
if (relay != null) {
addStringIfNotNull(TlvTypes.RELAY, relay.url)
}
}.build()
.toNProfile()
fun create(
authorPubKeyHex: String,
relays: List<NormalizedRelayUrl>,