kotlin: refactor chat contexts 1 (remove functions creating indirection) (#5827)

* kotlin: refactor chat contexts 1

* remove withChats

* comment

* remove withReportChatsIfOpen

* remove comment

* fix desktop
This commit is contained in:
spaced4ndy
2025-04-14 16:01:22 +00:00
committed by GitHub
parent 14d9240995
commit 38c2529d8b
33 changed files with 598 additions and 580 deletions
@@ -24,7 +24,6 @@ import chat.simplex.app.views.call.CallActivity
import chat.simplex.common.helpers.*
import chat.simplex.common.model.*
import chat.simplex.common.model.ChatController.appPrefs
import chat.simplex.common.model.ChatModel.withChats
import chat.simplex.common.platform.*
import chat.simplex.common.ui.theme.*
import chat.simplex.common.views.call.*
@@ -33,7 +32,6 @@ import chat.simplex.common.views.helpers.*
import chat.simplex.common.views.onboarding.OnboardingStage
import com.jakewharton.processphoenix.ProcessPhoenix
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.map
import java.io.*
import java.util.*
import java.util.concurrent.TimeUnit
@@ -94,7 +92,7 @@ class SimplexApp: Application(), LifecycleEventObserver {
Lifecycle.Event.ON_START -> {
isAppOnForeground = true
if (chatModel.chatRunning.value == true) {
withChats {
withContext(Dispatchers.Main) {
kotlin.runCatching {
val currentUserId = chatModel.currentUser.value?.userId
val chats = ArrayList(chatController.apiGetChats(chatModel.remoteHostId()))
@@ -107,7 +105,7 @@ class SimplexApp: Application(), LifecycleEventObserver {
/** Pass old chatStats because unreadCounter can be changed already while [ChatController.apiGetChats] is executing */
if (indexOfCurrentChat >= 0) chats[indexOfCurrentChat] = chats[indexOfCurrentChat].copy(chatStats = oldStats)
}
updateChats(chats)
chatModel.chatsContext.updateChats(chats)
}
}.onFailure { Log.e(TAG, it.stackTraceToString()) }
}