Fixing crash when calling localcache on the main thread.

This commit is contained in:
Vitor Pamplona
2024-05-30 11:21:39 -04:00
parent 632c78792a
commit 36b0c8acb5

View File

@@ -1358,26 +1358,27 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
} }
} }
suspend fun cachedDVMContentDiscovery(pubkeyHex: String): Note? { suspend fun cachedDVMContentDiscovery(pubkeyHex: String): Note? =
val fifteenMinsAgo = TimeUtils.fifteenMinutesAgo() withContext(Dispatchers.IO) {
// First check if we have an actual response from the DVM in LocalCache val fifteenMinsAgo = TimeUtils.fifteenMinutesAgo()
val response = // First check if we have an actual response from the DVM in LocalCache
LocalCache.notes.maxOrNullOf( val response =
filter = { key, note -> LocalCache.notes.maxOrNullOf(
val noteEvent = note.event filter = { key, note ->
noteEvent is NIP90ContentDiscoveryResponseEvent && val noteEvent = note.event
noteEvent.pubKey == pubkeyHex && noteEvent is NIP90ContentDiscoveryResponseEvent &&
noteEvent.isTaggedUser(account.keyPair.pubKey.toHexKey()) && noteEvent.pubKey == pubkeyHex &&
noteEvent.createdAt > fifteenMinsAgo noteEvent.isTaggedUser(account.keyPair.pubKey.toHexKey()) &&
}, noteEvent.createdAt > fifteenMinsAgo
comparator = CreatedAtComparator, },
) comparator = CreatedAtComparator,
)
// If we have a response, get the tagged Request Event otherwise null // If we have a response, get the tagged Request Event otherwise null
return response?.event?.tags()?.firstOrNull { it.size > 1 && it[0] == "e" }?.get(1)?.let { return@withContext response?.event?.tags()?.firstOrNull { it.size > 1 && it[0] == "e" }?.get(1)?.let {
LocalCache.getOrCreateNote(it) LocalCache.getOrCreateNote(it)
}
} }
}
fun sendZapPaymentRequestFor( fun sendZapPaymentRequestFor(
bolt11: String, bolt11: String,