kopia lustrzana https://github.com/vitorpamplona/amethyst
Moves loading of an embed event to thread.
rodzic
bbbb614718
commit
31958215be
|
@ -171,6 +171,22 @@ object LocalCache {
|
||||||
return channels.get(key)
|
return channels.get(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getNoteIfExists(event: Event): Note? {
|
||||||
|
return if (event is AddressableEvent) {
|
||||||
|
getAddressableNoteIfExists(event.addressTag())
|
||||||
|
} else {
|
||||||
|
getNoteIfExists(event.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getOrCreateNote(event: Event): Note {
|
||||||
|
return if (event is AddressableEvent) {
|
||||||
|
getOrCreateAddressableNote(event.address())
|
||||||
|
} else {
|
||||||
|
getOrCreateNote(event.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun checkGetOrCreateNote(key: String): Note? {
|
fun checkGetOrCreateNote(key: String): Note? {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
|
|
|
@ -1035,13 +1035,6 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadNEmbedIfNeeded(nembed: Event) {
|
|
||||||
val baseNote = LocalCache.getNoteIfExists(nembed.id)
|
|
||||||
if (baseNote?.event == null) {
|
|
||||||
LocalCache.verifyAndConsume(nembed, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun checkIsOnline(
|
fun checkIsOnline(
|
||||||
media: String?,
|
media: String?,
|
||||||
onDone: (Boolean) -> Unit,
|
onDone: (Boolean) -> Unit,
|
||||||
|
@ -1374,11 +1367,14 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
||||||
is Nip19Bech32.NEvent -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } }
|
is Nip19Bech32.NEvent -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.hex)?.let { note -> returningNote = note } }
|
||||||
is Nip19Bech32.NEmbed ->
|
is Nip19Bech32.NEmbed ->
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
accountViewModel.loadNEmbedIfNeeded(parsed.event)
|
val baseNote = LocalCache.getOrCreateNote(parsed.event)
|
||||||
|
if (baseNote.event == null) {
|
||||||
LocalCache.checkGetOrCreateNote(parsed.event.id)?.let { note ->
|
launch(Dispatchers.IO) {
|
||||||
returningNote = note
|
LocalCache.verifyAndConsume(parsed.event, null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 -> withContext(Dispatchers.IO) { LocalCache.checkGetOrCreateNote(parsed.atag)?.let { note -> returningNote = note } }
|
||||||
|
|
Ładowanie…
Reference in New Issue