commit 3f67cb205b0a2f27f23efac5d313ec50a097532f
parent 27606977b79eab5356151fae570768fc05e6580d
Author: t3sserakt <t3ss@posteo.de>
Date: Tue, 7 Apr 2026 19:33:30 +0200
WIP: fixing chat overview race condition
Diffstat:
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/GNUnetMessenger/app/src/main/java/org/gnunet/gnunetmessenger/MainActivity.kt b/GNUnetMessenger/app/src/main/java/org/gnunet/gnunetmessenger/MainActivity.kt
@@ -81,9 +81,6 @@ class MainActivity : AppCompatActivity() {
var currentAccount: ChatAccount? = null
private set
- @Volatile
- var connectingAccount = false
-
companion object {
private const val TAG = "MainActivity"
private const val CHAT_READY_POLL_MS = 50L
@@ -193,14 +190,15 @@ class MainActivity : AppCompatActivity() {
}
MessageKind.LOGIN -> {
- if (!connectingAccount) {
- loadChats()
- }
+ loadChats()
}
MessageKind.LOGOUT -> {
- if (!connectingAccount) {
- Log.d(TAG, "Received LOGOUT")
+ Log.d(TAG, "Received LOGOUT")
+ // During account switch, clearChatState() is called explicitly
+ // before disconnect(). Skip clearing here to avoid wiping data
+ // that loadChats() (triggered by the subsequent LOGIN) has loaded.
+ if (currentAccount == null) {
contactListViewModel.clearModel()
chatOverviewViewModel.clearModel()
chatViewModels.values.forEach { it.clearModel() }
@@ -332,10 +330,6 @@ class MainActivity : AppCompatActivity() {
}
}
- suspend fun loadChatsAwait() {
- loadChatsSuspend()
- }
-
private suspend fun loadChatsSuspend() = withContext(Dispatchers.IO) {
val summaries = mutableListOf<ChatSummary>()
val contacts = mutableListOf<ChatContact>()