Added withContext(Dispatchers.IO) for network call

This commit is contained in:
davotoula
2025-09-15 18:25:52 +02:00
parent 5796052f36
commit f4501d799d
@@ -20,6 +20,7 @@
*/
package com.vitorpamplona.amethyst.ui.screen.loggedIn.home.live
import android.util.Log
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
@@ -36,7 +37,9 @@ import com.vitorpamplona.amethyst.model.emphChat.EphemeralChatChannel
import com.vitorpamplona.amethyst.model.nip53LiveActivities.LiveActivitiesChannel
import com.vitorpamplona.amethyst.service.OnlineChecker
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
@Composable
fun LiveStatusIndicator(
@@ -75,6 +78,8 @@ private suspend fun checkChannelIsOnline(
channel: Channel,
accountViewModel: AccountViewModel,
): Boolean =
withContext(Dispatchers.IO) {
try {
when (channel) {
is LiveActivitiesChannel -> {
// Check if streaming URL is online, fall back to relay check
@@ -98,3 +103,9 @@ private suspend fun checkChannelIsOnline(
}
else -> false
}
} catch (e: Exception) {
Log.d("LiveStatusIndicator", "Network error checking channel ${channel.toBestDisplayName()}: ${e.message}")
// Return false if any network error occurs
false
}
}