mirror of
https://github.com/fiatjaf/nak.git
synced 2024-10-30 09:09:08 -04:00
get rid of the string arithmetics and just re-encode nip19 on the fly.
This commit is contained in:
parent
b1d9c9d5bf
commit
551e09ea0f
|
@ -266,11 +266,33 @@ object Components {
|
||||||
self.value.get.flatMap(url =>
|
self.value.get.flatMap(url =>
|
||||||
if url.startsWith("wss://") || url
|
if url.startsWith("wss://") || url
|
||||||
.startsWith("ws://")
|
.startsWith("ws://")
|
||||||
then
|
then {
|
||||||
store.input.update(
|
store.result.get.flatMap(result =>
|
||||||
_.trim() ++ " + " ++ url
|
store.input.set(
|
||||||
) >> active.set(false)
|
result
|
||||||
else IO.unit
|
.map {
|
||||||
|
case a: AddressPointer =>
|
||||||
|
NIP19
|
||||||
|
.encode(
|
||||||
|
a.copy(relays = url :: a.relays)
|
||||||
|
)
|
||||||
|
case p: ProfilePointer =>
|
||||||
|
NIP19
|
||||||
|
.encode(
|
||||||
|
p.copy(relays = url :: p.relays)
|
||||||
|
)
|
||||||
|
case e: EventPointer =>
|
||||||
|
NIP19
|
||||||
|
.encode(
|
||||||
|
e.copy(relays = url :: e.relays)
|
||||||
|
)
|
||||||
|
case r => ""
|
||||||
|
}
|
||||||
|
.getOrElse("")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
>> active.set(false)
|
||||||
|
} else IO.unit
|
||||||
)
|
)
|
||||||
case _ => IO.unit
|
case _ => IO.unit
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,12 @@ object Parser {
|
||||||
|
|
||||||
def parseInput(input: String): Result =
|
def parseInput(input: String): Result =
|
||||||
if input == "" then Left("")
|
if input == "" then Left("")
|
||||||
else {
|
else
|
||||||
val spl = additions.split(input)
|
ByteVector
|
||||||
val result = ByteVector
|
.fromHex(input)
|
||||||
.fromHex(spl.head)
|
|
||||||
.flatMap(b => Try(Right(ByteVector32(b))).toOption)
|
.flatMap(b => Try(Right(ByteVector32(b))).toOption)
|
||||||
.getOrElse(
|
.getOrElse(
|
||||||
NIP19.decode(spl.head) match {
|
NIP19.decode(input) match {
|
||||||
case Right(pp: ProfilePointer) => Right(pp)
|
case Right(pp: ProfilePointer) => Right(pp)
|
||||||
case Right(evp: EventPointer) => Right(evp)
|
case Right(evp: EventPointer) => Right(evp)
|
||||||
case Right(sk: PrivateKey) => Right(sk)
|
case Right(sk: PrivateKey) => Right(sk)
|
||||||
|
@ -43,17 +42,4 @@ object Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
val extraRelays = spl
|
|
||||||
.drop(1)
|
|
||||||
.toList
|
|
||||||
.filter(e => e.startsWith("wss://") || e.startsWith("ws://"))
|
|
||||||
|
|
||||||
result.map {
|
|
||||||
case a: AddressPointer => a.copy(relays = a.relays ::: extraRelays)
|
|
||||||
case p: ProfilePointer => p.copy(relays = p.relays ::: extraRelays)
|
|
||||||
case e: EventPointer => e.copy(relays = e.relays ::: extraRelays)
|
|
||||||
case r => r
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user