From 9db126a4283fd18224f2d5d823751018f38a54cf Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Mon, 20 Apr 2026 14:38:07 -0300 Subject: [PATCH 1/2] Optimize performance of batch intent operations in IntentMultiEventHomeScreen - Grouped operations by local account to minimize database opening and data loading. - Added AmberUtils.updatePermission for in-memory permission modifications. - Implemented bulk history insertion in HistoryDao to reduce I/O overhead. - Staged permission updates and performed a single database write per account. - Fixed minor compilation issues and improved overall efficiency for large event batches. --- .../nostrsigner/database/HistoryDao.kt | 25 +- .../nostrsigner/service/AmberUtils.kt | 28 +- .../components/IntentMultiEventHomeScreen.kt | 489 +++++++++--------- 3 files changed, 282 insertions(+), 260 deletions(-) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/database/HistoryDao.kt b/app/src/main/java/com/greenart7c3/nostrsigner/database/HistoryDao.kt index 3bb019f9..e3b89282 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/database/HistoryDao.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/database/HistoryDao.kt @@ -12,6 +12,7 @@ import androidx.room.Query import androidx.room.Transaction import com.greenart7c3.nostrsigner.Amber import com.greenart7c3.nostrsigner.models.Permission +import com.vitorpamplona.quartz.utils.TimeUtils private const val MAX_CONTENT_LENGTH = 500 @@ -65,20 +66,26 @@ interface HistoryDao { @Insert(onConflict = OnConflictStrategy.REPLACE) @Transaction - suspend fun innerAddHistory(entity: HistoryEntity) + suspend fun innerAddHistory(entities: List) @Insert(onConflict = OnConflictStrategy.IGNORE) @Transaction - suspend fun addHistory(entity: HistoryEntity, npub: String?) { + suspend fun addHistory(entities: List, npub: String?) { try { - val permission = Permission(entity.type.toLowerCase(Locale.current), entity.kind) - val localEntity = entity.copy( - translatedPermission = permission.toLocalizedString(Amber.instance, true), - content = if (entity.content.length > MAX_CONTENT_LENGTH) entity.content.take(MAX_CONTENT_LENGTH) else entity.content, - ) - innerAddHistory(localEntity) + val localEntities = entities.map { entity -> + val permission = Permission(entity.type.toLowerCase(Locale.current), entity.kind) + entity.copy( + translatedPermission = permission.toLocalizedString(Amber.instance, true), + content = if (entity.content.length > MAX_CONTENT_LENGTH) entity.content.take(MAX_CONTENT_LENGTH) else entity.content, + ) + } + innerAddHistory(localEntities) npub?.let { - Amber.instance.getDatabase(npub).dao().updateLastUsed(entity.pkKey, entity.time) + val lastUsed = entities.maxByOrNull { it.time }?.time ?: TimeUtils.now() + val pkKey = entities.firstOrNull()?.pkKey + if (pkKey != null) { + Amber.instance.getDatabase(npub).dao().updateLastUsed(pkKey, lastUsed) + } } } catch (e: Exception) { Log.e(Amber.TAG, "Error adding history", e) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/AmberUtils.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/AmberUtils.kt index ce314016..ca640538 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/AmberUtils.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/AmberUtils.kt @@ -77,14 +77,13 @@ object AmberUtils { ) } - suspend fun acceptOrRejectPermission( + fun updatePermission( application: ApplicationWithPermissions, key: String, signerType: SignerType, kind: Int?, value: Boolean, rememberType: RememberType, - account: Account, relay: String = "", encryptedData: EncryptedDataKind?, decryptTypeScope: DecryptTypeScope = DecryptTypeScope.ALL, @@ -141,6 +140,31 @@ object AmberUtils { relay, ), ) + } + + suspend fun acceptOrRejectPermission( + application: ApplicationWithPermissions, + key: String, + signerType: SignerType, + kind: Int?, + value: Boolean, + rememberType: RememberType, + account: Account, + relay: String = "", + encryptedData: EncryptedDataKind?, + decryptTypeScope: DecryptTypeScope = DecryptTypeScope.ALL, + ) { + updatePermission( + application, + key, + signerType, + kind, + value, + rememberType, + relay, + encryptedData, + decryptTypeScope, + ) Amber.instance.getDatabase(account.npub) .dao() diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/IntentMultiEventHomeScreen.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/IntentMultiEventHomeScreen.kt index 04080b2e..b0f08a40 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/IntentMultiEventHomeScreen.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/IntentMultiEventHomeScreen.kt @@ -190,82 +190,85 @@ fun IntentMultiEventHomeScreen( containerColor = orange, ), onClick = { - Amber.instance.applicationIOScope.launch { + Amber.instance.applicationIOScope.launch(Dispatchers.IO) { var closeApp = true onRemoveIntentData(intents, IntentResultType.REMOVE) - for (intentData in intents) { - val thisAccount = - if (intentData.currentAccount.isNotBlank()) { - LocalPreferences.loadFromEncryptedStorage( - context, - intentData.currentAccount, - ) - } else { - accountParam - } ?: continue + val localKey = packageName ?: return@launch + val intentsByAccount = intents.groupBy { it.currentAccount.ifBlank { accountParam.npub } } + + for ((accountNpub, accountIntents) in intentsByAccount) { + val thisAccount = if (accountNpub == accountParam.npub) { + accountParam + } else { + LocalPreferences.loadFromEncryptedStorage(context, accountNpub) + } ?: continue - val localKey = packageName ?: continue val database = Amber.instance.getDatabase(thisAccount.npub) - val application = - database - .dao() - .getByKey(localKey) ?: ApplicationWithPermissions( - application = ApplicationEntity( - localKey, - "", - listOf(), - "", - "", - "", - thisAccount.hexKey, - true, - "", - false, - thisAccount.signPolicy, - true, - 0L, - lastUsed = TimeUtils.now(), - ), - permissions = mutableListOf(), - ) - - val isChecked = MultiEventScreenIntents.checkedStates[intentData.id] ?: true - if (rememberType != RememberType.NEVER && isChecked) { - val rejectKind = if (intentData.type == SignerType.SIGN_EVENT) intentData.event?.kind else null - val rejectRelay = if (intentData.type == SignerType.SIGN_EVENT && intentData.event?.kind == 22242) { - if (relayAuthScope == RelayAuthScope.ALL) { - "*" - } else { - ( - AmberEvent.relay(intentData.event)?.let { url -> - try { - java.net.URI(url).host ?: url - } catch (e: Exception) { - url - } - } ?: "" - ) - } - } else { - "" - } - AmberUtils.acceptOrRejectPermission( - application, + val application = database.dao().getByKey(localKey) ?: ApplicationWithPermissions( + application = ApplicationEntity( localKey, - intentData.type, - rejectKind, + "", + listOf(), + "", + "", + "", + thisAccount.hexKey, + true, + "", false, - rememberType, - thisAccount, - relay = rejectRelay, - encryptedData = intentData.encryptedData, - ) - } + thisAccount.signPolicy, + true, + 0L, + lastUsed = TimeUtils.now(), + ), + permissions = mutableListOf(), + ) if (!application.application.closeApplication) { closeApp = false } + + var permissionsChanged = false + for (intentData in accountIntents) { + val isChecked = MultiEventScreenIntents.checkedStates[intentData.id] ?: true + if (rememberType != RememberType.NEVER && isChecked) { + val rejectKind = if (intentData.type == SignerType.SIGN_EVENT) intentData.event?.kind else null + val rejectRelay = if (intentData.type == SignerType.SIGN_EVENT && intentData.event?.kind == 22242) { + if (relayAuthScope == RelayAuthScope.ALL) { + "*" + } else { + ( + AmberEvent.relay(intentData.event)?.let { url -> + try { + java.net.URI(url).host ?: url + } catch (e: Exception) { + url + } + } ?: "" + ) + } + } else { + "" + } + AmberUtils.updatePermission( + application, + localKey, + intentData.type, + rejectKind, + false, + rememberType, + relay = rejectRelay, + encryptedData = intentData.encryptedData, + ) + permissionsChanged = true + } + } + + if (permissionsChanged || application.application.key.isBlank()) { + database.dao().insertApplicationWithPermissions(application) + } } + sendRejectIntent( results = intents.map { Result( @@ -292,215 +295,203 @@ fun IntentMultiEventHomeScreen( try { val results = mutableListOf() var closeApp = true - onRemoveIntentData(intents, IntentResultType.REMOVE) + val localKey = packageName ?: return@launch + val intentsByAccount = intents.groupBy { it.currentAccount.ifBlank { accountParam.npub } } - for (intentData in intents) { - val thisAccount = - if (intentData.currentAccount.isNotBlank()) { - LocalPreferences.loadFromEncryptedStorage( - context, - intentData.currentAccount, - ) - } else { - accountParam - } ?: continue - - val localKey = packageName ?: continue + for ((accountNpub, accountIntents) in intentsByAccount) { + val thisAccount = if (accountNpub == accountParam.npub) { + accountParam + } else { + LocalPreferences.loadFromEncryptedStorage(context, accountNpub) + } ?: continue val database = Amber.instance.getDatabase(thisAccount.npub) val historyDatabase = Amber.instance.getHistoryDatabase(thisAccount.npub) - val savedApplication = database.dao().getByKey(localKey) - - val application = - savedApplication ?: ApplicationWithPermissions( - application = ApplicationEntity( - localKey, - "", - listOf(), - "", - "", - "", - thisAccount.hexKey, - true, - "", - false, - thisAccount.signPolicy, - true, - 0L, - lastUsed = TimeUtils.now(), - ), - permissions = mutableListOf(), - ) + val application = database.dao().getByKey(localKey) ?: ApplicationWithPermissions( + application = ApplicationEntity( + localKey, + "", + listOf(), + "", + "", + "", + thisAccount.hexKey, + true, + "", + false, + thisAccount.signPolicy, + true, + 0L, + lastUsed = TimeUtils.now(), + ), + permissions = mutableListOf(), + ) if (!application.application.closeApplication) { closeApp = false } - val isChecked = MultiEventScreenIntents.checkedStates[intentData.id] ?: true + var permissionsChanged = false + val historyList = mutableListOf() - if (intentData.type == SignerType.SIGN_EVENT) { - val localEvent = intentData.event!! + for (intentData in accountIntents) { + val isChecked = MultiEventScreenIntents.checkedStates[intentData.id] ?: true + val type = intentData.type - if (rememberType != RememberType.NEVER && isChecked) { - val signRelay = if (localEvent.kind == 22242) { - if (relayAuthScope == RelayAuthScope.ALL) { - "*" + if (type == SignerType.SIGN_EVENT) { + val localEvent = intentData.event!! + + if (rememberType != RememberType.NEVER && isChecked) { + val signRelay = if (localEvent.kind == 22242) { + if (relayAuthScope == RelayAuthScope.ALL) { + "*" + } else { + ( + AmberEvent.relay(localEvent)?.let { url -> + try { + java.net.URI(url).host ?: url + } catch (e: Exception) { + url + } + } ?: "" + ) + } } else { - ( - AmberEvent.relay(localEvent)?.let { url -> - try { - java.net.URI(url).host ?: url - } catch (e: Exception) { - url - } - } ?: "" - ) + "" } - } else { - "" + AmberUtils.updatePermission( + application, + localKey, + type, + localEvent.kind, + true, + rememberType, + relay = signRelay, + encryptedData = intentData.encryptedData, + ) + permissionsChanged = true } - AmberUtils.acceptOrRejectPermission( - application, - localKey, - intentData.type, - localEvent.kind, - true, - rememberType, - thisAccount, - relay = signRelay, - encryptedData = intentData.encryptedData, - ) - } - database.dao().insertApplicationWithPermissions(application) - - historyDatabase.dao().addHistory( - HistoryEntity( - 0, - localKey, - intentData.type.toString(), - localEvent.kind, - TimeUtils.now(), - isChecked, - content = localEvent.toJson(), - ), - thisAccount.npub, - ) - - if (isChecked) { - results.add( - Result( - null, - signature = if (localEvent is LnZapRequestEvent && - localEvent.tags.any { tag -> - tag.any { t -> t == "anon" } - } - ) { - localEvent.toJson() - } else { - localEvent.sig - }, - result = if (localEvent is LnZapRequestEvent && - localEvent.tags.any { tag -> - tag.any { t -> t == "anon" } - } - ) { - localEvent.toJson() - } else { - localEvent.sig - }, - id = intentData.id, - rejected = null, + historyList.add( + HistoryEntity( + 0, + localKey, + type.toString(), + localEvent.kind, + TimeUtils.now(), + isChecked, + content = localEvent.toJson(), ), ) - } - } else if (intentData.type == SignerType.SIGN_MESSAGE) { - if (rememberType != RememberType.NEVER && isChecked) { - AmberUtils.acceptOrRejectPermission( - application, - localKey, - intentData.type, - null, - true, - rememberType, - thisAccount, - encryptedData = intentData.encryptedData, - ) - } - database.dao().insertApplicationWithPermissions(application) - historyDatabase.dao().addHistory( - HistoryEntity( - 0, - localKey, - intentData.type.toString(), - null, - TimeUtils.now(), - isChecked, - content = intentData.data, - ), - thisAccount.npub, - ) - - val signedMessage = thisAccount.signString(intentData.data) - if (isChecked) { - results.add( - Result( - null, - signature = signedMessage, - result = signedMessage, - id = intentData.id, - rejected = null, - ), - ) - } - } else { - if (rememberType != RememberType.NEVER && isChecked) { - AmberUtils.acceptOrRejectPermission( - application, - localKey, - intentData.type, - null, - true, - rememberType, - thisAccount, - encryptedData = intentData.encryptedData, - ) - } - - database.dao().insertApplicationWithPermissions(application) - - historyDatabase.dao().addHistory( - HistoryEntity( - 0, - localKey, - intentData.type.toString(), - null, - TimeUtils.now(), - isChecked, - content = if (intentData.type == SignerType.NIP04_DECRYPT || intentData.type == SignerType.NIP44_DECRYPT || intentData.type == SignerType.DECRYPT_ZAP_EVENT) { - intentData.encryptedData?.result ?: "" + if (isChecked) { + val signature = if (localEvent is LnZapRequestEvent && + localEvent.tags.any { tag -> + tag.any { t -> t == "anon" } + } + ) { + localEvent.toJson() } else { - intentData.data - }, - ), - thisAccount.npub, - ) - - val signature = intentData.encryptedData?.result ?: continue - if (isChecked) { - results.add( - Result( + localEvent.sig + } + results.add( + Result( + null, + signature = signature, + result = signature, + id = intentData.id, + rejected = null, + ), + ) + } + } else if (type == SignerType.SIGN_MESSAGE) { + if (rememberType != RememberType.NEVER && isChecked) { + AmberUtils.updatePermission( + application, + localKey, + type, null, - signature = signature, - result = signature, - id = intentData.id, - rejected = null, + true, + rememberType, + encryptedData = intentData.encryptedData, + ) + permissionsChanged = true + } + + historyList.add( + HistoryEntity( + 0, + localKey, + type.toString(), + null, + TimeUtils.now(), + isChecked, + content = intentData.data, ), ) + + val signedMessage = thisAccount.signString(intentData.data) + if (isChecked) { + results.add( + Result( + null, + signature = signedMessage, + result = signedMessage, + id = intentData.id, + rejected = null, + ), + ) + } + } else { + if (rememberType != RememberType.NEVER && isChecked) { + AmberUtils.updatePermission( + application, + localKey, + type, + null, + true, + rememberType, + encryptedData = intentData.encryptedData, + ) + permissionsChanged = true + } + + historyList.add( + HistoryEntity( + 0, + localKey, + type.toString(), + null, + TimeUtils.now(), + isChecked, + content = if (type == SignerType.NIP04_DECRYPT || type == SignerType.NIP44_DECRYPT || type == SignerType.DECRYPT_ZAP_EVENT) { + intentData.encryptedData?.result ?: "" + } else { + intentData.data + }, + ), + ) + + val signature = intentData.encryptedData?.result + if (isChecked && signature != null) { + results.add( + Result( + null, + signature = signature, + result = signature, + id = intentData.id, + rejected = null, + ), + ) + } } } + + if (permissionsChanged || application.application.key.isBlank()) { + database.dao().insertApplicationWithPermissions(application) + } + historyDatabase.dao().addHistory(historyList, thisAccount.npub) } if (results.isNotEmpty()) { From 9ae222dd6568f7bd6a43db6d96e3785ade8a4c25 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Mon, 20 Apr 2026 14:45:07 -0300 Subject: [PATCH 2/2] Refactor history logging to use list-based insertion Update `HistoryDao.addHistory` calls across the application to pass a list of `HistoryEntity` objects instead of single entities. This change ensures consistency with the underlying database DAO and allows for more efficient batch insertions in the future. Affected areas include: - `SignerProvider`: ContentProvider-based signing, encryption, and decryption requests. - `IntentUtils`: Signing and permission requests handled via Android Intents. - `EventNotificationConsumer`: NIP-46 remote signer requests. - `BunkerMultiEventHomeScreen`: Multi-event approvals in the UI. - `BunkerRequestUtils`: Background processing of bunker requests. --- .../greenart7c3/nostrsigner/SignerProvider.kt | 158 ++++++++++-------- .../nostrsigner/service/BunkerRequestUtils.kt | 50 +++--- .../service/EventNotificationConsumer.kt | 50 +++--- .../nostrsigner/service/IntentUtils.kt | 50 +++--- .../components/BunkerMultiEventHomeScreen.kt | 80 +++++---- 5 files changed, 214 insertions(+), 174 deletions(-) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/SignerProvider.kt b/app/src/main/java/com/greenart7c3/nostrsigner/SignerProvider.kt index 8b0a9e96..88b07cd6 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/SignerProvider.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/SignerProvider.kt @@ -98,14 +98,16 @@ class SignerProvider : ContentProvider() { if (!isRemembered) { scope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - packageName, - uriString.replace("content://$appId.", ""), - null, - TimeUtils.now(), - false, - content = message, + listOf( + HistoryEntity( + 0, + packageName, + uriString.replace("content://$appId.", ""), + null, + TimeUtils.now(), + false, + content = message, + ), ), account.npub, ) @@ -121,14 +123,16 @@ class SignerProvider : ContentProvider() { val result = runBlocking { account.signString(message) } scope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - packageName, - "SIGN_MESSAGE", - null, - TimeUtils.now(), - true, - content = message, + listOf( + HistoryEntity( + 0, + packageName, + "SIGN_MESSAGE", + null, + TimeUtils.now(), + true, + content = message, + ), ), account.npub, ) @@ -187,14 +191,16 @@ class SignerProvider : ContentProvider() { else -> { scope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - packageName, - uriString.replace("content://$appId.", ""), - event.kind, - TimeUtils.now(), - false, - content = event.toJson(), + listOf( + HistoryEntity( + 0, + packageName, + uriString.replace("content://$appId.", ""), + event.kind, + TimeUtils.now(), + false, + content = event.toJson(), + ), ), account.npub, ) @@ -240,14 +246,16 @@ class SignerProvider : ContentProvider() { if (!isRemembered) { scope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - packageName, - uriString.replace("content://$appId.", ""), - event.kind, - TimeUtils.now(), - false, - content = event.toJson(), + listOf( + HistoryEntity( + 0, + packageName, + uriString.replace("content://$appId.", ""), + event.kind, + TimeUtils.now(), + false, + content = event.toJson(), + ), ), account.npub, ) @@ -265,14 +273,16 @@ class SignerProvider : ContentProvider() { scope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - packageName, - "SIGN_EVENT", - event.kind, - TimeUtils.now(), - true, - content = signedEvent.toJson(), + listOf( + HistoryEntity( + 0, + packageName, + "SIGN_EVENT", + event.kind, + TimeUtils.now(), + true, + content = signedEvent.toJson(), + ), ), account.npub, ) @@ -387,14 +397,16 @@ class SignerProvider : ContentProvider() { if (!isRemembered) { scope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - packageName, - uriString.replace("content://$appId.", ""), - null, - TimeUtils.now(), - false, - content = content, + listOf( + HistoryEntity( + 0, + packageName, + uriString.replace("content://$appId.", ""), + null, + TimeUtils.now(), + false, + content = content, + ), ), account.npub, ) @@ -436,14 +448,16 @@ class SignerProvider : ContentProvider() { scope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - packageName, - uriString.replace("content://$appId.", ""), - null, - TimeUtils.now(), - true, - content = if (!isEncrypt) finalResult else content, + listOf( + HistoryEntity( + 0, + packageName, + uriString.replace("content://$appId.", ""), + null, + TimeUtils.now(), + true, + content = if (!isEncrypt) finalResult else content, + ), ), account.npub, ) @@ -487,13 +501,15 @@ class SignerProvider : ContentProvider() { if (!isRemembered) { scope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - packageName, - uriString.replace("content://$appId.", ""), - null, - TimeUtils.now(), - false, + listOf( + HistoryEntity( + 0, + packageName, + uriString.replace("content://$appId.", ""), + null, + TimeUtils.now(), + false, + ), ), account.npub, ) @@ -509,13 +525,15 @@ class SignerProvider : ContentProvider() { scope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - packageName, - uriString.replace("content://$appId.", ""), - null, - TimeUtils.now(), - true, + listOf( + HistoryEntity( + 0, + packageName, + uriString.replace("content://$appId.", ""), + null, + TimeUtils.now(), + true, + ), ), account.npub, ) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/BunkerRequestUtils.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/BunkerRequestUtils.kt index b4c61a94..0744ec26 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/BunkerRequestUtils.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/BunkerRequestUtils.kt @@ -391,21 +391,23 @@ object BunkerRequestUtils { EventNotificationConsumer(context).notificationManager().cancelAll() database.dao().insertApplicationWithPermissions(application) historyDatabase.dao().addHistory( - HistoryEntity( - 0, - key, - type.toString(), - kind, - TimeUtils.now(), - true, - content = when (type) { - SignerType.SIGN_EVENT, - SignerType.NIP04_DECRYPT, - SignerType.NIP44_DECRYPT, - SignerType.DECRYPT_ZAP_EVENT, - -> response - else -> getDataFromBunker(bunkerRequest.request) - }, + listOf( + HistoryEntity( + 0, + key, + type.toString(), + kind, + TimeUtils.now(), + true, + content = when (type) { + SignerType.SIGN_EVENT, + SignerType.NIP04_DECRYPT, + SignerType.NIP44_DECRYPT, + SignerType.DECRYPT_ZAP_EVENT, + -> response + else -> getDataFromBunker(bunkerRequest.request) + }, + ), ), account.npub, ) @@ -539,14 +541,16 @@ object BunkerRequestUtils { if (bunkerRequest.request !is BunkerRequestConnect) { Amber.instance.getDatabase(account.npub).dao().insertApplicationWithPermissions(application) Amber.instance.getHistoryDatabase(account.npub).dao().addHistory( - HistoryEntity( - 0, - key, - signerType.toString(), - null, - TimeUtils.now(), - false, - content = getDataFromBunker(bunkerRequest.request), + listOf( + HistoryEntity( + 0, + key, + signerType.toString(), + null, + TimeUtils.now(), + false, + content = getDataFromBunker(bunkerRequest.request), + ), ), account.npub, ) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/EventNotificationConsumer.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/EventNotificationConsumer.kt index 2e899a99..825b6101 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/EventNotificationConsumer.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/EventNotificationConsumer.kt @@ -277,14 +277,16 @@ class EventNotificationConsumer(private val applicationContext: Context) { Amber.instance.applicationIOScope.launch { historyDao .addHistory( - HistoryEntity( - 0, - permission.application.key, - type.toString().toLowerCase(Locale.current), - amberEvent?.kind, - TimeUtils.now(), - true, - content = amberEvent?.content ?: "", + listOf( + HistoryEntity( + 0, + permission.application.key, + type.toString().toLowerCase(Locale.current), + amberEvent?.kind, + TimeUtils.now(), + true, + content = amberEvent?.content ?: "", + ), ), acc.npub, ) @@ -409,13 +411,15 @@ class EventNotificationConsumer(private val applicationContext: Context) { if (!isRemembered) { Amber.instance.applicationIOScope.launch { historyDao.addHistory( - HistoryEntity( - 0, - event.pubKey, - "GET_PUBLIC_KEY", - null, - TimeUtils.now(), - false, + listOf( + HistoryEntity( + 0, + event.pubKey, + "GET_PUBLIC_KEY", + null, + TimeUtils.now(), + false, + ), ), acc.npub, ) @@ -433,13 +437,15 @@ class EventNotificationConsumer(private val applicationContext: Context) { } Amber.instance.applicationIOScope.launch { historyDao.addHistory( - HistoryEntity( - 0, - event.pubKey, - "GET_PUBLIC_KEY", - null, - TimeUtils.now(), - true, + listOf( + HistoryEntity( + 0, + event.pubKey, + "GET_PUBLIC_KEY", + null, + TimeUtils.now(), + true, + ), ), acc.npub, ) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt index 82b5d438..6daf2ee7 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/IntentUtils.kt @@ -754,22 +754,24 @@ object IntentUtils { val historyDatabase = Amber.instance.getHistoryDatabase(account.npub) Amber.instance.applicationIOScope.launch { historyDatabase.dao().addHistory( - HistoryEntity( - 0, - key, - intentData.type.toString(), - kind, - TimeUtils.now(), - true, - content = when (intentData.type) { - SignerType.SIGN_EVENT -> event - SignerType.NIP04_DECRYPT, - SignerType.NIP44_DECRYPT, - SignerType.DECRYPT_ZAP_EVENT, - -> value + listOf( + HistoryEntity( + 0, + key, + intentData.type.toString(), + kind, + TimeUtils.now(), + true, + content = when (intentData.type) { + SignerType.SIGN_EVENT -> event + SignerType.NIP04_DECRYPT, + SignerType.NIP44_DECRYPT, + SignerType.DECRYPT_ZAP_EVENT, + -> value - else -> intentData.data - }, + else -> intentData.data + }, + ), ), account.npub, ) @@ -903,14 +905,16 @@ object IntentUtils { Amber.instance.getDatabase(account.npub).dao().insertApplicationWithPermissions(application) Amber.instance.getHistoryDatabase(account.npub).dao().addHistory( - HistoryEntity( - 0, - key, - intentData.type.toString(), - kind, - TimeUtils.now(), - false, - content = intentData.data, + listOf( + HistoryEntity( + 0, + key, + intentData.type.toString(), + kind, + TimeUtils.now(), + false, + content = intentData.data, + ), ), account.npub, ) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/BunkerMultiEventHomeScreen.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/BunkerMultiEventHomeScreen.kt index a2e348d8..2ee4b85b 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/BunkerMultiEventHomeScreen.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/BunkerMultiEventHomeScreen.kt @@ -398,14 +398,16 @@ fun BunkerMultiEventHomeScreen( database.dao().insertApplicationWithPermissions(application) historyDatabase.dao().addHistory( - entity = HistoryEntity( - id = 0, - pkKey = localKey, - type = SignerType.SIGN_EVENT.toString(), - kind = localEvent.kind, - time = TimeUtils.now(), - accepted = isChecked, - content = localEvent.toJson(), + listOf( + HistoryEntity( + id = 0, + pkKey = localKey, + type = SignerType.SIGN_EVENT.toString(), + kind = localEvent.kind, + time = TimeUtils.now(), + accepted = isChecked, + content = localEvent.toJson(), + ), ), thisAccount.npub, ) @@ -448,14 +450,16 @@ fun BunkerMultiEventHomeScreen( database.dao().insertApplicationWithPermissions(application) historyDatabase.dao().addHistory( - HistoryEntity( - 0, - localKey, - SignerType.SIGN_MESSAGE.toString(), - null, - TimeUtils.now(), - isChecked, - content = request.request.params.first(), + listOf( + HistoryEntity( + 0, + localKey, + SignerType.SIGN_MESSAGE.toString(), + null, + TimeUtils.now(), + isChecked, + content = request.request.params.first(), + ), ), thisAccount.npub, ) @@ -488,14 +492,16 @@ fun BunkerMultiEventHomeScreen( database.dao().insertApplicationWithPermissions(application) historyDatabase.dao().addHistory( - HistoryEntity( - 0, - localKey, - SignerType.CONNECT.toString(), - null, - TimeUtils.now(), - isChecked, - content = "", + listOf( + HistoryEntity( + 0, + localKey, + SignerType.CONNECT.toString(), + null, + TimeUtils.now(), + isChecked, + content = "", + ), ), thisAccount.npub, ) @@ -540,18 +546,20 @@ fun BunkerMultiEventHomeScreen( database.dao().insertApplicationWithPermissions(application) historyDatabase.dao().addHistory( - HistoryEntity( - 0, - localKey, - type.toString(), - null, - TimeUtils.now(), - isChecked, - content = if (type == SignerType.NIP04_DECRYPT || type == SignerType.NIP44_DECRYPT || type == SignerType.DECRYPT_ZAP_EVENT) { - request.encryptedData?.result ?: "" - } else { - request.request.params.getOrElse(1) { "" } - }, + listOf( + HistoryEntity( + 0, + localKey, + type.toString(), + null, + TimeUtils.now(), + isChecked, + content = if (type == SignerType.NIP04_DECRYPT || type == SignerType.NIP44_DECRYPT || type == SignerType.DECRYPT_ZAP_EVENT) { + request.encryptedData?.result ?: "" + } else { + request.request.params.getOrElse(1) { "" } + }, + ), ), thisAccount.npub, )