- Adds nembed

- Redesigns NIP-19 returns to allow nembeds and give more nuance to the UI.
This commit is contained in:
Vitor Pamplona
2024-02-27 15:39:15 -05:00
parent 87fabd54de
commit f78a252c8f
23 changed files with 710 additions and 517 deletions
@@ -27,12 +27,10 @@ import com.vitorpamplona.amethyst.service.checkNotInMainThread
import com.vitorpamplona.amethyst.service.relays.Relay
import com.vitorpamplona.amethyst.ui.components.BundledInsert
import com.vitorpamplona.quartz.encoders.ATag
import com.vitorpamplona.quartz.encoders.Hex
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.HexValidator
import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.quartz.encoders.decodeEventIdAsHexOrNull
import com.vitorpamplona.quartz.encoders.decodePublicKeyAsHexOrNull
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.events.AddressableEvent
import com.vitorpamplona.quartz.events.AdvertisedRelayListEvent
import com.vitorpamplona.quartz.events.AppDefinitionEvent
@@ -1578,13 +1576,7 @@ object LocalCache {
fun findNotesStartingWith(text: String): List<Note> {
checkNotInMainThread()
val key =
try {
Nip19Bech32.uriToRoute(text)?.hex ?: Hex.decode(text).toHexKey()
} catch (e: Exception) {
if (e is CancellationException) throw e
null
}
val key = decodeEventIdAsHexOrNull(text)
if (key != null) {
val note = getNoteIfExists(key)
@@ -1631,14 +1623,7 @@ object LocalCache {
fun findChannelsStartingWith(text: String): List<Channel> {
checkNotInMainThread()
val key =
try {
Nip19Bech32.uriToRoute(text)?.hex ?: Hex.decode(text).toHexKey()
} catch (e: Exception) {
if (e is CancellationException) throw e
null
}
val key = decodeEventIdAsHexOrNull(text)
if (key != null && channels[key] != null) {
return listOfNotNull(channels[key])
}
@@ -24,9 +24,12 @@ import com.vitorpamplona.amethyst.service.relays.COMMON_FEED_TYPES
import com.vitorpamplona.amethyst.service.relays.FeedType
import com.vitorpamplona.amethyst.service.relays.JsonFilter
import com.vitorpamplona.amethyst.service.relays.TypedFilter
import com.vitorpamplona.quartz.crypto.KeyPair
import com.vitorpamplona.quartz.encoders.ATag
import com.vitorpamplona.quartz.encoders.Hex
import com.vitorpamplona.quartz.encoders.HexValidator
import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.quartz.encoders.bechToBytes
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.events.AudioHeaderEvent
import com.vitorpamplona.quartz.events.AudioTrackEvent
@@ -66,83 +69,118 @@ object NostrSearchEventOrUserDataSource : NostrDataSource("SearchEventFeed") {
null
}
Nip19Bech32.uriToRoute(mySearchString)?.hex ?: isAStraightHex
when (val parsed = Nip19Bech32.uriToRoute(mySearchString)?.entity) {
is Nip19Bech32.NSec -> KeyPair(privKey = parsed.hex.bechToBytes()).pubKey.toHexKey()
is Nip19Bech32.NPub -> parsed.hex
is Nip19Bech32.NProfile -> parsed.hex
is Nip19Bech32.Note -> parsed.hex
is Nip19Bech32.NEvent -> parsed.hex
is Nip19Bech32.NEmbed -> parsed.event.id
is Nip19Bech32.NRelay -> null
is Nip19Bech32.NAddress -> parsed.atag
else -> isAStraightHex
}
} catch (e: Exception) {
if (e is CancellationException) throw e
null
}
// downloads all the reactions to a given event.
return listOfNotNull(
val directReferenceFilters =
hexToWatch?.let {
TypedFilter(
types = COMMON_FEED_TYPES,
filter =
JsonFilter(
ids = listOfNotNull(hexToWatch),
if (it.contains(":")) {
// naddr
listOfNotNull(
ATag.parse(it, null)?.let { aTag ->
TypedFilter(
types = COMMON_FEED_TYPES,
filter =
JsonFilter(
kinds = listOf(MetadataEvent.KIND, aTag.kind),
authors = listOfNotNull(aTag.pubKeyHex),
// just to be sure
limit = 5,
),
)
},
)
} else {
// event ids
listOf(
TypedFilter(
types = COMMON_FEED_TYPES,
filter =
JsonFilter(
ids = listOfNotNull(hexToWatch),
),
),
)
},
hexToWatch?.let {
// authors
TypedFilter(
types = COMMON_FEED_TYPES,
filter =
JsonFilter(
kinds = listOf(MetadataEvent.KIND),
authors = listOfNotNull(hexToWatch),
// just to be sure
limit = 5,
),
),
)
}
} ?: emptyList()
// downloads all the reactions to a given event.
return directReferenceFilters +
listOfNotNull(
TypedFilter(
types = COMMON_FEED_TYPES,
types = setOf(FeedType.SEARCH),
filter =
JsonFilter(
kinds = listOf(MetadataEvent.KIND),
authors = listOfNotNull(hexToWatch),
search = mySearchString,
limit = 100,
),
)
},
TypedFilter(
types = setOf(FeedType.SEARCH),
filter =
JsonFilter(
kinds = listOf(MetadataEvent.KIND),
search = mySearchString,
limit = 100,
),
),
TypedFilter(
types = setOf(FeedType.SEARCH),
filter =
JsonFilter(
kinds =
listOf(
TextNoteEvent.KIND,
LongTextNoteEvent.KIND,
BadgeDefinitionEvent.KIND,
PeopleListEvent.KIND,
BookmarkListEvent.KIND,
AudioHeaderEvent.KIND,
AudioTrackEvent.KIND,
PinListEvent.KIND,
PollNoteEvent.KIND,
ChannelCreateEvent.KIND,
),
search = mySearchString,
limit = 100,
),
),
TypedFilter(
types = setOf(FeedType.SEARCH),
filter =
JsonFilter(
kinds =
listOf(
ChannelMetadataEvent.KIND,
ClassifiedsEvent.KIND,
CommunityDefinitionEvent.KIND,
EmojiPackEvent.KIND,
HighlightEvent.KIND,
LiveActivitiesEvent.KIND,
PollNoteEvent.KIND,
NNSEvent.KIND,
),
search = mySearchString,
limit = 100,
),
),
)
),
TypedFilter(
types = setOf(FeedType.SEARCH),
filter =
JsonFilter(
kinds =
listOf(
TextNoteEvent.KIND,
LongTextNoteEvent.KIND,
BadgeDefinitionEvent.KIND,
PeopleListEvent.KIND,
BookmarkListEvent.KIND,
AudioHeaderEvent.KIND,
AudioTrackEvent.KIND,
PinListEvent.KIND,
PollNoteEvent.KIND,
ChannelCreateEvent.KIND,
),
search = mySearchString,
limit = 100,
),
),
TypedFilter(
types = setOf(FeedType.SEARCH),
filter =
JsonFilter(
kinds =
listOf(
ChannelMetadataEvent.KIND,
ClassifiedsEvent.KIND,
CommunityDefinitionEvent.KIND,
EmojiPackEvent.KIND,
HighlightEvent.KIND,
LiveActivitiesEvent.KIND,
PollNoteEvent.KIND,
NNSEvent.KIND,
),
search = mySearchString,
limit = 100,
),
),
)
}
val searchChannel = requestNewChannel()
@@ -45,6 +45,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.vitorpamplona.amethyst.LocalPreferences
import com.vitorpamplona.amethyst.ServiceManager
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.service.HttpClientManager
import com.vitorpamplona.amethyst.service.lang.LanguageTranslatorService
import com.vitorpamplona.amethyst.service.notifications.PushNotificationUtils
@@ -311,11 +312,12 @@ fun uriToRoute(uri: String?): String? {
if (uri?.startsWith("nostr:Hashtag?id=") == true) {
Route.Hashtag.route.replace("{id}", uri.removePrefix("nostr:Hashtag?id="))
} else {
val nip19 = Nip19Bech32.uriToRoute(uri)
when (nip19?.type) {
Nip19Bech32.Type.USER -> "User/${nip19.hex}"
Nip19Bech32.Type.NOTE -> "Note/${nip19.hex}"
Nip19Bech32.Type.EVENT -> {
val nip19 = Nip19Bech32.uriToRoute(uri)?.entity
when (nip19) {
is Nip19Bech32.NPub -> "User/${nip19.hex}"
is Nip19Bech32.NProfile -> "User/${nip19.hex}"
is Nip19Bech32.Note -> "Note/${nip19.hex}"
is Nip19Bech32.NEvent -> {
if (nip19.kind == PrivateDmEvent.KIND) {
nip19.author?.let { "RoomByAuthor/$it" }
} else if (
@@ -328,14 +330,21 @@ fun uriToRoute(uri: String?): String? {
"Event/${nip19.hex}"
}
}
Nip19Bech32.Type.ADDRESS ->
is Nip19Bech32.NAddress -> {
if (nip19.kind == CommunityDefinitionEvent.KIND) {
"Community/${nip19.hex}"
"Community/${nip19.atag}"
} else if (nip19.kind == LiveActivitiesEvent.KIND) {
"Channel/${nip19.hex}"
"Channel/${nip19.atag}"
} else {
"Event/${nip19.hex}"
"Event/${nip19.atag}"
}
}
is Nip19Bech32.NEmbed -> {
if (LocalCache.getNoteIfExists(nip19.event.id) == null) {
LocalCache.verifyAndConsume(nip19.event, null)
}
"Event/${nip19.event.id}"
}
else -> null
}
}
@@ -68,17 +68,23 @@ class NewMessageTagger(
paragraph.split(' ').forEach { word: String ->
val results = parseDirtyWordForKey(word)
if (results?.key?.type == Nip19Bech32.Type.USER) {
addUserToMentions(dao.getOrCreateUser(results.key.hex))
} else if (results?.key?.type == Nip19Bech32.Type.NOTE) {
addNoteToReplyTos(dao.getOrCreateNote(results.key.hex))
} else if (results?.key?.type == Nip19Bech32.Type.EVENT) {
addNoteToReplyTos(dao.getOrCreateNote(results.key.hex))
} else if (results?.key?.type == Nip19Bech32.Type.ADDRESS) {
val note = dao.checkGetOrCreateAddressableNote(results.key.hex)
if (note != null) {
addNoteToReplyTos(note)
when (val entity = results?.key?.entity) {
is Nip19Bech32.NPub -> addUserToMentions(dao.getOrCreateUser(entity.hex))
is Nip19Bech32.NProfile -> addUserToMentions(dao.getOrCreateUser(entity.hex))
is Nip19Bech32.Note -> addNoteToReplyTos(dao.getOrCreateNote(entity.hex))
is Nip19Bech32.NEvent -> addNoteToReplyTos(dao.getOrCreateNote(entity.hex))
is Nip19Bech32.NEmbed -> addNoteToReplyTos(dao.getOrCreateNote(entity.event.id))
is Nip19Bech32.NAddress -> {
val note = dao.checkGetOrCreateAddressableNote(entity.atag)
if (note != null) {
addNoteToReplyTos(note)
}
}
is Nip19Bech32.NSec -> {}
is Nip19Bech32.NRelay -> {}
}
}
}
@@ -92,27 +98,45 @@ class NewMessageTagger(
.split(' ')
.map { word: String ->
val results = parseDirtyWordForKey(word)
if (results?.key?.type == Nip19Bech32.Type.USER) {
val user = dao.getOrCreateUser(results.key.hex)
when (val entity = results?.key?.entity) {
is Nip19Bech32.NPub -> {
getNostrAddress(dao.getOrCreateUser(entity.hex).pubkeyNpub(), results.restOfWord)
}
is Nip19Bech32.NProfile -> {
getNostrAddress(dao.getOrCreateUser(entity.hex).pubkeyNpub(), results.restOfWord)
}
getNostrAddress(user.pubkeyNpub(), results.restOfWord)
} else if (results?.key?.type == Nip19Bech32.Type.NOTE) {
val note = dao.getOrCreateNote(results.key.hex)
is Nip19Bech32.Note -> {
getNostrAddress(dao.getOrCreateNote(entity.hex).toNEvent(), results.restOfWord)
}
is Nip19Bech32.NEvent -> {
getNostrAddress(dao.getOrCreateNote(entity.hex).toNEvent(), results.restOfWord)
}
getNostrAddress(note.toNEvent(), results.restOfWord)
} else if (results?.key?.type == Nip19Bech32.Type.EVENT) {
val note = dao.getOrCreateNote(results.key.hex)
is Nip19Bech32.NAddress -> {
val note = dao.checkGetOrCreateAddressableNote(entity.atag)
if (note != null) {
getNostrAddress(note.idNote(), results.restOfWord)
} else {
word
}
}
getNostrAddress(note.toNEvent(), results.restOfWord)
} else if (results?.key?.type == Nip19Bech32.Type.ADDRESS) {
val note = dao.checkGetOrCreateAddressableNote(results.key.hex)
if (note != null) {
getNostrAddress(note.idNote(), results.restOfWord)
} else {
is Nip19Bech32.NEmbed -> {
word
}
is Nip19Bech32.NSec -> {
word
}
is Nip19Bech32.NRelay -> {
word
}
else -> {
word
}
} else {
word
}
}
.joinToString(" ")
@@ -135,7 +159,7 @@ class NewMessageTagger(
}
}
@Immutable data class DirtyKeyInfo(val key: Nip19Bech32.Return, val restOfWord: String)
@Immutable data class DirtyKeyInfo(val key: Nip19Bech32.ParseReturn, val restOfWord: String)
fun parseDirtyWordForKey(mightBeAKey: String): DirtyKeyInfo? {
var key = mightBeAKey
@@ -61,9 +61,11 @@ import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.ui.note.LoadChannel
import com.vitorpamplona.amethyst.ui.note.toShortenHex
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.quartz.encoders.Nip30CustomEmoji
import com.vitorpamplona.quartz.events.ChannelCreateEvent
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.ImmutableListOfLists
import com.vitorpamplona.quartz.events.PrivateDmEvent
import com.vitorpamplona.quartz.events.toImmutableListOfLists
@@ -72,45 +74,63 @@ import kotlinx.collections.immutable.ImmutableMap
@Composable
fun ClickableRoute(
nip19: Nip19Bech32.Return,
word: String,
nip19: Nip19Bech32.ParseReturn,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
when (nip19.type) {
Nip19Bech32.Type.USER -> {
DisplayUser(nip19, accountViewModel, nav)
when (val entity = nip19.entity) {
is Nip19Bech32.NPub -> DisplayUser(entity.hex, nip19.additionalChars, accountViewModel, nav)
is Nip19Bech32.NProfile -> DisplayUser(entity.hex, nip19.additionalChars, accountViewModel, nav)
is Nip19Bech32.Note -> DisplayEvent(entity.hex, null, nip19.additionalChars, accountViewModel, nav)
is Nip19Bech32.NEvent -> DisplayEvent(entity.hex, entity.kind, nip19.additionalChars, accountViewModel, nav)
is Nip19Bech32.NEmbed -> LoadAndDisplayEvent(entity.event, nip19.additionalChars, accountViewModel, nav)
is Nip19Bech32.NAddress -> DisplayAddress(entity, nip19.additionalChars, accountViewModel, nav)
is Nip19Bech32.NRelay -> {
Text(word)
}
Nip19Bech32.Type.ADDRESS -> {
DisplayAddress(nip19, accountViewModel, nav)
}
Nip19Bech32.Type.NOTE -> {
DisplayNote(nip19, accountViewModel, nav)
}
Nip19Bech32.Type.EVENT -> {
DisplayEvent(nip19, accountViewModel, nav)
is Nip19Bech32.NSec -> {
Text(word)
}
else -> {
Text(
remember { "@${nip19.hex}${nip19.additionalChars}" },
)
Text(word)
}
}
}
@Composable
private fun DisplayEvent(
nip19: Nip19Bech32.Return,
fun LoadOrCreateNote(
event: Event,
accountViewModel: AccountViewModel,
content: @Composable (Note?) -> Unit,
) {
var note by
remember(event.id) { mutableStateOf<Note?>(accountViewModel.getNoteIfExists(event.id)) }
if (note == null) {
LaunchedEffect(key1 = event.id) {
accountViewModel.checkGetOrCreateNote(event) { note = it }
}
}
content(note)
}
@Composable
private fun LoadAndDisplayEvent(
event: Event,
additionalChars: String,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
LoadNote(nip19.hex, accountViewModel) {
LoadOrCreateNote(event, accountViewModel) {
if (it != null) {
DisplayNoteLink(it, nip19, accountViewModel, nav)
DisplayNoteLink(it, event.id, event.kind, additionalChars, accountViewModel, nav)
} else {
CreateClickableText(
clickablePart = remember(nip19) { "@${nip19.hex.toShortenHex()}" },
suffix = nip19.additionalChars,
route = remember(nip19) { "Event/${nip19.hex}" },
clickablePart = remember(event.id) { "@${event.toNIP19()}" },
suffix = additionalChars,
route = remember(event.id) { "Event/${event.id}" },
nav = nav,
)
}
@@ -118,19 +138,21 @@ private fun DisplayEvent(
}
@Composable
private fun DisplayNote(
nip19: Nip19Bech32.Return,
private fun DisplayEvent(
hex: HexKey,
kind: Int?,
additionalChars: String,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
LoadNote(nip19.hex, accountViewModel = accountViewModel) {
LoadNote(hex, accountViewModel) {
if (it != null) {
DisplayNoteLink(it, nip19, accountViewModel, nav)
DisplayNoteLink(it, hex, kind, additionalChars, accountViewModel, nav)
} else {
CreateClickableText(
clickablePart = remember(nip19) { "@${nip19.hex.toShortenHex()}" },
suffix = nip19.additionalChars,
route = remember(nip19) { "Event/${nip19.hex}" },
clickablePart = remember(hex) { "@${hex.toShortenHex()}" },
suffix = additionalChars,
route = remember(hex) { "Event/$hex" },
nav = nav,
)
}
@@ -140,7 +162,9 @@ private fun DisplayNote(
@Composable
private fun DisplayNoteLink(
it: Note,
nip19: Nip19Bech32.Return,
hex: HexKey,
kind: Int?,
addedCharts: String,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
@@ -150,21 +174,20 @@ private fun DisplayNoteLink(
val channelHex = remember(noteState) { note.channelHex() }
val noteIdDisplayNote = remember(noteState) { "@${note.idDisplayNote()}" }
val addedCharts = nip19.additionalChars
if (note.event is ChannelCreateEvent || nip19.kind == ChannelCreateEvent.KIND) {
if (note.event is ChannelCreateEvent || kind == ChannelCreateEvent.KIND) {
CreateClickableText(
clickablePart = noteIdDisplayNote,
suffix = addedCharts,
route = remember(noteState) { "Channel/${nip19.hex}" },
route = remember(noteState) { "Channel/$hex" },
nav = nav,
)
} else if (note.event is PrivateDmEvent || nip19.kind == PrivateDmEvent.KIND) {
} else if (note.event is PrivateDmEvent || kind == PrivateDmEvent.KIND) {
CreateClickableText(
clickablePart = noteIdDisplayNote,
suffix = addedCharts,
route =
remember(noteState) { (note.author?.pubkeyHex ?: nip19.hex).let { "RoomByAuthor/$it" } },
remember(noteState) { (note.author?.pubkeyHex ?: hex).let { "RoomByAuthor/$it" } },
nav = nav,
)
} else if (channelHex != null) {
@@ -186,7 +209,7 @@ private fun DisplayNoteLink(
CreateClickableText(
clickablePart = noteIdDisplayNote,
suffix = addedCharts,
route = remember(noteState) { "Event/${nip19.hex}" },
route = remember(noteState) { "Event/$hex" },
nav = nav,
)
}
@@ -194,27 +217,28 @@ private fun DisplayNoteLink(
@Composable
private fun DisplayAddress(
nip19: Nip19Bech32.Return,
nip19: Nip19Bech32.NAddress,
additionalChars: String,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
var noteBase by remember(nip19) { mutableStateOf(accountViewModel.getNoteIfExists(nip19.hex)) }
var noteBase by remember(nip19) { mutableStateOf(accountViewModel.getNoteIfExists(nip19.atag)) }
if (noteBase == null) {
LaunchedEffect(key1 = nip19.hex) {
accountViewModel.checkGetOrCreateAddressableNote(nip19.hex) { noteBase = it }
LaunchedEffect(key1 = nip19.atag) {
accountViewModel.checkGetOrCreateAddressableNote(nip19.atag) { noteBase = it }
}
}
noteBase?.let {
val noteState by it.live().metadata.observeAsState()
val route = remember(noteState) { "Note/${nip19.hex}" }
val route = remember(noteState) { "Note/${nip19.atag}" }
val displayName = remember(noteState) { "@${noteState?.note?.idDisplayNote()}" }
CreateClickableText(
clickablePart = displayName,
suffix = nip19.additionalChars,
suffix = additionalChars,
route = route,
nav = nav,
)
@@ -222,35 +246,36 @@ private fun DisplayAddress(
if (noteBase == null) {
Text(
remember { "@${nip19.hex}${nip19.additionalChars}" },
remember { "@${nip19.atag}$additionalChars" },
)
}
}
@Composable
private fun DisplayUser(
nip19: Nip19Bech32.Return,
userHex: HexKey,
additionalChars: String,
accountViewModel: AccountViewModel,
nav: (String) -> Unit,
) {
var userBase by
remember(nip19) {
remember(userHex) {
mutableStateOf(
accountViewModel.getUserIfExists(nip19.hex),
accountViewModel.getUserIfExists(userHex),
)
}
if (userBase == null) {
LaunchedEffect(key1 = nip19.hex) {
accountViewModel.checkGetOrCreateUser(nip19.hex) { userBase = it }
LaunchedEffect(key1 = userHex) {
accountViewModel.checkGetOrCreateUser(userHex) { userBase = it }
}
}
userBase?.let { RenderUserAsClickableText(it, nip19, nav) }
userBase?.let { RenderUserAsClickableText(it, additionalChars, nav) }
if (userBase == null) {
Text(
remember { "@${nip19.hex}${nip19.additionalChars}" },
remember { "@${userHex}$additionalChars" },
)
}
}
@@ -258,7 +283,7 @@ private fun DisplayUser(
@Composable
private fun RenderUserAsClickableText(
baseUser: User,
nip19: Nip19Bech32.Return,
additionalChars: String,
nav: (String) -> Unit,
) {
val userState by baseUser.live().metadata.observeAsState()
@@ -281,7 +306,7 @@ private fun RenderUserAsClickableText(
tags = userTags,
)
nip19.additionalChars.ifBlank { null }?.let {
additionalChars.ifBlank { null }?.let {
Text(text = it, maxLines = 1)
}
}
@@ -25,6 +25,7 @@ import android.util.Patterns
import com.vitorpamplona.amethyst.commons.RichTextParser
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.service.checkNotInMainThread
import com.vitorpamplona.quartz.encoders.ATag
import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.quartz.events.ImmutableListOfLists
import kotlinx.coroutines.CancellationException
@@ -64,58 +65,80 @@ class MarkdownParser {
return null
}
private fun getDisplayNameFromNip19(nip19: Nip19Bech32.Return): Pair<String, String>? {
if (nip19.type == Nip19Bech32.Type.USER) {
LocalCache.getUserIfExists(nip19.hex)?.let {
return Pair(it.toBestDisplayName(), it.pubkeyNpub())
private suspend fun getDisplayNameFromNip19(nip19: Nip19Bech32.Entity): Pair<String, String>? {
return when (nip19) {
is Nip19Bech32.NSec -> null
is Nip19Bech32.NPub -> {
LocalCache.getUserIfExists(nip19.hex)?.let {
return Pair(it.toBestDisplayName(), it.pubkeyNpub())
}
}
} else if (nip19.type == Nip19Bech32.Type.NOTE) {
LocalCache.getNoteIfExists(nip19.hex)?.let {
return Pair(it.idDisplayNote(), it.toNEvent())
is Nip19Bech32.NProfile -> {
LocalCache.getUserIfExists(nip19.hex)?.let {
return Pair(it.toBestDisplayName(), it.pubkeyNpub())
}
}
} else if (nip19.type == Nip19Bech32.Type.ADDRESS) {
LocalCache.getAddressableNoteIfExists(nip19.hex)?.let {
return Pair(it.idDisplayNote(), it.toNEvent())
is Nip19Bech32.Note -> {
LocalCache.getNoteIfExists(nip19.hex)?.let {
return Pair(it.idDisplayNote(), it.toNEvent())
}
}
} else if (nip19.type == Nip19Bech32.Type.EVENT) {
LocalCache.getNoteIfExists(nip19.hex)?.let {
return Pair(it.idDisplayNote(), it.toNEvent())
is Nip19Bech32.NEvent -> {
LocalCache.getNoteIfExists(nip19.hex)?.let {
return Pair(it.idDisplayNote(), it.toNEvent())
}
}
}
is Nip19Bech32.NEmbed -> {
if (LocalCache.getNoteIfExists(nip19.event.id) == null) {
LocalCache.verifyAndConsume(nip19.event, null)
}
return null
LocalCache.getNoteIfExists(nip19.event.id)?.let {
return Pair(it.idDisplayNote(), it.toNEvent())
}
}
is Nip19Bech32.NRelay -> null
is Nip19Bech32.NAddress -> {
LocalCache.getAddressableNoteIfExists(nip19.atag)?.let {
return Pair(it.idDisplayNote(), it.toNEvent())
}
}
else -> null
}
}
fun returnNIP19References(
content: String,
tags: ImmutableListOfLists<String>?,
): List<Nip19Bech32.Return> {
): List<Nip19Bech32.Entity> {
checkNotInMainThread()
val listOfReferences = mutableListOf<Nip19Bech32.Return>()
val listOfReferences = mutableListOf<Nip19Bech32.Entity>()
content.split('\n').forEach { paragraph ->
paragraph.split(' ').forEach { word: String ->
if (RichTextParser.startsWithNIP19Scheme(word)) {
val parsedNip19 = Nip19Bech32.uriToRoute(word)
parsedNip19?.let { listOfReferences.add(it) }
parsedNip19?.let { listOfReferences.add(it.entity) }
}
}
}
tags?.lists?.forEach {
if (it[0] == "p" && it.size > 1) {
listOfReferences.add(Nip19Bech32.Return(Nip19Bech32.Type.USER, it[1], null, null, null, ""))
listOfReferences.add(Nip19Bech32.NProfile(it[1], listOfNotNull(it.getOrNull(2))))
} else if (it[0] == "e" && it.size > 1) {
listOfReferences.add(Nip19Bech32.Return(Nip19Bech32.Type.NOTE, it[1], null, null, null, ""))
listOfReferences.add(Nip19Bech32.NEvent(it[1], listOfNotNull(it.getOrNull(2)), null, null))
} else if (it[0] == "a" && it.size > 1) {
listOfReferences.add(Nip19Bech32.Return(Nip19Bech32.Type.ADDRESS, it[1], null, null, null, ""))
ATag.parseAtag(it[1], it.getOrNull(2))?.let { atag ->
listOfReferences.add(Nip19Bech32.NAddress(it[1], listOfNotNull(atag.relay), atag.pubKeyHex, atag.kind))
}
}
}
return listOfReferences
}
fun returnMarkdownWithSpecialContent(
suspend fun returnMarkdownWithSpecialContent(
content: String,
tags: ImmutableListOfLists<String>?,
): String {
@@ -135,8 +158,8 @@ class MarkdownParser {
} else if (RichTextParser.startsWithNIP19Scheme(word)) {
val parsedNip19 = Nip19Bech32.uriToRoute(word)
returnContent +=
if (parsedNip19 !== null) {
val pair = getDisplayNameFromNip19(parsedNip19)
if (parsedNip19?.entity !== null) {
val pair = getDisplayNameFromNip19(parsedNip19.entity)
if (pair != null) {
val (displayName, nip19) = pair
"[$displayName](nostr:$nip19) "
@@ -106,6 +106,7 @@ import com.vitorpamplona.amethyst.ui.theme.innerPostModifier
import com.vitorpamplona.amethyst.ui.theme.markdownStyle
import com.vitorpamplona.amethyst.ui.uriToRoute
import com.vitorpamplona.quartz.crypto.KeyPair
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.quartz.events.EmptyTagList
import com.vitorpamplona.quartz.events.ImmutableListOfLists
@@ -507,9 +508,7 @@ private fun RefreshableContent(
var markdownWithSpecialContent by remember(content) { mutableStateOf<String?>(content) }
ObserverAllNIP19References(content, tags, accountViewModel) {
accountViewModel.returnMarkdownWithSpecialContent(content, tags) {
newMarkdownWithSpecialContent,
->
accountViewModel.returnMarkdownWithSpecialContent(content, tags) { newMarkdownWithSpecialContent ->
if (markdownWithSpecialContent != newMarkdownWithSpecialContent) {
markdownWithSpecialContent = newMarkdownWithSpecialContent
}
@@ -526,7 +525,7 @@ fun ObserverAllNIP19References(
accountViewModel: AccountViewModel,
onRefresh: () -> Unit,
) {
var nip19References by remember(content) { mutableStateOf<List<Nip19Bech32.Return>>(emptyList()) }
var nip19References by remember(content) { mutableStateOf<List<Nip19Bech32.Entity>>(emptyList()) }
LaunchedEffect(key1 = content) {
accountViewModel.returnNIP19References(content, tags) {
@@ -540,33 +539,37 @@ fun ObserverAllNIP19References(
@Composable
fun ObserveNIP19(
it: Nip19Bech32.Return,
entity: Nip19Bech32.Entity,
accountViewModel: AccountViewModel,
onRefresh: () -> Unit,
) {
if (it.type == Nip19Bech32.Type.NOTE || it.type == Nip19Bech32.Type.EVENT || it.type == Nip19Bech32.Type.ADDRESS) {
ObserveNIP19Event(it, accountViewModel, onRefresh)
} else if (it.type == Nip19Bech32.Type.USER) {
ObserveNIP19User(it, accountViewModel, onRefresh)
when (val parsed = entity) {
is Nip19Bech32.NPub -> ObserveNIP19User(parsed.hex, accountViewModel, onRefresh)
is Nip19Bech32.NProfile -> ObserveNIP19User(parsed.hex, accountViewModel, onRefresh)
is Nip19Bech32.Note -> ObserveNIP19Event(parsed.hex, accountViewModel, onRefresh)
is Nip19Bech32.NEvent -> ObserveNIP19Event(parsed.hex, accountViewModel, onRefresh)
is Nip19Bech32.NEmbed -> ObserveNIP19Event(parsed.event.id, accountViewModel, onRefresh)
is Nip19Bech32.NAddress -> ObserveNIP19Event(parsed.atag, accountViewModel, onRefresh)
is Nip19Bech32.NSec -> {}
is Nip19Bech32.NRelay -> {}
}
}
@Composable
private fun ObserveNIP19Event(
it: Nip19Bech32.Return,
hex: HexKey,
accountViewModel: AccountViewModel,
onRefresh: () -> Unit,
) {
var baseNote by remember(it) { mutableStateOf<Note?>(accountViewModel.getNoteIfExists(it.hex)) }
var baseNote by remember(hex) { mutableStateOf<Note?>(accountViewModel.getNoteIfExists(hex)) }
if (baseNote == null) {
LaunchedEffect(key1 = it.hex) {
if (
it.type == Nip19Bech32.Type.NOTE || it.type == Nip19Bech32.Type.EVENT || it.type == Nip19Bech32.Type.ADDRESS
) {
accountViewModel.checkGetOrCreateNote(it.hex) { note ->
launch(Dispatchers.Main) { baseNote = note }
}
LaunchedEffect(key1 = hex) {
accountViewModel.checkGetOrCreateNote(hex) { note ->
launch(Dispatchers.Main) { baseNote = note }
}
}
}
@@ -590,18 +593,16 @@ fun ObserveNote(
@Composable
private fun ObserveNIP19User(
it: Nip19Bech32.Return,
hex: HexKey,
accountViewModel: AccountViewModel,
onRefresh: () -> Unit,
) {
var baseUser by remember(it) { mutableStateOf<User?>(accountViewModel.getUserIfExists(it.hex)) }
var baseUser by remember(hex) { mutableStateOf<User?>(accountViewModel.getUserIfExists(hex)) }
if (baseUser == null) {
LaunchedEffect(key1 = it.hex) {
if (it.type == Nip19Bech32.Type.USER) {
accountViewModel.checkGetOrCreateUser(it.hex)?.let { user ->
launch(Dispatchers.Main) { baseUser = user }
}
LaunchedEffect(key1 = hex) {
accountViewModel.checkGetOrCreateUser(hex)?.let { user ->
launch(Dispatchers.Main) { baseUser = user }
}
}
}
@@ -634,7 +635,9 @@ fun BechLink(
var loadedLink by remember { mutableStateOf<LoadedBechLink?>(null) }
if (loadedLink == null) {
LaunchedEffect(key1 = word) { accountViewModel.parseNIP19(word) { loadedLink = it } }
LaunchedEffect(key1 = word) {
accountViewModel.parseNIP19(word) { loadedLink = it }
}
}
if (canPreview && loadedLink?.baseNote != null) {
@@ -648,7 +651,7 @@ fun BechLink(
)
}
} else if (loadedLink?.nip19 != null) {
ClickableRoute(loadedLink?.nip19!!, accountViewModel, nav)
ClickableRoute(word, loadedLink?.nip19!!, accountViewModel, nav)
} else {
val text =
remember(word) {
@@ -77,10 +77,8 @@ import com.vitorpamplona.amethyst.ui.screen.loggedOff.LoginOrSignupScreen
import com.vitorpamplona.amethyst.ui.theme.AccountPictureModifier
import com.vitorpamplona.amethyst.ui.theme.Size10dp
import com.vitorpamplona.amethyst.ui.theme.Size55dp
import com.vitorpamplona.quartz.encoders.decodePublicKey
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.encoders.decodePublicKeyAsHexOrNull
import com.vitorpamplona.quartz.events.toImmutableListOfLists
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -149,12 +147,9 @@ fun DisplayAccount(
) {
var baseUser by remember {
mutableStateOf<User?>(
LocalCache.getUserIfExists(
decodePublicKey(
acc.npub,
)
.toHexKey(),
),
decodePublicKeyAsHexOrNull(acc.npub)?.let {
LocalCache.getUserIfExists(it)
},
)
}
@@ -162,13 +157,8 @@ fun DisplayAccount(
LaunchedEffect(key1 = acc.npub) {
launch(Dispatchers.IO) {
baseUser =
try {
LocalCache.getOrCreateUser(
decodePublicKey(acc.npub).toHexKey(),
)
} catch (e: Exception) {
if (e is CancellationException) throw e
null
decodePublicKeyAsHexOrNull(acc.npub)?.let {
LocalCache.getOrCreateUser(it)
}
}
}
@@ -99,6 +99,7 @@ import com.vitorpamplona.amethyst.ui.theme.DividerThickness
import com.vitorpamplona.amethyst.ui.theme.Font14SP
import com.vitorpamplona.amethyst.ui.theme.placeholderText
import com.vitorpamplona.quartz.encoders.Nip47WalletConnect
import com.vitorpamplona.quartz.encoders.decodePrivateKeyAsHexOrNull
import com.vitorpamplona.quartz.encoders.decodePublicKey
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.events.LnZapEvent
@@ -165,14 +166,7 @@ class UpdateZapAmountViewModel(val account: Account) : ViewModel() {
addedWSS
}
val unverifiedPrivKey = walletConnectSecret.text.ifBlank { null }
val privKeyHex =
try {
unverifiedPrivKey?.let { decodePublicKey(it).toHexKey() }
} catch (e: Exception) {
if (e is CancellationException) throw e
null
}
val privKeyHex = walletConnectSecret.text.ifBlank { null }?.let { decodePrivateKeyAsHexOrNull(it) }
if (pubkeyHex != null) {
account?.changeZapPaymentRequest(
@@ -29,28 +29,14 @@ import com.google.zxing.client.android.Intents
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.amethyst.ui.uriToRoute
import kotlinx.coroutines.CancellationException
@Composable
fun NIP19QrCodeScanner(onScan: (String?) -> Unit) {
SimpleQrCodeScanner {
try {
val nip19 = Nip19Bech32.uriToRoute(it)
val startingPage =
when (nip19?.type) {
Nip19Bech32.Type.USER -> "User/${nip19.hex}"
Nip19Bech32.Type.NOTE -> "Note/${nip19.hex}"
Nip19Bech32.Type.EVENT -> "Event/${nip19.hex}"
Nip19Bech32.Type.ADDRESS -> "Note/${nip19.hex}"
else -> null
}
if (startingPage != null) {
onScan(startingPage)
} else {
onScan(null)
}
onScan(uriToRoute(it))
} catch (e: Throwable) {
if (e is CancellationException) throw e
Log.e("NIP19 Scanner", "Error parsing $it", e)
@@ -85,8 +85,20 @@ class AccountStateViewModel() : ViewModel() {
loginWithExternalSigner: Boolean = false,
packageName: String = "",
) = withContext(Dispatchers.IO) {
val parsed = Nip19Bech32.uriToRoute(key)
val pubKeyParsed = parsed?.hex?.hexToByteArray()
val parsed = Nip19Bech32.uriToRoute(key)?.entity
val pubKeyParsed =
when (parsed) {
is Nip19Bech32.NSec -> null
is Nip19Bech32.NPub -> parsed.hex.hexToByteArray()
is Nip19Bech32.NProfile -> parsed.hex.hexToByteArray()
is Nip19Bech32.Note -> null
is Nip19Bech32.NEvent -> null
is Nip19Bech32.NEmbed -> null
is Nip19Bech32.NRelay -> null
is Nip19Bech32.NAddress -> null
else -> null
}
val proxy = HttpClientManager.initProxy(useProxy, "127.0.0.1", proxyPort)
if (loginWithExternalSigner && pubKeyParsed == null) {
@@ -868,6 +868,22 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
viewModelScope.launch(Dispatchers.IO) { onResult(checkGetOrCreateNote(key)) }
}
fun checkGetOrCreateNote(
event: Event,
onResult: (Note?) -> Unit,
) {
viewModelScope.launch(Dispatchers.IO) {
var note = checkGetOrCreateNote(event.id)
if (note == null) {
LocalCache.verifyAndConsume(event, null)
note = checkGetOrCreateNote(event.id)
}
onResult(note)
}
}
fun getNoteIfExists(hex: HexKey): Note? {
return LocalCache.getNoteIfExists(hex)
}
@@ -970,7 +986,7 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
fun returnNIP19References(
content: String,
tags: ImmutableListOfLists<String>?,
onNewReferences: (List<Nip19Bech32.Return>) -> Unit,
onNewReferences: (List<Nip19Bech32.Entity>) -> Unit,
) {
viewModelScope.launch(Dispatchers.IO) {
onNewReferences(MarkdownParser().returnNIP19References(content, tags))
@@ -987,17 +1003,32 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
}
}
fun parseNIP19(
suspend fun parseNIP19(
str: String,
onNote: (LoadedBechLink) -> Unit,
) {
viewModelScope.launch(Dispatchers.IO) {
withContext(Dispatchers.IO) {
Nip19Bech32.uriToRoute(str)?.let {
var returningNote: Note? = null
if (
it.type == Nip19Bech32.Type.NOTE || it.type == Nip19Bech32.Type.EVENT || it.type == Nip19Bech32.Type.ADDRESS
) {
LocalCache.checkGetOrCreateNote(it.hex)?.let { note -> returningNote = note }
when (val parsed = it.entity) {
is Nip19Bech32.NSec -> {}
is Nip19Bech32.NPub -> {}
is Nip19Bech32.NProfile -> {}
is Nip19Bech32.Note -> LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note }
is Nip19Bech32.NEvent -> LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note }
is Nip19Bech32.NEmbed -> {
if (LocalCache.getNoteIfExists(parsed.event.id) == null) {
LocalCache.verifyAndConsume(parsed.event, null)
}
LocalCache.checkGetOrCreateNote(parsed.event.id)?.let { note ->
returningNote = note
}
}
is Nip19Bech32.NRelay -> {}
is Nip19Bech32.NAddress -> LocalCache.checkGetOrCreateNote(parsed.atag)?.let { note -> returningNote = note }
else -> {}
}
onNote(LoadedBechLink(returningNote, it))
@@ -1298,7 +1329,7 @@ class HasNotificationDot(bottomNavigationItems: ImmutableList<Route>) {
}
}
@Immutable data class LoadedBechLink(val baseNote: Note?, val nip19: Nip19Bech32.Return)
@Immutable data class LoadedBechLink(val baseNote: Note?, val nip19: Nip19Bech32.ParseReturn)
public fun <T, K> allOrNothingSigningOperations(
remainingTos: List<T>,
@@ -26,6 +26,7 @@ import com.vitorpamplona.amethyst.ui.actions.Dao
import com.vitorpamplona.amethyst.ui.actions.NewMessageTagger
import com.vitorpamplona.quartz.encoders.Nip19Bech32
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
/**
@@ -54,10 +55,10 @@ class NewMessageTaggerKeyParseTest {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn")
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.Note)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.Note)?.hex,
)
assertEquals("", result?.restOfWord)
}
@@ -67,10 +68,10 @@ class NewMessageTaggerKeyParseTest {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z")
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.NPub)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.NPub)?.hex,
)
assertEquals("", result?.restOfWord)
}
@@ -80,10 +81,10 @@ class NewMessageTaggerKeyParseTest {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.Note)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.Note)?.hex,
)
assertEquals(",", result?.restOfWord)
}
@@ -93,10 +94,10 @@ class NewMessageTaggerKeyParseTest {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.NPub)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.NPub)?.hex,
)
assertEquals(",", result?.restOfWord)
}
@@ -106,10 +107,10 @@ class NewMessageTaggerKeyParseTest {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("@note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,")
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.Note)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.Note)?.hex,
)
assertEquals(",", result?.restOfWord)
}
@@ -119,10 +120,10 @@ class NewMessageTaggerKeyParseTest {
val result =
NewMessageTagger(message = "", dao = dao)
.parseDirtyWordForKey("@npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,")
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.NPub)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.NPub)?.hex,
)
assertEquals(",", result?.restOfWord)
}
@@ -134,10 +135,10 @@ class NewMessageTaggerKeyParseTest {
.parseDirtyWordForKey(
"nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,",
)
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.Note)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.Note)?.hex,
)
assertEquals(",", result?.restOfWord)
}
@@ -149,10 +150,10 @@ class NewMessageTaggerKeyParseTest {
.parseDirtyWordForKey(
"nostr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,",
)
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.NPub)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.NPub)?.hex,
)
assertEquals(",", result?.restOfWord)
}
@@ -164,10 +165,10 @@ class NewMessageTaggerKeyParseTest {
.parseDirtyWordForKey(
"Nostr:note1z5e2m0smx6d7e2d0zaq8d3rnd7httm6j0uf8tf90yqqjrs842czshwtkmn,",
)
assertEquals(Nip19Bech32.Type.NOTE, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.Note)
assertEquals(
"1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.Note)?.hex,
)
assertEquals(",", result?.restOfWord)
}
@@ -179,10 +180,10 @@ class NewMessageTaggerKeyParseTest {
.parseDirtyWordForKey(
"nOstr:npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z,",
)
assertEquals(Nip19Bech32.Type.USER, result?.key?.type)
assertTrue(result?.key?.entity is Nip19Bech32.NPub)
assertEquals(
"460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c",
result?.key?.hex,
(result?.key?.entity as? Nip19Bech32.NPub)?.hex,
)
assertEquals(",", result?.restOfWord)
}