Skip to content

Commit

Permalink
Fix app duplicated when connecting to bunker
Browse files Browse the repository at this point in the history
  • Loading branch information
greenart7c3 committed Dec 4, 2024
1 parent 40eb430 commit 82afa2e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
Expand All @@ -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,
)
}
}
Expand All @@ -371,6 +373,7 @@ object IntentUtils {

@OptIn(DelicateCoroutinesApi::class)
private fun sendBunkerResponse(
bunkerRequest: BunkerRequest? = null,
account: Account,
localKey: String,
encryptedContent: String,
Expand All @@ -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(
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 82afa2e

Please sign in to comment.