Fix connected applications

This commit is contained in:
greenart7c3
2024-12-25 21:32:26 -03:00
parent b3e5adb976
commit 40c51e5f82
2 changed files with 13 additions and 1 deletions
@@ -40,6 +40,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class NostrSigner : Application() {
@@ -87,6 +88,14 @@ class NostrSigner : Application() {
LocalPreferences.allSavedAccounts(this).forEach {
databases[it.npub] = AppDatabase.getDatabase(this, it.npub)
applicationIOScope.launch {
databases[it.npub]?.applicationDao()?.getAllNotConnected()?.forEach { app ->
if (app.application.secret.isNotEmpty() && app.application.secret != app.application.key) {
app.application.isConnected = true
databases[it.npub]?.applicationDao()?.insertApplicationWithPermissions(app)
}
}
}
}
runBlocking {
@@ -26,6 +26,9 @@ interface ApplicationDao {
@Query("SELECT * FROM application where pubKey = :pubKey order by name")
fun getAll(pubKey: String): List<ApplicationEntity>
@Query("SELECT * FROM application where isConnected = 0")
fun getAllNotConnected(): List<ApplicationWithPermissions>
@Query(
"""
SELECT a.*, MAX(h.time) as latestTime
@@ -66,7 +69,7 @@ interface ApplicationDao {
type: String,
): ApplicationPermissionsEntity?
@Insert(onConflict = OnConflictStrategy.IGNORE)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertApplication(event: ApplicationEntity): Long?
@Query("UPDATE application SET name = :name WHERE `key` = :key")