android: prevent race when changing active user (#1913)

This commit is contained in:
Stanislav Dmitrenko 2023-02-08 16:21:55 +03:00 committed by GitHub
parent f24035a99d
commit aa6011a196
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,8 +101,12 @@ class SimplexApp: Application(), LifecycleEventObserver {
isAppOnForeground = true isAppOnForeground = true
if (chatModel.chatRunning.value == true) { if (chatModel.chatRunning.value == true) {
kotlin.runCatching { kotlin.runCatching {
val currentUserId = chatModel.currentUser.value?.userId
val chats = chatController.apiGetChats() val chats = chatController.apiGetChats()
chatModel.updateChats(chats) /** Active user can be changed in background while [ChatController.apiGetChats] is executing */
if (chatModel.currentUser.value?.userId == currentUserId) {
chatModel.updateChats(chats)
}
}.onFailure { Log.e(TAG, it.stackTraceToString()) } }.onFailure { Log.e(TAG, it.stackTraceToString()) }
} }
} }