mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 03:18:23 +00:00
Refactor: Rename DAO accessors
Renames `applicationDao()` to `dao()` in `AppDatabase` and `logDao()` to `dao()` in `LogDatabase` for consistency and simplicity. Updates all call sites to reflect the new method names.
This commit is contained in:
@@ -212,10 +212,10 @@ class Amber : Application(), LifecycleObserver {
|
||||
LocalPreferences.allSavedAccounts(this).forEach {
|
||||
databases[it.npub] = getDatabase(it.npub)
|
||||
applicationIOScope.launch {
|
||||
databases[it.npub]?.applicationDao()?.getAllNotConnected()?.forEach { app ->
|
||||
databases[it.npub]?.dao()?.getAllNotConnected()?.forEach { app ->
|
||||
if (app.application.secret.isNotEmpty() && app.application.secret != app.application.key) {
|
||||
app.application.isConnected = true
|
||||
databases[it.npub]?.applicationDao()?.insertApplicationWithPermissions(app)
|
||||
databases[it.npub]?.dao()?.insertApplicationWithPermissions(app)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -307,7 +307,7 @@ class Amber : Application(), LifecycleObserver {
|
||||
|
||||
suspend fun fixRejectedPermissions() {
|
||||
LocalPreferences.allSavedAccounts(this).forEach { account ->
|
||||
val permissions = getDatabase(account.npub).applicationDao().getAllRejectedPermissions()
|
||||
val permissions = getDatabase(account.npub).dao().getAllRejectedPermissions()
|
||||
val localPermissions =
|
||||
permissions.map {
|
||||
val isAcceptable = it.acceptable
|
||||
@@ -321,13 +321,13 @@ class Amber : Application(), LifecycleObserver {
|
||||
rememberType = RememberType.ALWAYS.screenCode,
|
||||
)
|
||||
}
|
||||
getDatabase(account.npub).applicationDao().insertPermissions(localPermissions)
|
||||
getDatabase(account.npub).dao().insertPermissions(localPermissions)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun fixAcceptedPermissions() {
|
||||
LocalPreferences.allSavedAccounts(this).forEach { account ->
|
||||
val permissions = getDatabase(account.npub).applicationDao().getAllAcceptedPermissions()
|
||||
val permissions = getDatabase(account.npub).dao().getAllAcceptedPermissions()
|
||||
Log.d(TAG, "Found ${permissions.size} accepted permissions")
|
||||
val localPermissions =
|
||||
permissions.map {
|
||||
@@ -342,7 +342,7 @@ class Amber : Application(), LifecycleObserver {
|
||||
rememberType = RememberType.ALWAYS.screenCode,
|
||||
)
|
||||
}
|
||||
getDatabase(account.npub).applicationDao().insertPermissions(localPermissions)
|
||||
getDatabase(account.npub).dao().insertPermissions(localPermissions)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ class Amber : Application(), LifecycleObserver {
|
||||
val savedRelays = mutableSetOf<NormalizedRelayUrl>()
|
||||
LocalPreferences.allSavedAccounts(this).forEach { accountInfo ->
|
||||
val database = getDatabase(accountInfo.npub)
|
||||
database.applicationDao().getAllApplications().forEach {
|
||||
database.dao().getAllApplications().forEach {
|
||||
it.application.relays.forEach { setupInfo ->
|
||||
savedRelays.add(setupInfo)
|
||||
}
|
||||
|
||||
@@ -102,12 +102,12 @@ class SignerProvider : ContentProvider() {
|
||||
val historyDatabase = Amber.instance.getHistoryDatabase(account.npub)
|
||||
val permission =
|
||||
database
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.getPermission(
|
||||
packageName,
|
||||
"SIGN_MESSAGE",
|
||||
)
|
||||
val signPolicy = database.applicationDao().getSignPolicy(packageName)
|
||||
val signPolicy = database.dao().getSignPolicy(packageName)
|
||||
val isRemembered = IntentUtils.isRemembered(signPolicy, permission)
|
||||
if (isRemembered == null) {
|
||||
return null
|
||||
@@ -186,7 +186,7 @@ class SignerProvider : ContentProvider() {
|
||||
val historyDatabase = Amber.instance.getHistoryDatabase(account.npub)
|
||||
var permission =
|
||||
database
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.getPermission(
|
||||
packageName,
|
||||
"SIGN_EVENT",
|
||||
@@ -199,7 +199,7 @@ class SignerProvider : ContentProvider() {
|
||||
null
|
||||
} else {
|
||||
database
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.getPermission(
|
||||
packageName,
|
||||
"NIP",
|
||||
@@ -208,7 +208,7 @@ class SignerProvider : ContentProvider() {
|
||||
}
|
||||
}
|
||||
}
|
||||
val signPolicy = database.applicationDao().getSignPolicy(packageName)
|
||||
val signPolicy = database.dao().getSignPolicy(packageName)
|
||||
val isRemembered = IntentUtils.isRemembered(signPolicy, permission)
|
||||
if (isRemembered == null) {
|
||||
return null
|
||||
@@ -287,7 +287,7 @@ class SignerProvider : ContentProvider() {
|
||||
val historyDatabase = Amber.instance.getHistoryDatabase(account.npub)
|
||||
var permission =
|
||||
database
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.getPermission(
|
||||
packageName,
|
||||
uri.toString().replace("content://$appId.", ""),
|
||||
@@ -304,7 +304,7 @@ class SignerProvider : ContentProvider() {
|
||||
nip?.let {
|
||||
permission =
|
||||
database
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.getPermission(
|
||||
packageName,
|
||||
"NIP",
|
||||
@@ -312,7 +312,7 @@ class SignerProvider : ContentProvider() {
|
||||
)
|
||||
}
|
||||
}
|
||||
val signPolicy = database.applicationDao().getSignPolicy(packageName)
|
||||
val signPolicy = database.dao().getSignPolicy(packageName)
|
||||
val isRemembered = IntentUtils.isRemembered(signPolicy, permission)
|
||||
if (isRemembered == null) {
|
||||
return null
|
||||
@@ -360,7 +360,7 @@ class SignerProvider : ContentProvider() {
|
||||
) ?: "Could not decrypt the message"
|
||||
} catch (e: Exception) {
|
||||
scope.launch {
|
||||
logDatabase.logDao().insertLog(
|
||||
logDatabase.dao().insertLog(
|
||||
LogEntity(
|
||||
0,
|
||||
packageName,
|
||||
@@ -399,7 +399,7 @@ class SignerProvider : ContentProvider() {
|
||||
} else {
|
||||
LocalPreferences.allSavedAccounts(context!!).firstNotNullOfOrNull { accountInfo ->
|
||||
val localDatabase = Amber.instance.getDatabase(accountInfo.npub)
|
||||
val hasAccount = localDatabase.applicationDao().getByKeySync(packageName) != null
|
||||
val hasAccount = localDatabase.dao().getByKeySync(packageName) != null
|
||||
if (hasAccount) {
|
||||
LocalPreferences.loadFromEncryptedStorageSync(context!!, accountInfo.npub)
|
||||
} else {
|
||||
@@ -414,13 +414,13 @@ class SignerProvider : ContentProvider() {
|
||||
val historyDatabase = Amber.instance.getHistoryDatabase(account.npub)
|
||||
val permission =
|
||||
database
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.getPermission(
|
||||
packageName,
|
||||
"GET_PUBLIC_KEY",
|
||||
)
|
||||
|
||||
val signPolicy = database.applicationDao().getSignPolicy(packageName)
|
||||
val signPolicy = database.dao().getSignPolicy(packageName)
|
||||
val isRemembered = IntentUtils.isRemembered(signPolicy, permission)
|
||||
if (isRemembered == null) {
|
||||
return null
|
||||
@@ -474,7 +474,7 @@ class SignerProvider : ContentProvider() {
|
||||
scope.launch {
|
||||
LocalPreferences.allSavedAccounts(context!!).forEach { accInfo ->
|
||||
val database = Amber.instance.getLogDatabase(accInfo.npub)
|
||||
database.logDao().insertLog(
|
||||
database.dao().insertLog(
|
||||
LogEntity(
|
||||
0,
|
||||
packageName,
|
||||
|
||||
@@ -157,7 +157,7 @@ val MIGRATION_15_16 = object : Migration(15, 16) {
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun applicationDao(): ApplicationDao
|
||||
abstract fun dao(): ApplicationDao
|
||||
|
||||
companion object {
|
||||
fun getDatabase(
|
||||
|
||||
@@ -43,7 +43,7 @@ interface HistoryDao {
|
||||
try {
|
||||
innerAddHistory(entity)
|
||||
npub?.let {
|
||||
Amber.instance.getDatabase(npub).applicationDao().updateLastUsed(entity.pkKey, entity.time)
|
||||
Amber.instance.getDatabase(npub).dao().updateLastUsed(entity.pkKey, entity.time)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(Amber.TAG, "Error adding history", e)
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.concurrent.Executors
|
||||
)
|
||||
@TypeConverters(Converters::class)
|
||||
abstract class LogDatabase : RoomDatabase() {
|
||||
abstract fun logDao(): LogDao
|
||||
abstract fun dao(): LogDao
|
||||
|
||||
companion object {
|
||||
fun getDatabase(
|
||||
|
||||
@@ -50,7 +50,7 @@ class NostrClientLoggerListener(
|
||||
override fun onAuth(relay: IRelayClient, challenge: String) {
|
||||
scope.launch {
|
||||
LocalPreferences.currentAccount(context)?.let { account ->
|
||||
Amber.instance.getLogDatabase(account).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = relay.url.url,
|
||||
@@ -66,7 +66,7 @@ class NostrClientLoggerListener(
|
||||
override fun onBeforeSend(relay: IRelayClient, event: Event) {
|
||||
scope.launch {
|
||||
LocalPreferences.currentAccount(context)?.let { account ->
|
||||
Amber.instance.getLogDatabase(account).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = relay.url.url,
|
||||
@@ -82,7 +82,7 @@ class NostrClientLoggerListener(
|
||||
override fun onSend(relay: IRelayClient, msg: String, success: Boolean) {
|
||||
scope.launch {
|
||||
LocalPreferences.currentAccount(context)?.let { account ->
|
||||
Amber.instance.getLogDatabase(account).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = relay.url.url,
|
||||
@@ -105,7 +105,7 @@ class NostrClientLoggerListener(
|
||||
override fun onSendResponse(relay: IRelayClient, eventId: String, success: Boolean, message: String) {
|
||||
scope.launch {
|
||||
LocalPreferences.currentAccount(context)?.let { account ->
|
||||
Amber.instance.getLogDatabase(account).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = relay.url.url,
|
||||
@@ -132,7 +132,7 @@ class NostrClientLoggerListener(
|
||||
if (error.message?.trim()?.equals("Relay sent notice:") == true) return
|
||||
scope.launch {
|
||||
LocalPreferences.currentAccount(context)?.let { account ->
|
||||
Amber.instance.getLogDatabase(account).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = relay.url.url,
|
||||
@@ -157,7 +157,7 @@ class NostrClientLoggerListener(
|
||||
override fun onEvent(relay: IRelayClient, subId: String, event: Event, arrivalTime: Long, afterEOSE: Boolean) {
|
||||
scope.launch {
|
||||
LocalPreferences.currentAccount(context)?.let { account ->
|
||||
Amber.instance.getLogDatabase(account).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = relay.url.url,
|
||||
@@ -175,7 +175,7 @@ class NostrClientLoggerListener(
|
||||
override fun onNotify(relay: IRelayClient, description: String) {
|
||||
scope.launch {
|
||||
LocalPreferences.currentAccount(context)?.let { account ->
|
||||
Amber.instance.getLogDatabase(account).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = relay.url.url,
|
||||
@@ -191,7 +191,7 @@ class NostrClientLoggerListener(
|
||||
override fun onRelayStateChange(relay: IRelayClient, type: RelayState) {
|
||||
scope.launch {
|
||||
LocalPreferences.currentAccount(context)?.let { account ->
|
||||
Amber.instance.getLogDatabase(account).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = relay.url.url,
|
||||
|
||||
@@ -151,7 +151,7 @@ object AmberUtils {
|
||||
)
|
||||
|
||||
Amber.instance.getDatabase(account.npub)
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.insertApplicationWithPermissions(application)
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ object BunkerRequestUtils {
|
||||
if (relays.isEmpty()) {
|
||||
onDone(true)
|
||||
onLoading(false)
|
||||
Amber.instance.getLogDatabase(account.npub).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account.npub).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = bunkerRequest.localKey,
|
||||
@@ -89,7 +89,7 @@ object BunkerRequestUtils {
|
||||
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
relays.forEach { relay ->
|
||||
Amber.instance.getLogDatabase(account.npub).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account.npub).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = relay.url,
|
||||
@@ -124,7 +124,7 @@ object BunkerRequestUtils {
|
||||
onDone(false)
|
||||
onLoading(false)
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
Amber.instance.getLogDatabase(account.npub).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account.npub).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = bunkerRequest.localKey,
|
||||
@@ -243,13 +243,13 @@ object BunkerRequestUtils {
|
||||
val defaultRelays = Amber.instance.settings.defaultRelays
|
||||
|
||||
if (oldKey.isNotBlank()) {
|
||||
database.applicationDao().delete(oldKey)
|
||||
database.dao().delete(oldKey)
|
||||
historyDatabase.dao().deleteHistory(oldKey)
|
||||
}
|
||||
|
||||
var savedApplication = database.applicationDao().getByKey(key)
|
||||
var savedApplication = database.dao().getByKey(key)
|
||||
if (savedApplication == null && bunkerRequest.request is BunkerRequestConnect && bunkerRequest.request.secret?.isNotBlank() == true) {
|
||||
savedApplication = database.applicationDao().getByKey(bunkerRequest.request.secret!!)
|
||||
savedApplication = database.dao().getByKey(bunkerRequest.request.secret!!)
|
||||
if (savedApplication != null) {
|
||||
val tempApplication = savedApplication.application.copy(
|
||||
key = key,
|
||||
@@ -261,11 +261,11 @@ object BunkerRequestUtils {
|
||||
}.toMutableList(),
|
||||
)
|
||||
|
||||
database.applicationDao().delete(bunkerRequest.request.secret!!)
|
||||
database.applicationDao().insertApplicationWithPermissions(tempApp2)
|
||||
database.dao().delete(bunkerRequest.request.secret!!)
|
||||
database.dao().insertApplicationWithPermissions(tempApp2)
|
||||
}
|
||||
}
|
||||
savedApplication = database.applicationDao().getByKey(key)
|
||||
savedApplication = database.dao().getByKey(key)
|
||||
if (bunkerRequest.request is BunkerRequestConnect) {
|
||||
savedApplication?.application?.deleteAfter = deleteAfter
|
||||
}
|
||||
@@ -319,7 +319,7 @@ object BunkerRequestUtils {
|
||||
|
||||
var didChangeRelays = false
|
||||
if (type == SignerType.CONNECT) {
|
||||
database.applicationDao().deletePermissions(key)
|
||||
database.dao().deletePermissions(key)
|
||||
application.application.isConnected = true
|
||||
shouldCloseApplication?.let {
|
||||
application.application.closeApplication = it
|
||||
@@ -350,7 +350,7 @@ object BunkerRequestUtils {
|
||||
|
||||
// assume that everything worked and try to revert it if it fails
|
||||
EventNotificationConsumer(context).notificationManager().cancelAll()
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
database.dao().insertApplicationWithPermissions(application)
|
||||
historyDatabase.dao().addHistory(
|
||||
HistoryEntity(
|
||||
0,
|
||||
@@ -382,10 +382,10 @@ object BunkerRequestUtils {
|
||||
if (rememberType != RememberType.NEVER) {
|
||||
if (type == SignerType.SIGN_EVENT) {
|
||||
kind?.let {
|
||||
database.applicationDao().deletePermissions(key, type.toString(), kind)
|
||||
database.dao().deletePermissions(key, type.toString(), kind)
|
||||
}
|
||||
} else {
|
||||
database.applicationDao().deletePermissions(key, type.toString())
|
||||
database.dao().deletePermissions(key, type.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ object BunkerRequestUtils {
|
||||
onLoading: (Boolean) -> Unit,
|
||||
) {
|
||||
Amber.instance.applicationIOScope.launch(Dispatchers.IO) {
|
||||
val savedApplication = Amber.instance.getDatabase(account.npub).applicationDao().getByKey(key)
|
||||
val savedApplication = Amber.instance.getDatabase(account.npub).dao().getByKey(key)
|
||||
val defaultRelays = Amber.instance.settings.defaultRelays
|
||||
val relays = savedApplication?.application?.relays?.ifEmpty { defaultRelays } ?: bunkerRequest.relays.ifEmpty { defaultRelays }
|
||||
|
||||
@@ -449,7 +449,7 @@ object BunkerRequestUtils {
|
||||
}
|
||||
|
||||
if (bunkerRequest.request !is BunkerRequestConnect) {
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().insertApplicationWithPermissions(application)
|
||||
Amber.instance.getDatabase(account.npub).dao().insertApplicationWithPermissions(application)
|
||||
Amber.instance.getHistoryDatabase(account.npub).dao().addHistory(
|
||||
HistoryEntity(
|
||||
0,
|
||||
|
||||
@@ -34,18 +34,18 @@ class ClearLogsWorker(appContext: Context, workerParams: WorkerParameters) :
|
||||
}
|
||||
|
||||
val logDatabase = Amber.instance.getLogDatabase(it.npub)
|
||||
val countLog = logDatabase.logDao().countOldLog(oneWeek)
|
||||
val countLog = logDatabase.dao().countOldLog(oneWeek)
|
||||
Log.d(Amber.TAG, "Deleting $countLog old log entries from ${com.greenart7c3.nostrsigner.models.TimeUtils.formatLongToCustomDateTimeWithSeconds(oneWeek)}")
|
||||
if (countLog > 0) {
|
||||
var logs = logDatabase.logDao().getOldLog(oneWeek)
|
||||
var logs = logDatabase.dao().getOldLog(oneWeek)
|
||||
var count = 0
|
||||
while (logs.isNotEmpty()) {
|
||||
count++
|
||||
logs.forEach { history ->
|
||||
Log.d(Amber.TAG, "Deleting log entry ${com.greenart7c3.nostrsigner.models.TimeUtils.formatLongToCustomDateTimeWithSeconds(history.time)}")
|
||||
logDatabase.logDao().deleteLog(history)
|
||||
logDatabase.dao().deleteLog(history)
|
||||
}
|
||||
logs = logDatabase.logDao().getOldLog(oneWeek)
|
||||
logs = logDatabase.dao().getOldLog(oneWeek)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -128,9 +128,9 @@ class ConnectivityService : Service() {
|
||||
scope.launch {
|
||||
LocalPreferences.allSavedAccounts(Amber.instance).forEach { accountInfo ->
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
val deleted = Amber.instance.getDatabase(accountInfo.npub).applicationDao().deleteOldApplications(now)
|
||||
val deleted = Amber.instance.getDatabase(accountInfo.npub).dao().deleteOldApplications(now)
|
||||
if (deleted > 0) {
|
||||
Amber.instance.getLogDatabase(accountInfo.npub).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(accountInfo.npub).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = "",
|
||||
|
||||
@@ -67,7 +67,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
||||
val accounts = LocalPreferences.allSavedAccounts(applicationContext)
|
||||
accounts.forEach {
|
||||
LocalPreferences.loadFromEncryptedStorage(applicationContext, it.npub)?.let { acc ->
|
||||
val dao = Amber.instance.getLogDatabase(acc.npub).logDao()
|
||||
val dao = Amber.instance.getLogDatabase(acc.npub).dao()
|
||||
dao.insertLog(
|
||||
LogEntity(
|
||||
0,
|
||||
@@ -114,7 +114,7 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
||||
) {
|
||||
if (event.content.isEmpty()) return
|
||||
|
||||
val dao = Amber.instance.getLogDatabase(acc.npub).logDao()
|
||||
val dao = Amber.instance.getLogDatabase(acc.npub).dao()
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
dao.insertLog(
|
||||
LogEntity(
|
||||
@@ -148,8 +148,8 @@ class EventNotificationConsumer(private val applicationContext: Context) {
|
||||
) {
|
||||
val responseRelay = listOf(relay)
|
||||
val database = Amber.instance.getDatabase(acc.npub)
|
||||
val dao = database.applicationDao()
|
||||
val logDao = Amber.instance.getLogDatabase(acc.npub).logDao()
|
||||
val dao = database.dao()
|
||||
val logDao = Amber.instance.getLogDatabase(acc.npub).dao()
|
||||
val historyDao = Amber.instance.getHistoryDatabase(acc.npub).dao()
|
||||
|
||||
val notification = Amber.instance.notificationCache[event.id]
|
||||
|
||||
@@ -177,7 +177,7 @@ object IntentUtils {
|
||||
} catch (e: Exception) {
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
val database = Amber.instance.getLogDatabase(account.npub)
|
||||
database.logDao().insertLog(
|
||||
database.dao().insertLog(
|
||||
LogEntity(
|
||||
0,
|
||||
packageName ?: "",
|
||||
@@ -360,7 +360,7 @@ object IntentUtils {
|
||||
} catch (e: Exception) {
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
val database = Amber.instance.getLogDatabase(account.npub)
|
||||
database.logDao().insertLog(
|
||||
database.dao().insertLog(
|
||||
LogEntity(
|
||||
0,
|
||||
packageName ?: "",
|
||||
@@ -508,7 +508,7 @@ object IntentUtils {
|
||||
} catch (e: Exception) {
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
LocalPreferences.allSavedAccounts(Amber.instance).forEach {
|
||||
Amber.instance.getLogDatabase(it.npub).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(it.npub).dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = "IntentUtils",
|
||||
@@ -569,7 +569,7 @@ object IntentUtils {
|
||||
val database = Amber.instance.getDatabase(account.npub)
|
||||
val historyDatabase = Amber.instance.getHistoryDatabase(account.npub)
|
||||
val defaultRelays = Amber.instance.settings.defaultRelays
|
||||
val savedApplication = database.applicationDao().getByKey(key)
|
||||
val savedApplication = database.dao().getByKey(key)
|
||||
val relays = savedApplication?.application?.relays?.ifEmpty { defaultRelays } ?: defaultRelays
|
||||
val localAppName =
|
||||
if (packageName != null) {
|
||||
@@ -637,7 +637,7 @@ object IntentUtils {
|
||||
}
|
||||
|
||||
if (packageName != null) {
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
database.dao().insertApplicationWithPermissions(application)
|
||||
historyDatabase.dao().addHistory(
|
||||
HistoryEntity(
|
||||
0,
|
||||
@@ -744,7 +744,7 @@ object IntentUtils {
|
||||
}
|
||||
|
||||
val defaultRelays = Amber.instance.settings.defaultRelays
|
||||
val savedApplication = Amber.instance.getDatabase(account.npub).applicationDao().getByKey(key)
|
||||
val savedApplication = Amber.instance.getDatabase(account.npub).dao().getByKey(key)
|
||||
val relays = savedApplication?.application?.relays?.ifEmpty { defaultRelays } ?: defaultRelays
|
||||
val application =
|
||||
savedApplication ?: ApplicationWithPermissions(
|
||||
@@ -778,7 +778,7 @@ object IntentUtils {
|
||||
)
|
||||
}
|
||||
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().insertApplicationWithPermissions(application)
|
||||
Amber.instance.getDatabase(account.npub).dao().insertApplicationWithPermissions(application)
|
||||
Amber.instance.getHistoryDatabase(account.npub).dao().addHistory(
|
||||
HistoryEntity(
|
||||
0,
|
||||
|
||||
@@ -131,7 +131,7 @@ object NostrConnectUtils {
|
||||
} catch (e: Exception) {
|
||||
Log.e(Amber.TAG, e.message, e)
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
Amber.instance.getLogDatabase(account.npub).logDao().insertLog(
|
||||
Amber.instance.getLogDatabase(account.npub).dao().insertLog(
|
||||
LogEntity(
|
||||
0,
|
||||
"nostrconnect",
|
||||
|
||||
@@ -182,7 +182,7 @@ fun ApplicationName(
|
||||
LaunchedEffect(Unit) {
|
||||
launch(Dispatchers.IO) {
|
||||
if (ApplicationNameCache.names["${account.npub.toShortenHex()}-$key"] == null) {
|
||||
val app = database.applicationDao().getByKey(key)
|
||||
val app = database.dao().getByKey(key)
|
||||
app?.let {
|
||||
name = it.application.name
|
||||
ApplicationNameCache.names["${account.npub.toShortenHex()}-$key"] = it.application.name
|
||||
|
||||
@@ -55,7 +55,7 @@ fun ApplicationsScreen(
|
||||
account: Account,
|
||||
navController: NavController,
|
||||
) {
|
||||
val applications = Amber.instance.getDatabase(account.npub).applicationDao().getAllFlow(account.hexKey).collectAsStateWithLifecycle(emptyList())
|
||||
val applications = Amber.instance.getDatabase(account.npub).dao().getAllFlow(account.hexKey).collectAsStateWithLifecycle(emptyList())
|
||||
var hasAccountsWithoutBackup by remember { mutableStateOf(false) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
|
||||
@@ -77,7 +77,7 @@ fun EditConfigurationScreen(
|
||||
var closeApp by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(Unit) {
|
||||
launch(Dispatchers.IO) {
|
||||
application = Amber.instance.getDatabase(account.npub).applicationDao().getByKey(key)
|
||||
application = Amber.instance.getDatabase(account.npub).dao().getByKey(key)
|
||||
name = TextFieldValue(AnnotatedString(application?.application?.name?.ifBlank { application?.application?.key?.toShortenHex() } ?: ""))
|
||||
closeApp = application?.application?.closeApplication != false
|
||||
|
||||
@@ -288,8 +288,8 @@ fun EditConfigurationScreen(
|
||||
relays = relays,
|
||||
closeApplication = closeApp,
|
||||
)
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().delete(it.application)
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().insertApplicationWithPermissions(
|
||||
Amber.instance.getDatabase(account.npub).dao().delete(it.application)
|
||||
Amber.instance.getDatabase(account.npub).dao().insertApplicationWithPermissions(
|
||||
ApplicationWithPermissions(
|
||||
localApplicationData,
|
||||
it.permissions,
|
||||
@@ -317,7 +317,7 @@ fun EditConfigurationScreen(
|
||||
onClick = {
|
||||
application?.let {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().delete(it.application)
|
||||
Amber.instance.getDatabase(account.npub).dao().delete(it.application)
|
||||
Amber.instance.getHistoryDatabase(account.npub).dao().deleteHistory(it.application.key)
|
||||
|
||||
scope.launch(Dispatchers.Main) {
|
||||
|
||||
@@ -88,8 +88,8 @@ fun EditPermission(
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
launch(Dispatchers.IO) {
|
||||
permissions.addAll(Amber.instance.getDatabase(account.npub).applicationDao().getAllByKey(selectedPackage).sortedBy { "${it.type}-${it.kind}" })
|
||||
applicationData = Amber.instance.getDatabase(account.npub).applicationDao().getByKey(selectedPackage)!!.application
|
||||
permissions.addAll(Amber.instance.getDatabase(account.npub).dao().getAllByKey(selectedPackage).sortedBy { "${it.type}-${it.kind}" })
|
||||
applicationData = Amber.instance.getDatabase(account.npub).dao().getByKey(selectedPackage)!!.application
|
||||
checked = applicationData.useSecret
|
||||
val relays = applicationData.relays.joinToString(separator = "&") { "relay=${it.url}" }
|
||||
val localSecret = if (checked) "&secret=${applicationData.secret}" else ""
|
||||
@@ -105,7 +105,7 @@ fun EditPermission(
|
||||
) {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
Amber.instance.getDatabase(account.npub)
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.deletePermissions(applicationData.key)
|
||||
|
||||
permissions.clear()
|
||||
@@ -231,7 +231,7 @@ fun EditPermission(
|
||||
permissions.clear()
|
||||
permissions.addAll(localPermissions)
|
||||
Amber.instance.getDatabase(account.npub)
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.insertPermissions(localPermissions)
|
||||
}
|
||||
},
|
||||
@@ -262,7 +262,7 @@ fun EditPermission(
|
||||
}
|
||||
permissions.clear()
|
||||
permissions.addAll(localPermissions)
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().insertPermissions(localPermissions)
|
||||
Amber.instance.getDatabase(account.npub).dao().insertPermissions(localPermissions)
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -285,7 +285,7 @@ fun EditPermission(
|
||||
onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
permissions.remove(permission)
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().deletePermission(permission)
|
||||
Amber.instance.getDatabase(account.npub).dao().deletePermission(permission)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -63,7 +63,7 @@ fun IncomingRequestScreen(
|
||||
loading = true
|
||||
try {
|
||||
LocalPreferences.allSavedAccounts(context).forEach { account ->
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().getAllApplications().forEach {
|
||||
Amber.instance.getDatabase(account.npub).dao().getAllApplications().forEach {
|
||||
if (it.application.name.isNotBlank()) {
|
||||
ApplicationNameCache.names["${account.npub.toShortenHex()}-${it.application.key}"] = it.application.name
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ fun LogsScreen(
|
||||
account: Account,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val logsFlow = Amber.instance.getLogDatabase(account.npub).logDao().getLogs()
|
||||
val logsFlow = Amber.instance.getLogDatabase(account.npub).dao().getLogs()
|
||||
val logs = logsFlow.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||
val state = rememberLazyListState()
|
||||
|
||||
@@ -51,7 +51,7 @@ fun LogsScreen(
|
||||
modifier = Modifier.padding(bottom = 8.dp),
|
||||
onClick = {
|
||||
scope.launch(Dispatchers.IO) {
|
||||
Amber.instance.getLogDatabase(account.npub).logDao().clearLogs()
|
||||
Amber.instance.getLogDatabase(account.npub).dao().clearLogs()
|
||||
}
|
||||
},
|
||||
text = stringResource(R.string.clear_logs),
|
||||
|
||||
@@ -258,7 +258,7 @@ fun NewNsecBunkerScreen(
|
||||
lastUsed = 0L,
|
||||
)
|
||||
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().insertApplication(
|
||||
Amber.instance.getDatabase(account.npub).dao().insertApplication(
|
||||
application,
|
||||
)
|
||||
scope.launch(Dispatchers.Main) {
|
||||
@@ -285,7 +285,7 @@ fun NewNsecBunkerCreatedScreen(
|
||||
LaunchedEffect(Unit) {
|
||||
isLoading.value = true
|
||||
launch(Dispatchers.IO) {
|
||||
application = Amber.instance.getDatabase(account.npub).applicationDao().getByKey(key)?.application ?: ApplicationEntity.empty()
|
||||
application = Amber.instance.getDatabase(account.npub).dao().getByKey(key)?.application ?: ApplicationEntity.empty()
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,18 +291,18 @@ fun SettingsScreen(
|
||||
}
|
||||
|
||||
val logDatabase = Amber.instance.getLogDatabase(it.npub)
|
||||
val countLog = logDatabase.logDao().countOldLog(oneWeek)
|
||||
val countLog = logDatabase.dao().countOldLog(oneWeek)
|
||||
if (countLog > 0) {
|
||||
status = context.getString(R.string.deleting_old_log_entries, countLog)
|
||||
var logs = logDatabase.logDao().getOldLog(oneWeek)
|
||||
var logs = logDatabase.dao().getOldLog(oneWeek)
|
||||
var count = 0
|
||||
while (logs.isNotEmpty()) {
|
||||
count++
|
||||
status = context.getString(R.string.deleting_old_log_entries_2, 100 * count, countLog)
|
||||
logs.forEach { history ->
|
||||
logDatabase.logDao().deleteLog(history)
|
||||
logDatabase.dao().deleteLog(history)
|
||||
}
|
||||
logs = logDatabase.logDao().getOldLog(oneWeek)
|
||||
logs = logDatabase.dao().getOldLog(oneWeek)
|
||||
}
|
||||
}
|
||||
val dbFile = context.getDatabasePath("amber_db_${account.npub}")
|
||||
|
||||
@@ -451,7 +451,7 @@ fun RelayLogScreen(
|
||||
val context = LocalContext.current
|
||||
|
||||
val flows = LocalPreferences.allSavedAccounts(context).map {
|
||||
Amber.instance.getLogDatabase(it.npub).logDao().getLogsByUrl(url)
|
||||
Amber.instance.getLogDatabase(it.npub).dao().getLogsByUrl(url)
|
||||
}.merge()
|
||||
|
||||
val logs = flows.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||
|
||||
@@ -39,9 +39,9 @@ fun LogoutButton(
|
||||
val account = LocalPreferences.loadFromEncryptedStorage(context, acc.npub)
|
||||
account?.let {
|
||||
val database = Amber.instance.getDatabase(it.npub)
|
||||
val permissions = database.applicationDao().getAll(it.hexKey)
|
||||
val permissions = database.dao().getAll(it.hexKey)
|
||||
permissions.forEach { app ->
|
||||
database.applicationDao().delete(app)
|
||||
database.dao().delete(app)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ fun AmberTopAppBar(
|
||||
title = Route.QrCode.title
|
||||
}
|
||||
navBackStackEntry?.arguments?.getString("packageName")?.let { packageName ->
|
||||
val application = Amber.instance.getDatabase(account.npub).applicationDao().getByKey(packageName)?.application
|
||||
val application = Amber.instance.getDatabase(account.npub).dao().getByKey(packageName)?.application
|
||||
title = if (destinationRoute.startsWith("Activity/")) {
|
||||
"${application?.name?.ifBlank { application.key.toShortenHex() } ?: packageName} - ${routes.find { it.route.startsWith(destinationRoute) }?.title}"
|
||||
} else {
|
||||
@@ -170,7 +170,7 @@ fun AmberTopAppBar(
|
||||
}
|
||||
}
|
||||
navBackStackEntry?.arguments?.getString("key")?.let { packageName ->
|
||||
val application = Amber.instance.getDatabase(account.npub).applicationDao().getByKey(packageName)?.application
|
||||
val application = Amber.instance.getDatabase(account.npub).dao().getByKey(packageName)?.application
|
||||
title = if (destinationRoute.startsWith("Activity/")) {
|
||||
"${application?.name?.ifBlank { application.key.toShortenHex() } ?: packageName} - ${routes.find { it.route.startsWith(destinationRoute) }?.title}"
|
||||
} else {
|
||||
@@ -191,7 +191,7 @@ fun AmberTopAppBar(
|
||||
packageName
|
||||
}
|
||||
|
||||
val application = Amber.instance.getDatabase(account.npub).applicationDao().getByKey(key ?: "")?.application
|
||||
val application = Amber.instance.getDatabase(account.npub).dao().getByKey(key ?: "")?.application
|
||||
val titleTemp = application?.name?.ifBlank { application.key.toShortenHex() } ?: packageName ?: ""
|
||||
title = if (titleTemp.isBlank()) {
|
||||
routes.find { it.route == destinationRoute }?.title ?: ""
|
||||
|
||||
+3
-3
@@ -69,9 +69,9 @@ fun BunkerSingleEventHomeScreen(
|
||||
launch(Dispatchers.IO) {
|
||||
applicationEntity =
|
||||
if (bunkerRequest.request is BunkerRequestConnect && bunkerRequest.request.secret?.isNotBlank() == true) {
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().getBySecret(bunkerRequest.request.secret!!)
|
||||
Amber.instance.getDatabase(account.npub).dao().getBySecret(bunkerRequest.request.secret!!)
|
||||
} else {
|
||||
Amber.instance.getDatabase(account.npub).applicationDao().getByKey(key)
|
||||
Amber.instance.getDatabase(account.npub).dao().getByKey(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ fun BunkerSingleEventHomeScreen(
|
||||
|
||||
if (bunkerRequest.name.isNotBlank()) {
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
val existingApp = Amber.instance.getDatabase(account.npub).applicationDao().getByName(bunkerRequest.name)
|
||||
val existingApp = Amber.instance.getDatabase(account.npub).dao().getByName(bunkerRequest.name)
|
||||
if (existingApp == null) {
|
||||
BunkerRequestUtils.sendResult(
|
||||
context = context,
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ fun IntentSingleEventHomeScreen(
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
launch(Dispatchers.IO) {
|
||||
applicationEntity = Amber.instance.getDatabase(account.npub).applicationDao().getByKey(key)
|
||||
applicationEntity = Amber.instance.getDatabase(account.npub).dao().getByKey(key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -225,7 +225,7 @@ fun IntentMultiEventHomeScreen(
|
||||
|
||||
val database = Amber.instance.getDatabase(thisAccount.npub)
|
||||
val historyDatabase = Amber.instance.getHistoryDatabase(thisAccount.npub)
|
||||
val savedApplication = database.applicationDao().getByKey(localKey)
|
||||
val savedApplication = database.dao().getByKey(localKey)
|
||||
|
||||
val application =
|
||||
savedApplication ?: ApplicationWithPermissions(
|
||||
@@ -267,7 +267,7 @@ fun IntentMultiEventHomeScreen(
|
||||
)
|
||||
}
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
database.dao().insertApplicationWithPermissions(application)
|
||||
|
||||
historyDatabase.dao().addHistory(
|
||||
HistoryEntity(
|
||||
@@ -321,7 +321,7 @@ fun IntentMultiEventHomeScreen(
|
||||
)
|
||||
}
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
database.dao().insertApplicationWithPermissions(application)
|
||||
historyDatabase.dao().addHistory(
|
||||
HistoryEntity(
|
||||
0,
|
||||
@@ -359,7 +359,7 @@ fun IntentMultiEventHomeScreen(
|
||||
)
|
||||
}
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
database.dao().insertApplicationWithPermissions(application)
|
||||
|
||||
historyDatabase.dao().addHistory(
|
||||
HistoryEntity(
|
||||
@@ -424,7 +424,7 @@ fun IntentMultiEventHomeScreen(
|
||||
val database = Amber.instance.getDatabase(thisAccount.npub)
|
||||
val application =
|
||||
database
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.getByKey(localKey) ?: ApplicationWithPermissions(
|
||||
application = ApplicationEntity(
|
||||
localKey,
|
||||
@@ -597,7 +597,7 @@ fun BunkerMultiEventHomeScreen(
|
||||
val localKey = request.localKey
|
||||
val database = Amber.instance.getDatabase(thisAccount.npub)
|
||||
val historyDatabase = Amber.instance.getHistoryDatabase(thisAccount.npub)
|
||||
val savedApplication = database.applicationDao().getByKey(localKey)
|
||||
val savedApplication = database.dao().getByKey(localKey)
|
||||
|
||||
val secret = if (request.request is BunkerRequestConnect) {
|
||||
request.request.secret ?: ""
|
||||
@@ -645,7 +645,7 @@ fun BunkerMultiEventHomeScreen(
|
||||
)
|
||||
}
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
database.dao().insertApplicationWithPermissions(application)
|
||||
|
||||
historyDatabase.dao().addHistory(
|
||||
entity = HistoryEntity(
|
||||
@@ -699,7 +699,7 @@ fun BunkerMultiEventHomeScreen(
|
||||
)
|
||||
}
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
database.dao().insertApplicationWithPermissions(application)
|
||||
historyDatabase.dao().addHistory(
|
||||
HistoryEntity(
|
||||
0,
|
||||
@@ -742,7 +742,7 @@ fun BunkerMultiEventHomeScreen(
|
||||
}
|
||||
} else if (request.request is BunkerRequestConnect) {
|
||||
if (savedApplication == null) {
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
database.dao().insertApplicationWithPermissions(application)
|
||||
|
||||
historyDatabase.dao().addHistory(
|
||||
HistoryEntity(
|
||||
@@ -797,7 +797,7 @@ fun BunkerMultiEventHomeScreen(
|
||||
)
|
||||
}
|
||||
|
||||
database.applicationDao().insertApplicationWithPermissions(application)
|
||||
database.dao().insertApplicationWithPermissions(application)
|
||||
|
||||
historyDatabase.dao().addHistory(
|
||||
HistoryEntity(
|
||||
@@ -878,7 +878,7 @@ fun BunkerMultiEventHomeScreen(
|
||||
}
|
||||
val application =
|
||||
database
|
||||
.applicationDao()
|
||||
.dao()
|
||||
.getByKey(localKey) ?: ApplicationWithPermissions(
|
||||
application = ApplicationEntity(
|
||||
localKey,
|
||||
|
||||
Reference in New Issue
Block a user