Skip to content

Commit

Permalink
Use default relays if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
greenart7c3 committed Aug 30, 2024
1 parent 134569e commit ce5c635
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ class EventNotificationConsumer(private val applicationContext: Context) {
permission.application.relays,
onLoading = {},
onDone = {},
checkForEmptyRelays = false,
)
return
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -263,18 +261,17 @@ 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(
applicationContext,
acc,
bunkerRequest,
BunkerResponse(bunkerRequest.id, "", "no permission"),
listOf(),
relays,
onLoading = { },
onDone = {},
checkForEmptyRelays = false,
)
return
}
Expand Down Expand Up @@ -302,7 +299,6 @@ class EventNotificationConsumer(private val applicationContext: Context) {
relays,
onLoading = { },
onDone = { },
checkForEmptyRelays = false,
)
} else {
val index = localCursor.getColumnIndex("event")
Expand All @@ -316,7 +312,6 @@ class EventNotificationConsumer(private val applicationContext: Context) {
relays,
onLoading = { },
onDone = { },
checkForEmptyRelays = false,
)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,7 @@ object IntentUtils {
relays: List<RelaySetupInfo>,
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)
}
Expand All @@ -345,9 +338,7 @@ object IntentUtils {
account,
bunkerRequest.localKey,
encryptedContent,
relays,
checkForEmptyRelays,
context,
relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() },
onLoading,
onDone,
)
Expand All @@ -362,9 +353,7 @@ object IntentUtils {
account,
bunkerRequest.localKey,
encryptedContent,
relays,
checkForEmptyRelays,
context,
relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() },
onLoading,
onDone,
)
Expand All @@ -379,8 +368,6 @@ object IntentUtils {
localKey: String,
encryptedContent: String,
relays: List<RelaySetupInfo>,
checkForEmptyRelays: Boolean,
context: Context,
onLoading: (Boolean) -> Unit,
onDone: () -> Unit,
) {
Expand All @@ -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(),
Expand Down

0 comments on commit ce5c635

Please sign in to comment.