feat: Safely set last logged account public key using null safety
This commit is contained in:
@@ -82,8 +82,12 @@ fun UnlockScreen(
|
||||
var searchQuery by remember { mutableStateOf("") }
|
||||
val searchFocusRequester = remember { FocusRequester() }
|
||||
|
||||
// Load accounts
|
||||
// Load accounts and pre-select last used account
|
||||
LaunchedEffect(Unit) {
|
||||
// ⚡ СИНХРОННОЕ чтение последнего аккаунта ДО загрузки списка
|
||||
val lastLoggedKey = accountManager.getLastLoggedPublicKey()
|
||||
Log.d("UnlockScreen", "🔍 Last logged account from SharedPrefs: ${lastLoggedKey?.take(16) ?: "none"}")
|
||||
|
||||
val allAccounts = accountManager.getAllAccounts()
|
||||
accounts = allAccounts.map { acc ->
|
||||
AccountItem(
|
||||
@@ -93,30 +97,26 @@ fun UnlockScreen(
|
||||
)
|
||||
}
|
||||
|
||||
// Get last logged account from SharedPreferences (synchronous, reliable)
|
||||
val lastLoggedKey = accountManager.getLastLoggedPublicKey()
|
||||
Log.d("UnlockScreen", "📋 Available accounts: ${accounts.map { "${it.name}:${it.publicKey.take(8)}" }}")
|
||||
|
||||
Log.d("UnlockScreen", "Loading accounts. lastLoggedKey=$lastLoggedKey")
|
||||
Log.d("UnlockScreen", "Available accounts: ${accounts.map { "${it.name}:${it.publicKey.take(8)}" }}")
|
||||
|
||||
// Find the target account - prioritize selectedAccountId, then lastLoggedKey
|
||||
// Find the target account - приоритет: selectedAccountId > lastLoggedKey > первый
|
||||
val targetAccount = when {
|
||||
selectedAccountId != null -> {
|
||||
Log.d("UnlockScreen", "Using selectedAccountId: $selectedAccountId")
|
||||
!selectedAccountId.isNullOrEmpty() -> {
|
||||
Log.d("UnlockScreen", "✅ Using selectedAccountId: ${selectedAccountId.take(16)}")
|
||||
accounts.find { it.publicKey == selectedAccountId }
|
||||
}
|
||||
lastLoggedKey != null -> {
|
||||
Log.d("UnlockScreen", "Using lastLoggedKey: ${lastLoggedKey.take(8)}")
|
||||
!lastLoggedKey.isNullOrEmpty() -> {
|
||||
Log.d("UnlockScreen", "✅ Using lastLoggedKey: ${lastLoggedKey.take(16)}")
|
||||
accounts.find { it.publicKey == lastLoggedKey }
|
||||
}
|
||||
else -> {
|
||||
Log.d("UnlockScreen", "No lastLoggedKey, using first account")
|
||||
null
|
||||
Log.d("UnlockScreen", "⚠️ No preference, using first account")
|
||||
accounts.firstOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
selectedAccount = targetAccount ?: accounts.firstOrNull()
|
||||
Log.d("UnlockScreen", "Final selected: ${selectedAccount?.name}:${selectedAccount?.publicKey?.take(8)}")
|
||||
Log.d("UnlockScreen", "🎯 Final selected: ${selectedAccount?.name} (${selectedAccount?.publicKey?.take(16)})")
|
||||
}
|
||||
|
||||
// Filter accounts by search
|
||||
|
||||
@@ -176,6 +176,8 @@ fun ChatDetailScreen(
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
val focusManager = LocalFocusManager.current
|
||||
val clipboardManager = androidx.compose.ui.platform.LocalClipboardManager.current
|
||||
val context = LocalContext.current
|
||||
val database = remember { com.rosetta.messenger.database.RosettaDatabase.getDatabase(context) }
|
||||
// Цвета как в React Native themes.ts
|
||||
val backgroundColor = if (isDarkTheme) Color(0xFF1E1E1E) else Color(0xFFFFFFFF)
|
||||
val textColor = if (isDarkTheme) Color.White else Color.Black
|
||||
@@ -1103,7 +1105,22 @@ fun ChatDetailScreen(
|
||||
TextButton(
|
||||
onClick = {
|
||||
showDeleteConfirm = false
|
||||
// TODO: Implement delete chat
|
||||
scope.launch {
|
||||
try {
|
||||
// Delete all messages in this dialog
|
||||
database.messageDao().deleteDialog(
|
||||
account = currentUserPublicKey,
|
||||
dialogKey = user.publicKey
|
||||
)
|
||||
// Delete dialog cache
|
||||
database.dialogDao().deleteDialog(
|
||||
account = currentUserPublicKey,
|
||||
opponentKey = user.publicKey
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("ChatDetail", "Error deleting chat", e)
|
||||
}
|
||||
}
|
||||
onBack()
|
||||
}
|
||||
) {
|
||||
@@ -1140,7 +1157,21 @@ fun ChatDetailScreen(
|
||||
TextButton(
|
||||
onClick = {
|
||||
showBlockConfirm = false
|
||||
// TODO: Implement block user
|
||||
scope.launch {
|
||||
try {
|
||||
// Add user to blacklist
|
||||
database.blacklistDao().blockUser(
|
||||
com.rosetta.messenger.database.BlacklistEntity(
|
||||
publicKey = user.publicKey,
|
||||
account = currentUserPublicKey
|
||||
)
|
||||
)
|
||||
android.util.Log.d("ChatDetail", "User blocked: ${user.publicKey.take(10)}")
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("ChatDetail", "Error blocking user", e)
|
||||
}
|
||||
}
|
||||
onBack()
|
||||
}
|
||||
) {
|
||||
Text("Block", color = Color(0xFFFF3B30))
|
||||
@@ -1193,8 +1224,8 @@ private fun MessageBubble(
|
||||
onLongClick: () -> Unit = {},
|
||||
onClick: () -> Unit = {}
|
||||
) {
|
||||
// Telegram-style enter animation
|
||||
val (alpha, translationY) = rememberMessageEnterAnimation(message.id)
|
||||
// ❌ УБРАЛИ: Telegram-style enter animation - она мешает при скролле
|
||||
// val (alpha, translationY) = rememberMessageEnterAnimation(message.id)
|
||||
|
||||
// Selection animation
|
||||
val selectionScale by animateFloatAsState(
|
||||
@@ -1242,8 +1273,9 @@ private fun MessageBubble(
|
||||
Modifier.fillMaxWidth()
|
||||
.padding(horizontal = 8.dp, vertical = 1.dp)
|
||||
.graphicsLayer {
|
||||
this.alpha = alpha * selectionAlpha
|
||||
this.translationY = translationY
|
||||
// ❌ УБРАЛИ: alpha = alpha * selectionAlpha и translationY
|
||||
// Оставляем только selection анимацию
|
||||
this.alpha = selectionAlpha
|
||||
this.scaleX = selectionScale
|
||||
this.scaleY = selectionScale
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user