Промежуточный результат для 1.0.4 версии

This commit is contained in:
2026-02-22 08:54:46 +05:00
parent 3aa18fa9ac
commit 5b9b3f83f7
37 changed files with 5643 additions and 928 deletions

View File

@@ -153,6 +153,7 @@ class MainActivity : FragmentActivity() {
var hasExistingAccount by remember { mutableStateOf<Boolean?>(null) }
var currentAccount by remember { mutableStateOf<DecryptedAccount?>(null) }
var accountInfoList by remember { mutableStateOf<List<AccountInfo>>(emptyList()) }
var startCreateAccountFlow by remember { mutableStateOf(false) }
// Check for existing accounts and build AccountInfo list
// Also force logout so user always sees unlock screen on app restart
@@ -242,7 +243,9 @@ class MainActivity : FragmentActivity() {
hasExistingAccount = screen == "auth_unlock",
accounts = accountInfoList,
accountManager = accountManager,
startInCreateMode = startCreateAccountFlow,
onAuthComplete = { account ->
startCreateAccountFlow = false
currentAccount = account
hasExistingAccount = true
// Save as last logged account
@@ -261,6 +264,7 @@ class MainActivity : FragmentActivity() {
}
},
onLogout = {
startCreateAccountFlow = false
// Set currentAccount to null immediately to prevent UI
// lag
currentAccount = null
@@ -287,6 +291,7 @@ class MainActivity : FragmentActivity() {
scope.launch { preferencesManager.setThemeMode(mode) }
},
onLogout = {
startCreateAccountFlow = false
// Set currentAccount to null immediately to prevent UI
// lag
currentAccount = null
@@ -297,6 +302,7 @@ class MainActivity : FragmentActivity() {
}
},
onDeleteAccount = {
startCreateAccountFlow = false
val publicKey = currentAccount?.publicKey ?: return@MainScreen
scope.launch {
try {
@@ -331,14 +337,59 @@ class MainActivity : FragmentActivity() {
val accounts = accountManager.getAllAccounts()
accountInfoList = accounts.map { it.toAccountInfo() }
},
onDeleteAccountFromSidebar = { targetPublicKey ->
startCreateAccountFlow = false
scope.launch {
try {
val database = RosettaDatabase.getDatabase(this@MainActivity)
// 1. Delete all messages
database.messageDao().deleteAllByAccount(targetPublicKey)
// 2. Delete all dialogs
database.dialogDao().deleteAllByAccount(targetPublicKey)
// 3. Delete blacklist
database.blacklistDao().deleteAllByAccount(targetPublicKey)
// 4. Delete avatars from DB
database.avatarDao().deleteAvatars(targetPublicKey)
// 5. Delete account from Room DB
database.accountDao().deleteAccount(targetPublicKey)
// 6. Disconnect protocol only if deleting currently open account
if (currentAccount?.publicKey == targetPublicKey) {
com.rosetta.messenger.network.ProtocolManager.disconnect()
}
// 7. Delete account from AccountManager DataStore
accountManager.deleteAccount(targetPublicKey)
// 8. Refresh accounts list
val accounts = accountManager.getAllAccounts()
accountInfoList = accounts.map { it.toAccountInfo() }
hasExistingAccount = accounts.isNotEmpty()
// 9. If current account is deleted, return to main login screen
if (currentAccount?.publicKey == targetPublicKey) {
currentAccount = null
}
} catch (e: Exception) {
android.util.Log.e("DeleteAccount", "Failed to delete account from sidebar", e)
}
}
},
onSwitchAccount = { targetPublicKey ->
// Switch to another account: logout current, then auto-login target
startCreateAccountFlow = false
// Save target account before leaving main screen so Unlock
// screen preselects the account the user tapped.
accountManager.setLastLoggedPublicKey(targetPublicKey)
// Switch to another account: logout current, then show unlock.
currentAccount = null
scope.launch {
com.rosetta.messenger.network.ProtocolManager.disconnect()
accountManager.logout()
}
},
onAddAccount = {
startCreateAccountFlow = true
currentAccount = null
scope.launch {
com.rosetta.messenger.network.ProtocolManager.disconnect()
accountManager.logout()
// Set the target account as last logged so UnlockScreen picks it up
accountManager.setLastLoggedPublicKey(targetPublicKey)
}
}
)
@@ -529,7 +580,9 @@ fun MainScreen(
onLogout: () -> Unit = {},
onDeleteAccount: () -> Unit = {},
onAccountInfoUpdated: suspend () -> Unit = {},
onSwitchAccount: (String) -> Unit = {}
onSwitchAccount: (String) -> Unit = {},
onDeleteAccountFromSidebar: (String) -> Unit = {},
onAddAccount: () -> Unit = {}
) {
val accountPublicKey = account?.publicKey.orEmpty()
@@ -739,12 +792,11 @@ fun MainScreen(
},
chatsViewModel = chatsListViewModel,
avatarRepository = avatarRepository,
onLogout = onLogout,
onAddAccount = {
// Logout current account and go to auth screen to add new one
onLogout()
onAddAccount()
},
onSwitchAccount = onSwitchAccount
onSwitchAccount = onSwitchAccount,
onDeleteAccountFromSidebar = onDeleteAccountFromSidebar
)
SwipeBackContainer(