From ce5c635a0048702303ed21a808a60ad5d45306a0 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Fri, 30 Aug 2024 10:04:21 -0300 Subject: [PATCH] Use default relays if empty --- .../service/EventNotificationConsumer.kt | 11 +++-------- .../nostrsigner/service/IntentUtils.kt | 19 +++---------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/EventNotificationConsumer.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/EventNotificationConsumer.kt index bd4313a6..9b87f39b 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/EventNotificationConsumer.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/EventNotificationConsumer.kt @@ -189,7 +189,6 @@ class EventNotificationConsumer(private val applicationContext: Context) { permission.application.relays, onLoading = {}, onDone = {}, - checkForEmptyRelays = false, ) return } @@ -221,10 +220,9 @@ class EventNotificationConsumer(private val applicationContext: Context) { acc, bunkerRequest, BunkerResponse(bunkerRequest.id, "", message), - applicationWithSecret?.application?.relays ?: listOf(), + applicationWithSecret?.application?.relays ?: NostrSigner.getInstance().getSavedRelays().toList(), onLoading = { }, onDone = { }, - checkForEmptyRelays = false, ) return } @@ -263,7 +261,7 @@ class EventNotificationConsumer(private val applicationContext: Context) { if (type == SignerType.CONNECT) { message = "$name ${bunkerPermission.toLocalizedString(applicationContext)}" } - val relays = permission?.application?.relays ?: applicationWithSecret?.application?.relays ?: listOf() + val relays = permission?.application?.relays ?: applicationWithSecret?.application?.relays ?: NostrSigner.getInstance().getSavedRelays().toList() if (permission == null && applicationWithSecret == null && !acc.allowNewConnections) { IntentUtils.sendBunkerResponse( @@ -271,10 +269,9 @@ class EventNotificationConsumer(private val applicationContext: Context) { acc, bunkerRequest, BunkerResponse(bunkerRequest.id, "", "no permission"), - listOf(), + relays, onLoading = { }, onDone = {}, - checkForEmptyRelays = false, ) return } @@ -302,7 +299,6 @@ class EventNotificationConsumer(private val applicationContext: Context) { relays, onLoading = { }, onDone = { }, - checkForEmptyRelays = false, ) } else { val index = localCursor.getColumnIndex("event") @@ -316,7 +312,6 @@ class EventNotificationConsumer(private val applicationContext: Context) { relays, onLoading = { }, onDone = { }, - checkForEmptyRelays = false, ) } } else { diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt index cc738be4..f9b263fd 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt @@ -316,14 +316,7 @@ object IntentUtils { relays: List, onLoading: (Boolean) -> Unit, onDone: () -> Unit, - checkForEmptyRelays: Boolean = true, ) { - if (relays.isEmpty() && checkForEmptyRelays) { - onLoading(false) - AmberListenerSingleton.accountStateViewModel?.toast("Relays", "No relays found") - return - } - AmberListenerSingleton.getListener()?.let { Client.unsubscribe(it) } @@ -345,9 +338,7 @@ object IntentUtils { account, bunkerRequest.localKey, encryptedContent, - relays, - checkForEmptyRelays, - context, + relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() }, onLoading, onDone, ) @@ -362,9 +353,7 @@ object IntentUtils { account, bunkerRequest.localKey, encryptedContent, - relays, - checkForEmptyRelays, - context, + relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() }, onLoading, onDone, ) @@ -379,8 +368,6 @@ object IntentUtils { localKey: String, encryptedContent: String, relays: List, - checkForEmptyRelays: Boolean, - context: Context, onLoading: (Boolean) -> Unit, onDone: () -> Unit, ) { @@ -391,7 +378,7 @@ object IntentUtils { encryptedContent, ) { GlobalScope.launch(Dispatchers.IO) { - if (!checkForEmptyRelays || RelayPool.getAll().any { !it.isConnected() }) { + if (RelayPool.getAll().any { !it.isConnected() }) { NostrSigner.getInstance().checkForNewRelays( NostrSigner.getInstance().settings.notificationType != NotificationType.DIRECT, newRelays = relays.toSet(),