Moves Preview and NIP05 verification to IO Threads
This commit is contained in:
@@ -11,6 +11,8 @@ import androidx.compose.runtime.setValue
|
|||||||
import com.baha.url.preview.IUrlPreviewCallback
|
import com.baha.url.preview.IUrlPreviewCallback
|
||||||
import com.baha.url.preview.UrlInfoItem
|
import com.baha.url.preview.UrlInfoItem
|
||||||
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -19,6 +21,7 @@ fun UrlPreview(url: String, urlText: String, showUrlIfError: Boolean = true) {
|
|||||||
|
|
||||||
// Doesn't use a viewModel because of viewModel reusing issues (too many UrlPreview are created).
|
// Doesn't use a viewModel because of viewModel reusing issues (too many UrlPreview are created).
|
||||||
LaunchedEffect(url) {
|
LaunchedEffect(url) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
UrlCachedPreviewer.previewInfo(url, object : IUrlPreviewCallback {
|
UrlCachedPreviewer.previewInfo(url, object : IUrlPreviewCallback {
|
||||||
override fun onComplete(urlInfo: UrlInfoItem) {
|
override fun onComplete(urlInfo: UrlInfoItem) {
|
||||||
if (urlInfo.allFetchComplete() && urlInfo.url == url)
|
if (urlInfo.allFetchComplete() && urlInfo.url == url)
|
||||||
@@ -32,6 +35,7 @@ fun UrlPreview(url: String, urlText: String, showUrlIfError: Boolean = true) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Crossfade(targetState = urlPreviewState, animationSpec = tween(durationMillis = 100)) { state ->
|
Crossfade(targetState = urlPreviewState, animationSpec = tween(durationMillis = 100)) { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
|
|||||||
@@ -33,12 +33,15 @@ import com.vitorpamplona.amethyst.model.User
|
|||||||
import com.vitorpamplona.amethyst.model.UserMetadata
|
import com.vitorpamplona.amethyst.model.UserMetadata
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Nip05
|
import com.vitorpamplona.amethyst.ui.theme.Nip05
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String): State<Boolean?> {
|
fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String): State<Boolean?> {
|
||||||
var nip05Verified = remember { mutableStateOf<Boolean?>(null) }
|
var nip05Verified = remember { mutableStateOf<Boolean?>(null) }
|
||||||
|
|
||||||
LaunchedEffect(key1 = user) {
|
LaunchedEffect(key1 = user) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
user.nip05?.ifBlank { null }?.let { nip05 ->
|
user.nip05?.ifBlank { null }?.let { nip05 ->
|
||||||
val now = Date().time / 1000
|
val now = Date().time / 1000
|
||||||
if ((user.nip05LastVerificationTime ?: 0) > (now - 60 * 60)) { // 1hour
|
if ((user.nip05LastVerificationTime ?: 0) > (now - 60 * 60)) { // 1hour
|
||||||
@@ -67,6 +70,7 @@ fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String): State<Bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nip05Verified
|
return nip05Verified
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user