mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
Fix remember my choice when rejecting
This commit is contained in:
@@ -63,7 +63,7 @@ interface ApplicationDao {
|
||||
name: String,
|
||||
)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
@Transaction
|
||||
fun insertPermissions(permissions: List<ApplicationPermissionsEntity>): List<Long>? {
|
||||
permissions.forEach {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.greenart7c3.nostrsigner.service
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.greenart7c3.nostrsigner.database.AppDatabase
|
||||
import com.greenart7c3.nostrsigner.database.ApplicationEntity
|
||||
import com.greenart7c3.nostrsigner.database.ApplicationPermissionsEntity
|
||||
import com.greenart7c3.nostrsigner.database.ApplicationWithPermissions
|
||||
import com.greenart7c3.nostrsigner.models.Account
|
||||
@@ -143,34 +142,13 @@ object AmberUtils {
|
||||
}
|
||||
|
||||
fun acceptOrRejectPermission(
|
||||
application: ApplicationWithPermissions,
|
||||
key: String,
|
||||
intentData: IntentData,
|
||||
kind: Int?,
|
||||
value: Boolean,
|
||||
appName: String,
|
||||
account: Account,
|
||||
database: AppDatabase,
|
||||
) {
|
||||
val application =
|
||||
database
|
||||
.applicationDao()
|
||||
.getByKey(key) ?: ApplicationWithPermissions(
|
||||
application = ApplicationEntity(
|
||||
key,
|
||||
appName,
|
||||
listOf(),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
account.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
account.signPolicy,
|
||||
),
|
||||
permissions = mutableListOf(),
|
||||
)
|
||||
|
||||
val noPermission = application.permissions.none {
|
||||
val nip = it.kind?.kindToNip()?.toIntOrNull()
|
||||
(it.type == intentData.type.toString() && it.kind == kind) || (nip != null && it.type == "NIP" && it.kind == nip)
|
||||
|
||||
+25
-71
@@ -380,43 +380,40 @@ fun MultiEventHomeScreen(
|
||||
|
||||
val database = NostrSigner.getInstance().getDatabase(localAccount.keyPair.pubKey.toNpub())
|
||||
|
||||
val applicationEntity = database.applicationDao().getByKey(key)
|
||||
val application =
|
||||
database
|
||||
.applicationDao()
|
||||
.getByKey(key) ?: ApplicationWithPermissions(
|
||||
application = ApplicationEntity(
|
||||
key,
|
||||
"",
|
||||
listOf(),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
localAccount.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
localAccount.signPolicy,
|
||||
),
|
||||
permissions = mutableListOf(),
|
||||
)
|
||||
|
||||
if (intentData.type == SignerType.SIGN_EVENT) {
|
||||
val localEvent = intentData.event!!
|
||||
|
||||
if (intentData.rememberMyChoice.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
key,
|
||||
intentData,
|
||||
localEvent.kind,
|
||||
intentData.rememberMyChoice.value,
|
||||
applicationEntity?.application?.name?.ifBlank { applicationEntity.application.key.toShortenHex() } ?: "",
|
||||
localAccount,
|
||||
database,
|
||||
)
|
||||
}
|
||||
|
||||
val application =
|
||||
database
|
||||
.applicationDao()
|
||||
.getByKey(key) ?: ApplicationWithPermissions(
|
||||
application = ApplicationEntity(
|
||||
key,
|
||||
applicationEntity?.application?.name?.ifBlank { applicationEntity.application.key.toShortenHex() } ?: "",
|
||||
listOf(),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
localAccount.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
localAccount.signPolicy,
|
||||
),
|
||||
permissions = mutableListOf(),
|
||||
)
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
|
||||
database.applicationDao().addHistory(
|
||||
@@ -436,7 +433,7 @@ fun MultiEventHomeScreen(
|
||||
localAccount,
|
||||
intentData.bunkerRequest,
|
||||
BunkerResponse(intentData.bunkerRequest.id, localEvent.toJson(), null),
|
||||
applicationEntity?.application?.relays ?: emptyList(),
|
||||
application.application.relays,
|
||||
onLoading = {},
|
||||
onDone = {},
|
||||
)
|
||||
@@ -471,38 +468,16 @@ fun MultiEventHomeScreen(
|
||||
} else if (intentData.type == SignerType.SIGN_MESSAGE) {
|
||||
if (intentData.rememberMyChoice.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
key,
|
||||
intentData,
|
||||
null,
|
||||
intentData.rememberMyChoice.value,
|
||||
applicationEntity?.application?.name?.ifBlank { applicationEntity.application.key.toShortenHex() } ?: "",
|
||||
localAccount,
|
||||
database,
|
||||
)
|
||||
}
|
||||
|
||||
val application =
|
||||
database
|
||||
.applicationDao()
|
||||
.getByKey(key) ?: ApplicationWithPermissions(
|
||||
application = ApplicationEntity(
|
||||
key,
|
||||
applicationEntity?.application?.name?.ifBlank { applicationEntity.application.key.toShortenHex() } ?: "",
|
||||
listOf(),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
localAccount.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
localAccount.signPolicy,
|
||||
),
|
||||
permissions = mutableListOf(),
|
||||
)
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
|
||||
database.applicationDao().addHistory(
|
||||
HistoryEntity(
|
||||
0,
|
||||
@@ -522,7 +497,7 @@ fun MultiEventHomeScreen(
|
||||
localAccount,
|
||||
intentData.bunkerRequest,
|
||||
BunkerResponse(intentData.bunkerRequest.id, signedMessage, null),
|
||||
applicationEntity?.application?.relays ?: emptyList(),
|
||||
application.application.relays,
|
||||
onLoading = {},
|
||||
onDone = {},
|
||||
)
|
||||
@@ -539,36 +514,15 @@ fun MultiEventHomeScreen(
|
||||
} else {
|
||||
if (intentData.rememberMyChoice.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
key,
|
||||
intentData,
|
||||
null,
|
||||
intentData.rememberMyChoice.value,
|
||||
applicationEntity?.application?.name?.ifBlank { applicationEntity.application.key.toShortenHex() } ?: "",
|
||||
localAccount,
|
||||
database,
|
||||
)
|
||||
}
|
||||
|
||||
val application =
|
||||
database
|
||||
.applicationDao()
|
||||
.getByKey(key) ?: ApplicationWithPermissions(
|
||||
application = ApplicationEntity(
|
||||
key,
|
||||
applicationEntity?.application?.name?.ifBlank { applicationEntity.application.key.toShortenHex() } ?: "",
|
||||
listOf(),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
localAccount.keyPair.pubKey.toHexKey(),
|
||||
true,
|
||||
intentData.bunkerRequest?.secret ?: "",
|
||||
intentData.bunkerRequest?.secret != null,
|
||||
localAccount.signPolicy,
|
||||
),
|
||||
permissions = mutableListOf(),
|
||||
)
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
|
||||
database.applicationDao().addHistory(
|
||||
@@ -590,7 +544,7 @@ fun MultiEventHomeScreen(
|
||||
localAccount,
|
||||
intentData.bunkerRequest,
|
||||
BunkerResponse(intentData.bunkerRequest.id, signature, null),
|
||||
applicationEntity?.application?.relays ?: emptyList(),
|
||||
application.application.relays,
|
||||
onLoading = {},
|
||||
onDone = {},
|
||||
)
|
||||
|
||||
+54
-55
@@ -208,27 +208,9 @@ fun SingleEventHomeScreen(
|
||||
return@launch
|
||||
}
|
||||
|
||||
if (remember.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
key,
|
||||
intentData,
|
||||
null,
|
||||
false,
|
||||
applicationName ?: appName,
|
||||
account,
|
||||
database,
|
||||
)
|
||||
}
|
||||
|
||||
val defaultRelays = NostrSigner.getInstance().settings.defaultRelays
|
||||
val savedApplication = database.applicationDao().getByKey(key)
|
||||
val defaultRelays = NostrSigner.getInstance().settings.defaultRelays
|
||||
val relays = savedApplication?.application?.relays?.ifEmpty { defaultRelays } ?: (intentData.bunkerRequest?.relays?.ifEmpty { defaultRelays } ?: defaultRelays)
|
||||
if (intentData.bunkerRequest != null) {
|
||||
NostrSigner.getInstance().checkForNewRelays(
|
||||
NostrSigner.getInstance().settings.notificationType != NotificationType.DIRECT,
|
||||
relays.toSet(),
|
||||
)
|
||||
}
|
||||
val application =
|
||||
savedApplication ?: ApplicationWithPermissions(
|
||||
application = ApplicationEntity(
|
||||
@@ -247,6 +229,24 @@ fun SingleEventHomeScreen(
|
||||
permissions = mutableListOf(),
|
||||
)
|
||||
|
||||
if (remember.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
key,
|
||||
intentData,
|
||||
null,
|
||||
false,
|
||||
database,
|
||||
)
|
||||
}
|
||||
|
||||
if (intentData.bunkerRequest != null) {
|
||||
NostrSigner.getInstance().checkForNewRelays(
|
||||
NostrSigner.getInstance().settings.notificationType != NotificationType.DIRECT,
|
||||
relays.toSet(),
|
||||
)
|
||||
}
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
|
||||
database.applicationDao().addHistory(
|
||||
@@ -345,27 +345,9 @@ fun SingleEventHomeScreen(
|
||||
return@launch
|
||||
}
|
||||
|
||||
if (remember.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
key,
|
||||
intentData,
|
||||
null,
|
||||
false,
|
||||
applicationName ?: appName,
|
||||
account,
|
||||
database,
|
||||
)
|
||||
}
|
||||
val defaultRelays = NostrSigner.getInstance().settings.defaultRelays
|
||||
val 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(
|
||||
NostrSigner.getInstance().settings.notificationType != NotificationType.DIRECT,
|
||||
relays.toSet(),
|
||||
)
|
||||
}
|
||||
|
||||
val application =
|
||||
savedApplication ?: ApplicationWithPermissions(
|
||||
application = ApplicationEntity(
|
||||
@@ -383,6 +365,23 @@ fun SingleEventHomeScreen(
|
||||
),
|
||||
permissions = mutableListOf(),
|
||||
)
|
||||
if (remember.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
key,
|
||||
intentData,
|
||||
null,
|
||||
false,
|
||||
database,
|
||||
)
|
||||
}
|
||||
|
||||
if (intentData.bunkerRequest != null) {
|
||||
NostrSigner.getInstance().checkForNewRelays(
|
||||
NostrSigner.getInstance().settings.notificationType != NotificationType.DIRECT,
|
||||
relays.toSet(),
|
||||
)
|
||||
}
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
|
||||
@@ -508,24 +507,6 @@ fun SingleEventHomeScreen(
|
||||
val defaultRelays = NostrSigner.getInstance().settings.defaultRelays
|
||||
val 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(
|
||||
NostrSigner.getInstance().settings.notificationType != NotificationType.DIRECT,
|
||||
relays.toSet(),
|
||||
)
|
||||
}
|
||||
|
||||
if (remember.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
key,
|
||||
intentData,
|
||||
event.kind,
|
||||
false,
|
||||
applicationName ?: appName,
|
||||
account,
|
||||
database,
|
||||
)
|
||||
}
|
||||
|
||||
val application =
|
||||
savedApplication ?: ApplicationWithPermissions(
|
||||
@@ -545,6 +526,24 @@ fun SingleEventHomeScreen(
|
||||
permissions = mutableListOf(),
|
||||
)
|
||||
|
||||
if (intentData.bunkerRequest != null) {
|
||||
NostrSigner.getInstance().checkForNewRelays(
|
||||
NostrSigner.getInstance().settings.notificationType != NotificationType.DIRECT,
|
||||
relays.toSet(),
|
||||
)
|
||||
}
|
||||
|
||||
if (remember.value) {
|
||||
AmberUtils.acceptOrRejectPermission(
|
||||
application,
|
||||
key,
|
||||
intentData,
|
||||
event.kind,
|
||||
false,
|
||||
database,
|
||||
)
|
||||
}
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
|
||||
database.applicationDao().addHistory(
|
||||
|
||||
Reference in New Issue
Block a user