mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-28 23:53:03 +02:00
moves the processing of nip19 links to the default thread
This commit is contained in:
@@ -1548,6 +1548,7 @@ class AccountViewModel(
|
|||||||
val accountViewModel: AccountViewModel,
|
val accountViewModel: AccountViewModel,
|
||||||
) : GenericBaseCache<String, LoadedBechLink>(20) {
|
) : GenericBaseCache<String, LoadedBechLink>(20) {
|
||||||
override suspend fun compute(key: String): LoadedBechLink? =
|
override suspend fun compute(key: String): LoadedBechLink? =
|
||||||
|
withContext(Dispatchers.Default) {
|
||||||
Nip19Bech32.uriToRoute(key)?.let {
|
Nip19Bech32.uriToRoute(key)?.let {
|
||||||
var returningNote: Note? = null
|
var returningNote: Note? = null
|
||||||
|
|
||||||
@@ -1555,27 +1556,41 @@ class AccountViewModel(
|
|||||||
is Nip19Bech32.NSec -> {}
|
is Nip19Bech32.NSec -> {}
|
||||||
is Nip19Bech32.NPub -> {}
|
is Nip19Bech32.NPub -> {}
|
||||||
is Nip19Bech32.NProfile -> {}
|
is Nip19Bech32.NProfile -> {}
|
||||||
is Nip19Bech32.Note -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } }
|
is Nip19Bech32.Note -> {
|
||||||
is Nip19Bech32.NEvent -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } }
|
LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note ->
|
||||||
|
returningNote = note
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is Nip19Bech32.NEvent -> {
|
||||||
|
LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note ->
|
||||||
|
returningNote = note
|
||||||
|
}
|
||||||
|
}
|
||||||
is Nip19Bech32.NEmbed ->
|
is Nip19Bech32.NEmbed ->
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
val baseNote = LocalCache.getOrCreateNote(parsed.event)
|
val baseNote = LocalCache.getOrCreateNote(parsed.event)
|
||||||
if (baseNote.event == null) {
|
if (baseNote.event == null) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.Default) {
|
||||||
LocalCache.verifyAndConsume(parsed.event, null)
|
LocalCache.verifyAndConsume(parsed.event, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
returningNote = baseNote
|
returningNote = baseNote
|
||||||
}
|
}
|
||||||
|
|
||||||
is Nip19Bech32.NRelay -> {}
|
is Nip19Bech32.NRelay -> {}
|
||||||
is Nip19Bech32.NAddress -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.atag)?.let { note -> returningNote = note } }
|
is Nip19Bech32.NAddress -> {
|
||||||
|
LocalCache.checkGetOrCreateNote(parsed.atag)?.let { note ->
|
||||||
|
returningNote = note
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadedBechLink(returningNote, it)
|
LoadedBechLink(returningNote, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HasNotificationDot(
|
class HasNotificationDot(
|
||||||
|
@@ -31,7 +31,10 @@ fun <K, V> produceCachedState(
|
|||||||
key: K,
|
key: K,
|
||||||
): State<V?> =
|
): State<V?> =
|
||||||
produceState(initialValue = cache.cached(key), key1 = key) {
|
produceState(initialValue = cache.cached(key), key1 = key) {
|
||||||
value = cache.update(key)
|
val newValue = cache.update(key)
|
||||||
|
if (value != newValue) {
|
||||||
|
value = newValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -41,7 +44,10 @@ fun <K, V> produceCachedState(
|
|||||||
updateValue: K,
|
updateValue: K,
|
||||||
): State<V?> =
|
): State<V?> =
|
||||||
produceState(initialValue = cache.cached(updateValue), key1 = key) {
|
produceState(initialValue = cache.cached(updateValue), key1 = key) {
|
||||||
value = cache.update(updateValue)
|
val newValue = cache.update(updateValue)
|
||||||
|
if (value != newValue) {
|
||||||
|
value = newValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CachedState<K, V> {
|
interface CachedState<K, V> {
|
||||||
|
Reference in New Issue
Block a user