ios: prevent call to apiContactInfo after the app is suspended

This commit is contained in:
Evgeny Poberezkin
2024-03-29 19:43:16 +00:00
parent 42a35e8c72
commit 1410b4bd85
2 changed files with 5 additions and 3 deletions
+4 -1
View File
@@ -17,6 +17,7 @@ struct ChatView: View {
@Environment(\.colorScheme) var colorScheme
@Environment(\.dismiss) var dismiss
@Environment(\.presentationMode) var presentationMode
@Environment(\.scenePhase) var scenePhase
@State @ObservedObject var chat: Chat
@State private var showChatInfoSheet: Bool = false
@State private var showAddMembersSheet: Bool = false
@@ -234,7 +235,9 @@ struct ChatView: View {
private func initChatView() {
let cInfo = chat.chatInfo
if case let .direct(contact) = cInfo {
// This check prevents the call to apiContactInfo after the app is suspended, and the database is closed.
if case .active = scenePhase,
case let .direct(contact) = cInfo {
Task {
do {
let (stats, _) = try await apiContactInfo(chat.chatInfo.apiId)
@@ -92,8 +92,7 @@ struct UserPicker: View {
.opacity(userPickerVisible ? 1.0 : 0.0)
.onAppear {
do {
// This check prevents this after the app is suspended, and the database is closed.
// Unclear why it happens.
// This check prevents the call of listUsers after the app is suspended, and the database is closed.
if case .active = scenePhase {
m.users = try listUsers()
}