diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewMessageTagger.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewMessageTagger.kt index f7a3b5366..8cbeb910a 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewMessageTagger.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewMessageTagger.kt @@ -146,9 +146,9 @@ class NewMessageTagger( fun getNostrAddress( bechAddress: String, - restOfTheWord: String, + restOfTheWord: String?, ): String { - return if (restOfTheWord.isEmpty()) { + return if (restOfTheWord.isNullOrEmpty()) { "nostr:$bechAddress" } else { if (Bech32.ALPHABET.contains(restOfTheWord.get(0), true)) { @@ -159,7 +159,7 @@ class NewMessageTagger( } } - @Immutable data class DirtyKeyInfo(val key: Nip19Bech32.ParseReturn, val restOfWord: String) + @Immutable data class DirtyKeyInfo(val key: Nip19Bech32.ParseReturn, val restOfWord: String?) fun parseDirtyWordForKey(mightBeAKey: String): DirtyKeyInfo? { var key = mightBeAKey @@ -181,7 +181,7 @@ class NewMessageTagger( val pubkey = Nip19Bech32.uriToRoute(KeyPair(privKey = keyB32.bechToBytes()).pubKey.toNpub()) ?: return null - return DirtyKeyInfo(pubkey, restOfWord) + return DirtyKeyInfo(pubkey, restOfWord.ifEmpty { null }) } else if (key.startsWith("npub1", true)) { if (key.length < 63) { return null @@ -192,7 +192,7 @@ class NewMessageTagger( val pubkey = Nip19Bech32.uriToRoute(keyB32) ?: return null - return DirtyKeyInfo(pubkey, restOfWord) + return DirtyKeyInfo(pubkey, restOfWord.ifEmpty { null }) } else if (key.startsWith("note1", true)) { if (key.length < 63) { return null @@ -203,7 +203,7 @@ class NewMessageTagger( val noteId = Nip19Bech32.uriToRoute(keyB32) ?: return null - return DirtyKeyInfo(noteId, restOfWord) + return DirtyKeyInfo(noteId, restOfWord.ifEmpty { null }) } else if (key.startsWith("nprofile", true)) { val pubkeyRelay = Nip19Bech32.uriToRoute(key) ?: return null diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ClickableRoute.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ClickableRoute.kt index 466dafdb1..46f38d062 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ClickableRoute.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ClickableRoute.kt @@ -119,7 +119,7 @@ fun LoadOrCreateNote( @Composable private fun LoadAndDisplayEvent( event: Event, - additionalChars: String, + additionalChars: String?, accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { @@ -141,7 +141,7 @@ private fun LoadAndDisplayEvent( private fun DisplayEvent( hex: HexKey, kind: Int?, - additionalChars: String, + additionalChars: String?, accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { @@ -164,7 +164,7 @@ private fun DisplayNoteLink( it: Note, hex: HexKey, kind: Int?, - addedCharts: String, + addedCharts: String?, accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { @@ -218,7 +218,7 @@ private fun DisplayNoteLink( @Composable private fun DisplayAddress( nip19: Nip19Bech32.NAddress, - additionalChars: String, + additionalChars: String?, accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { @@ -245,16 +245,22 @@ private fun DisplayAddress( } if (noteBase == null) { - Text( - remember { "@${nip19.atag}$additionalChars" }, - ) + if (additionalChars != null) { + Text( + remember { "@${nip19.atag}$additionalChars" }, + ) + } else { + Text( + remember { "@${nip19.atag}" }, + ) + } } } @Composable -private fun DisplayUser( +public fun DisplayUser( userHex: HexKey, - additionalChars: String, + additionalChars: String?, accountViewModel: AccountViewModel, nav: (String) -> Unit, ) { @@ -274,16 +280,22 @@ private fun DisplayUser( userBase?.let { RenderUserAsClickableText(it, additionalChars, nav) } if (userBase == null) { - Text( - remember { "@${userHex}$additionalChars" }, - ) + if (additionalChars != null) { + Text( + remember { "@${userHex}$additionalChars" }, + ) + } else { + Text( + remember { "@$userHex" }, + ) + } } } @Composable private fun RenderUserAsClickableText( baseUser: User, - additionalChars: String, + additionalChars: String?, nav: (String) -> Unit, ) { val userState by baseUser.live().userMetadataInfo.observeAsState() diff --git a/app/src/test/java/com/vitorpamplona/amethyst/NewMessageTaggerKeyParseTest.kt b/app/src/test/java/com/vitorpamplona/amethyst/NewMessageTaggerKeyParseTest.kt index 43645c380..7511e3123 100644 --- a/app/src/test/java/com/vitorpamplona/amethyst/NewMessageTaggerKeyParseTest.kt +++ b/app/src/test/java/com/vitorpamplona/amethyst/NewMessageTaggerKeyParseTest.kt @@ -60,7 +60,7 @@ class NewMessageTaggerKeyParseTest { "1532adbe1b369beca9af174076c4736faeb5ef527f1275a4af200121c0f55605", (result?.key?.entity as? Nip19Bech32.Note)?.hex, ) - assertEquals("", result?.restOfWord) + assertEquals(null, result?.restOfWord) } @Test @@ -73,7 +73,7 @@ class NewMessageTaggerKeyParseTest { "460c25e682fda7832b52d1f22d3d22b3176d972f60dcdc3212ed8c92ef85065c", (result?.key?.entity as? Nip19Bech32.NPub)?.hex, ) - assertEquals("", result?.restOfWord) + assertEquals(null, result?.restOfWord) } @Test diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/encoders/Nip19Bech32.kt b/quartz/src/main/java/com/vitorpamplona/quartz/encoders/Nip19Bech32.kt index 31267b345..3a8cab829 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/encoders/Nip19Bech32.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/encoders/Nip19Bech32.kt @@ -53,7 +53,7 @@ object Nip19Bech32 { ) @Immutable - data class ParseReturn(val entity: Entity, val additionalChars: String = "") + data class ParseReturn(val entity: Entity, val additionalChars: String? = null) interface Entity @@ -96,7 +96,7 @@ object Nip19Bech32 { if (type == null) return null - return parseComponents(type, key, additionalChars) + return parseComponents(type, key, additionalChars.ifEmpty { null }) } catch (e: Throwable) { Log.e("NIP19 Parser", "Issue trying to Decode NIP19 $uri: ${e.message}", e) } @@ -123,7 +123,7 @@ object Nip19Bech32 { "nembed1" -> nembed(bytes) else -> null }?.let { - ParseReturn(it, additionalChars ?: "") + ParseReturn(it, additionalChars) } } catch (e: Throwable) { Log.w("NIP19 Parser", "Issue trying to Decode NIP19 $key: ${e.message}", e)