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.
This commit is contained in:
greenart7c3
2026-04-20 14:45:07 -03:00
parent 9db126a428
commit 9ae222dd65
5 changed files with 214 additions and 174 deletions
@@ -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,
)
@@ -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,
)
@@ -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,
)
@@ -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,
)
@@ -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,
)