fix(database): db cache

This commit is contained in:
rhunk
2024-01-04 23:09:27 +01:00
parent d1c4b4febe
commit a90f4875a7
3 changed files with 116 additions and 108 deletions

View File

@@ -261,69 +261,71 @@ class ScopeContent(
Spacer(modifier = Modifier.height(16.dp))
// e2ee section
SectionTitle(translation["e2ee_title"])
var hasSecretKey by remember { mutableStateOf(context.e2eeImplementation.friendKeyExists(friend.userId))}
var importDialog by remember { mutableStateOf(false) }
if (context.config.root.experimental.e2eEncryption.globalState == true) {
SectionTitle(translation["e2ee_title"])
var hasSecretKey by remember { mutableStateOf(context.e2eeImplementation.friendKeyExists(friend.userId))}
var importDialog by remember { mutableStateOf(false) }
if (importDialog) {
Dialog(
onDismissRequest = { importDialog = false }
) {
dialogs.RawInputDialog(onDismiss = { importDialog = false }, onConfirm = { newKey ->
importDialog = false
runCatching {
val key = Base64.decode(newKey)
if (key.size != 32) {
context.longToast("Invalid key size (must be 32 bytes)")
return@runCatching
if (importDialog) {
Dialog(
onDismissRequest = { importDialog = false }
) {
dialogs.RawInputDialog(onDismiss = { importDialog = false }, onConfirm = { newKey ->
importDialog = false
runCatching {
val key = Base64.decode(newKey)
if (key.size != 32) {
context.longToast("Invalid key size (must be 32 bytes)")
return@runCatching
}
context.e2eeImplementation.storeSharedSecretKey(friend.userId, key)
context.longToast("Successfully imported key")
hasSecretKey = true
}.onFailure {
context.longToast("Failed to import key: ${it.message}")
context.log.error("Failed to import key", it)
}
context.e2eeImplementation.storeSharedSecretKey(friend.userId, key)
context.longToast("Successfully imported key")
hasSecretKey = true
}.onFailure {
context.longToast("Failed to import key: ${it.message}")
context.log.error("Failed to import key", it)
}
})
})
}
}
}
ContentCard {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
if (hasSecretKey) {
OutlinedButton(onClick = {
val secretKey = Base64.encode(context.e2eeImplementation.getSharedSecretKey(friend.userId) ?: return@OutlinedButton)
//TODO: fingerprint auth
context.activity!!.startActivity(Intent.createChooser(Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, secretKey)
type = "text/plain"
}, "").apply {
putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(
Intent().apply {
putExtra(Intent.EXTRA_TEXT, secretKey)
putExtra(Intent.EXTRA_SUBJECT, secretKey)
})
ContentCard {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
if (hasSecretKey) {
OutlinedButton(onClick = {
val secretKey = Base64.encode(context.e2eeImplementation.getSharedSecretKey(friend.userId) ?: return@OutlinedButton)
//TODO: fingerprint auth
context.activity!!.startActivity(Intent.createChooser(Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, secretKey)
type = "text/plain"
}, "").apply {
putExtra(Intent.EXTRA_INITIAL_INTENTS, arrayOf(
Intent().apply {
putExtra(Intent.EXTRA_TEXT, secretKey)
putExtra(Intent.EXTRA_SUBJECT, secretKey)
})
)
})
}) {
Text(
text = "Export Base64",
maxLines = 1
)
})
}) {
}
}
OutlinedButton(onClick = { importDialog = true }) {
Text(
text = "Export Base64",
text = "Import Base64",
maxLines = 1
)
}
}
OutlinedButton(onClick = { importDialog = true }) {
Text(
text = "Import Base64",
maxLines = 1
)
}
}
}
}