Fixes the writting of nostr addresses in the text with additional words connected to them without a space. It adds a space if the first char is in the bech alphabet.
This commit is contained in:
@@ -4,6 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.quartz.crypto.KeyPair
|
import com.vitorpamplona.quartz.crypto.KeyPair
|
||||||
|
import com.vitorpamplona.quartz.encoders.Bech32
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19
|
||||||
import com.vitorpamplona.quartz.encoders.bechToBytes
|
import com.vitorpamplona.quartz.encoders.bechToBytes
|
||||||
@@ -69,19 +70,19 @@ class NewMessageTagger(
|
|||||||
if (results?.key?.type == Nip19.Type.USER) {
|
if (results?.key?.type == Nip19.Type.USER) {
|
||||||
val user = dao.getOrCreateUser(results.key.hex)
|
val user = dao.getOrCreateUser(results.key.hex)
|
||||||
|
|
||||||
"nostr:${user.pubkeyNpub()}${results.restOfWord}"
|
getNostrAddress(user.pubkeyNpub(), results.restOfWord)
|
||||||
} else if (results?.key?.type == Nip19.Type.NOTE) {
|
} else if (results?.key?.type == Nip19.Type.NOTE) {
|
||||||
val note = dao.getOrCreateNote(results.key.hex)
|
val note = dao.getOrCreateNote(results.key.hex)
|
||||||
|
|
||||||
"nostr:${note.toNEvent()}${results.restOfWord}"
|
getNostrAddress(note.toNEvent(), results.restOfWord)
|
||||||
} else if (results?.key?.type == Nip19.Type.EVENT) {
|
} else if (results?.key?.type == Nip19.Type.EVENT) {
|
||||||
val note = dao.getOrCreateNote(results.key.hex)
|
val note = dao.getOrCreateNote(results.key.hex)
|
||||||
|
|
||||||
"nostr:${note.toNEvent()}${results.restOfWord}"
|
getNostrAddress(note.toNEvent(), results.restOfWord)
|
||||||
} else if (results?.key?.type == Nip19.Type.ADDRESS) {
|
} else if (results?.key?.type == Nip19.Type.ADDRESS) {
|
||||||
val note = dao.checkGetOrCreateAddressableNote(results.key.hex)
|
val note = dao.checkGetOrCreateAddressableNote(results.key.hex)
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
"nostr:${note.idNote()}${results.restOfWord}"
|
getNostrAddress(note.idNote(), results.restOfWord)
|
||||||
} else {
|
} else {
|
||||||
word
|
word
|
||||||
}
|
}
|
||||||
@@ -92,6 +93,18 @@ class NewMessageTagger(
|
|||||||
}.joinToString("\n")
|
}.joinToString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getNostrAddress(bechAddress: String, restOfTheWord: String): String {
|
||||||
|
return if (restOfTheWord.isEmpty()) {
|
||||||
|
"nostr:$bechAddress"
|
||||||
|
} else {
|
||||||
|
if (Bech32.alphabet.contains(restOfTheWord.get(0), true)) {
|
||||||
|
"nostr:$bechAddress $restOfTheWord"
|
||||||
|
} else {
|
||||||
|
"nostr:${bechAddress}$restOfTheWord"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
data class DirtyKeyInfo(val key: Nip19.Return, val restOfWord: String)
|
data class DirtyKeyInfo(val key: Nip19.Return, val restOfWord: String)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user