diff --git a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/NotificationFeedFilterModeOverrideTest.kt b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/NotificationFeedFilterModeOverrideTest.kt index 4392be5a34..c869020eea 100644 --- a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/NotificationFeedFilterModeOverrideTest.kt +++ b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/NotificationFeedFilterModeOverrideTest.kt @@ -67,13 +67,16 @@ class NotificationFeedFilterModeOverrideTest { private val client = NostrClient( - OkHttpWebSocket.Builder { - OkHttpClient - .Builder() - .followRedirects(true) - .followSslRedirects(true) - .build() - }, + OkHttpWebSocket.Builder( + httpClient = { + OkHttpClient + .Builder() + .followRedirects(true) + .followSslRedirects(true) + .build() + }, + canDial = { true }, + ), scope, ) diff --git a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadDualAxisChartAssemblerTest.kt b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadDualAxisChartAssemblerTest.kt index 2bf278b03b..2cc4fcd1e9 100644 --- a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadDualAxisChartAssemblerTest.kt +++ b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadDualAxisChartAssemblerTest.kt @@ -58,13 +58,16 @@ class ThreadDualAxisChartAssemblerTest { val client = NostrClient( - OkHttpWebSocket.Builder { - OkHttpClient - .Builder() - .followRedirects(true) - .followSslRedirects(true) - .build() - }, + OkHttpWebSocket.Builder( + httpClient = { + OkHttpClient + .Builder() + .followRedirects(true) + .followSslRedirects(true) + .build() + }, + canDial = { true }, + ), scope, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/napplet/gateways/AccountNappletGateways.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/napplet/gateways/AccountNappletGateways.kt index 04e0c50991..c99dbcc37d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/napplet/gateways/AccountNappletGateways.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/napplet/gateways/AccountNappletGateways.kt @@ -57,6 +57,7 @@ import com.vitorpamplona.quartz.utils.sha256.sha256 import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.withTimeout import java.io.ByteArrayInputStream +import kotlin.time.Duration.Companion.seconds /** * The account adapter: turns a signed-in [Account] into a configured [NappletBroker] by wiring the @@ -137,6 +138,8 @@ class AccountNappletGateways( body: String, ) { val manager = NotificationManagerCompat.from(context) + if (!manager.areNotificationsEnabled()) return + val channel = NotificationChannelCompat .Builder(NOTIFY_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_DEFAULT) @@ -151,7 +154,11 @@ class AccountNappletGateways( .setContentText(body) .setAutoCancel(true) .build() - manager.notify(id.hashCode(), notification) + try { + manager.notify(id.hashCode(), notification) + } catch (_: SecurityException) { + // Best effort: if the user revoked permission between the check and here, just no-op. + } } /** @@ -213,7 +220,7 @@ class AccountNappletGateways( emptyList() } else { runCatching { - account.client.fetchAll(filters = relays.associateWith { filters }, timeoutMs = QUERY_TIMEOUT_MS) + account.client.fetchAll(filters = relays.associateWith { filters }, timeoutMs = QUERY_TIMEOUT.inWholeMilliseconds) }.getOrDefault(emptyList()) } val fromCache = filters.flatMap { filter -> account.cache.filter(filter).mapNotNull { it.event } } @@ -245,12 +252,12 @@ class AccountNappletGateways( else -> result.completeExceptionally(RuntimeException("Unexpected wallet response.")) } } - return withTimeout(WALLET_TIMEOUT_MS) { result.await() } + return withTimeout(WALLET_TIMEOUT) { result.await() } } companion object { - private const val QUERY_TIMEOUT_MS = 8_000L - private const val WALLET_TIMEOUT_MS = 60_000L + private val QUERY_TIMEOUT = 8.seconds + private val WALLET_TIMEOUT = 60.seconds /** Amethyst's brand purple (`AmethystPurple`, commons Colors.kt), exposed as the theme primary. */ private const val AMETHYST_PURPLE = "#9A82DB"