mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
Fix app duplicated when connecting to bunker
This commit is contained in:
@@ -125,8 +125,13 @@ interface ApplicationDao {
|
||||
}
|
||||
|
||||
@Delete
|
||||
@Transaction
|
||||
fun delete(entity: ApplicationEntity)
|
||||
|
||||
@Query("DELETE FROM application WHERE `key` = :key")
|
||||
@Transaction
|
||||
fun delete(key: String)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun innerAddHistory(entity: HistoryEntity)
|
||||
|
||||
|
||||
@@ -342,12 +342,13 @@ object IntentUtils {
|
||||
bunkerRequest.localKey,
|
||||
) { encryptedContent ->
|
||||
sendBunkerResponse(
|
||||
account,
|
||||
bunkerRequest.localKey,
|
||||
encryptedContent,
|
||||
relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() },
|
||||
onLoading,
|
||||
onDone,
|
||||
bunkerRequest = bunkerRequest,
|
||||
account = account,
|
||||
localKey = bunkerRequest.localKey,
|
||||
encryptedContent = encryptedContent,
|
||||
relays = relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() },
|
||||
onLoading = onLoading,
|
||||
onDone = onDone,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -357,12 +358,13 @@ object IntentUtils {
|
||||
bunkerRequest.localKey,
|
||||
) { encryptedContent ->
|
||||
sendBunkerResponse(
|
||||
account,
|
||||
bunkerRequest.localKey,
|
||||
encryptedContent,
|
||||
relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() },
|
||||
onLoading,
|
||||
onDone,
|
||||
bunkerRequest = bunkerRequest,
|
||||
account = account,
|
||||
localKey = bunkerRequest.localKey,
|
||||
encryptedContent = encryptedContent,
|
||||
relays = relays.ifEmpty { NostrSigner.getInstance().getSavedRelays().toList() },
|
||||
onLoading = onLoading,
|
||||
onDone = onDone,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -371,6 +373,7 @@ object IntentUtils {
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
private fun sendBunkerResponse(
|
||||
bunkerRequest: BunkerRequest? = null,
|
||||
account: Account,
|
||||
localKey: String,
|
||||
encryptedContent: String,
|
||||
@@ -385,7 +388,7 @@ object IntentUtils {
|
||||
encryptedContent,
|
||||
) {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
Log.d("IntentUtils", "Sending response to relays ${relays.map { it.url }}")
|
||||
Log.d("IntentUtils", "Sending response to relays ${relays.map { it.url }} type ${bunkerRequest?.method}")
|
||||
|
||||
if (RelayPool.getAll().any { !it.isConnected() }) {
|
||||
NostrSigner.getInstance().checkForNewRelays(
|
||||
@@ -395,10 +398,10 @@ object IntentUtils {
|
||||
|
||||
val success = Client.sendAndWaitForResponse(it, relayList = relays)
|
||||
if (success) {
|
||||
Log.d("IntentUtils", "Success response to relays ${relays.map { it.url }}")
|
||||
Log.d("IntentUtils", "Success response to relays ${relays.map { it.url }} type ${bunkerRequest?.method}")
|
||||
onDone()
|
||||
} else {
|
||||
Log.d("IntentUtils", "Failed response to relays ${relays.map { it.url }}")
|
||||
Log.d("IntentUtils", "Failed response to relays ${relays.map { it.url }} type ${bunkerRequest?.method}")
|
||||
}
|
||||
AmberListenerSingleton.getListener()?.let {
|
||||
Client.unsubscribe(it)
|
||||
|
||||
@@ -154,11 +154,16 @@ fun sendResult(
|
||||
)
|
||||
val tempApp2 = ApplicationWithPermissions(
|
||||
application = tempApplication,
|
||||
permissions = savedApplication.permissions,
|
||||
permissions = savedApplication.permissions.map {
|
||||
it.copy()
|
||||
}.toMutableList(),
|
||||
)
|
||||
|
||||
database.applicationDao().delete(intentData.bunkerRequest.secret)
|
||||
database.applicationDao().insertApplicationWithPermissions(tempApp2)
|
||||
}
|
||||
}
|
||||
savedApplication = database.applicationDao().getByKey(key)
|
||||
val relays = savedApplication?.application?.relays?.ifEmpty { defaultRelays } ?: (intentData.bunkerRequest?.relays?.ifEmpty { defaultRelays } ?: defaultRelays)
|
||||
if (intentData.bunkerRequest != null) {
|
||||
NostrSigner.getInstance().checkForNewRelays(
|
||||
|
||||
@@ -270,8 +270,8 @@ fun NewNsecBunkerCreatedScreen(
|
||||
val bunkerUri = "bunker://${account.signer.keyPair.pubKey.toHexKey()}?$relays$localSecret"
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
launch(Dispatchers.IO) {
|
||||
NostrSigner.getInstance().checkForNewRelays()
|
||||
NostrSigner.getInstance().applicationIOScope.launch(Dispatchers.IO) {
|
||||
NostrSigner.getInstance().checkForNewRelays(shouldReconnect = true)
|
||||
NotificationDataSource.stop()
|
||||
delay(2000)
|
||||
NotificationDataSource.start()
|
||||
|
||||
Reference in New Issue
Block a user