Fix more relay connection issues

This commit is contained in:
greenart7c3
2024-12-04 08:49:36 -03:00
parent f326568780
commit 29228ceca9
4 changed files with 37 additions and 9 deletions
@@ -95,7 +95,7 @@ data class BunkerRequest(
currentAccount = jsonObject.get("currentAccount")?.asText()?.intern() ?: "",
encryptionType = encryptionType,
nostrConnectSecret = jsonObject.get("nostrConnectSecret")?.asText()?.intern() ?: "",
closeApplication = jsonObject.get("closeApplication")?.asBoolean() ?: false,
closeApplication = jsonObject.get("closeApplication")?.asBoolean() ?: true,
)
}
@@ -385,6 +385,8 @@ object IntentUtils {
encryptedContent,
) {
GlobalScope.launch(Dispatchers.IO) {
Log.d("IntentUtils", "Sending response to relays ${relays.map { it.url }}")
if (RelayPool.getAll().any { !it.isConnected() }) {
NostrSigner.getInstance().checkForNewRelays(
newRelays = relays.toSet(),
@@ -393,7 +395,10 @@ object IntentUtils {
val success = Client.sendAndWaitForResponse(it, relayList = relays)
if (success) {
Log.d("IntentUtils", "Success response to relays ${relays.map { it.url }}")
onDone()
} else {
Log.d("IntentUtils", "Failed response to relays ${relays.map { it.url }}")
}
AmberListenerSingleton.getListener()?.let {
Client.unsubscribe(it)
@@ -145,7 +145,20 @@ fun sendResult(
onLoading(true)
GlobalScope.launch(Dispatchers.IO) {
val defaultRelays = NostrSigner.getInstance().settings.defaultRelays
val savedApplication = database.applicationDao().getByKey(key)
var savedApplication = database.applicationDao().getByKey(key)
if (savedApplication == null && intentData.bunkerRequest?.secret != null) {
savedApplication = database.applicationDao().getByKey(intentData.bunkerRequest.secret)
if (savedApplication != null) {
val tempApplication = savedApplication.application.copy(
key = key,
)
val tempApp2 = ApplicationWithPermissions(
application = tempApplication,
permissions = savedApplication.permissions,
)
database.applicationDao().insertApplicationWithPermissions(tempApp2)
}
}
val relays = savedApplication?.application?.relays?.ifEmpty { defaultRelays } ?: (intentData.bunkerRequest?.relays?.ifEmpty { defaultRelays } ?: defaultRelays)
if (intentData.bunkerRequest != null) {
NostrSigner.getInstance().checkForNewRelays(
@@ -256,16 +269,10 @@ fun sendResult(
account,
intentData.bunkerRequest,
BunkerResponse(intentData.bunkerRequest.id, event, null),
relays,
application.application.relays.ifEmpty { relays },
onLoading,
onDone = {
EventNotificationConsumer(context).notificationManager().cancelAll()
if (intentData.bunkerRequest.secret.isNotBlank()) {
val secretApplication = database.applicationDao().getBySecret(intentData.bunkerRequest.secret)
secretApplication?.let {
database.applicationDao().delete(it.application)
}
}
if (intentData.type == SignerType.CONNECT) {
database.applicationDao().deletePermissions(key)
}
@@ -306,6 +306,22 @@ suspend fun onAddRelay(
return@secondLaunch
}
val relays = NostrSigner.getInstance().getSavedRelays()
if (relays.any { it.url == addedWSS }) {
relays2.add(
RelaySetupInfo(
addedWSS,
read = true,
write = true,
feedTypes = COMMON_FEED_TYPES,
),
)
onDone()
textFieldRelay.value = TextFieldValue("")
isLoading.value = false
return@secondLaunch
}
val signer = NostrSignerInternal(KeyPair())
val encryptedContent = signer.signerSync.nip04Encrypt(
"Test bunker event",