android: prevent race when changing active user (#1913)
This commit is contained in:
parent
f24035a99d
commit
aa6011a196
@ -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()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user