diff --git a/apps/ios/Shared/Views/Chat/ChatInfoView.swift b/apps/ios/Shared/Views/Chat/ChatInfoView.swift index c070e483e2..855f5193d7 100644 --- a/apps/ios/Shared/Views/Chat/ChatInfoView.swift +++ b/apps/ios/Shared/Views/Chat/ChatInfoView.swift @@ -93,10 +93,10 @@ struct ChatInfoView: View { @Environment(\.dismiss) var dismiss: DismissAction @ObservedObject var chat: Chat @State var contact: Contact - @Binding var connectionStats: ConnectionStats? - @Binding var customUserProfile: Profile? @State var localAlias: String - @Binding var connectionCode: String? + @State private var connectionStats: ConnectionStats? = nil + @State private var customUserProfile: Profile? = nil + @State private var connectionCode: String? = nil @FocusState private var aliasTextFieldFocused: Bool @State private var alert: ChatInfoViewAlert? = nil @State private var showDeleteContactActionSheet = false @@ -235,6 +235,23 @@ struct ChatInfoView: View { sendReceiptsUserDefault = currentUser.sendRcptsContacts } sendReceipts = SendReceipts.fromBool(contact.chatSettings.sendRcpts, userDefault: sendReceiptsUserDefault) + + Task { + do { + let (stats, profile) = try await apiContactInfo(chat.chatInfo.apiId) + let (ct, code) = try await apiGetContactCode(chat.chatInfo.apiId) + await MainActor.run { + connectionStats = stats + customUserProfile = profile + connectionCode = code + if contact.activeConn?.connectionCode != ct.activeConn?.connectionCode { + chat.chatInfo = .direct(contact: ct) + } + } + } catch let error { + logger.error("apiContactInfo or apiGetContactCode error: \(responseError(error))") + } + } } .alert(item: $alert) { alertItem in switch(alertItem) { @@ -582,10 +599,7 @@ struct ChatInfoView_Previews: PreviewProvider { ChatInfoView( chat: Chat(chatInfo: ChatInfo.sampleData.direct, chatItems: []), contact: Contact.sampleData, - connectionStats: Binding.constant(nil), - customUserProfile: Binding.constant(nil), - localAlias: "", - connectionCode: Binding.constant(nil) + localAlias: "" ) } } diff --git a/apps/ios/Shared/Views/Chat/ChatView.swift b/apps/ios/Shared/Views/Chat/ChatView.swift index 5ec69412a6..71cba592a7 100644 --- a/apps/ios/Shared/Views/Chat/ChatView.swift +++ b/apps/ios/Shared/Views/Chat/ChatView.swift @@ -23,9 +23,6 @@ struct ChatView: View { @State private var showAddMembersSheet: Bool = false @State private var composeState = ComposeState() @State private var keyboardVisible = false - @State private var connectionStats: ConnectionStats? - @State private var customUserProfile: Profile? - @State private var connectionCode: String? @State private var tableView: UITableView? @State private var loadingItems = false @State private var firstPage = false @@ -111,32 +108,12 @@ struct ChatView: View { ToolbarItem(placement: .principal) { if case let .direct(contact) = cInfo { Button { - Task { - do { - let (stats, profile) = try await apiContactInfo(chat.chatInfo.apiId) - let (ct, code) = try await apiGetContactCode(chat.chatInfo.apiId) - await MainActor.run { - connectionStats = stats - customUserProfile = profile - connectionCode = code - if contact.activeConn?.connectionCode != ct.activeConn?.connectionCode { - chat.chatInfo = .direct(contact: ct) - } - } - } catch let error { - logger.error("apiContactInfo or apiGetContactCode error: \(responseError(error))") - } - await MainActor.run { showChatInfoSheet = true } - } + showChatInfoSheet = true } label: { ChatInfoToolbar(chat: chat) } - .sheet(isPresented: $showChatInfoSheet, onDismiss: { - connectionStats = nil - customUserProfile = nil - connectionCode = nil - }) { - ChatInfoView(chat: chat, contact: contact, connectionStats: $connectionStats, customUserProfile: $customUserProfile, localAlias: chat.chatInfo.localAlias, connectionCode: $connectionCode) + .sheet(isPresented: $showChatInfoSheet) { + ChatInfoView(chat: chat, contact: contact, localAlias: chat.chatInfo.localAlias) } } else if case let .group(groupInfo) = cInfo { Button { diff --git a/apps/ios/Shared/Views/Chat/Contacts/ContactListNavLink.swift b/apps/ios/Shared/Views/Chat/Contacts/ContactListNavLink.swift index 5a5a9ee108..59f98be89d 100644 --- a/apps/ios/Shared/Views/Chat/Contacts/ContactListNavLink.swift +++ b/apps/ios/Shared/Views/Chat/Contacts/ContactListNavLink.swift @@ -18,11 +18,7 @@ struct ContactListNavLink: View { ChatInfoView( chat: chat, contact: contact, - // TODO - connectionStats: Binding.constant(nil), - customUserProfile: Binding.constant(nil), - localAlias: "", - connectionCode: Binding.constant(nil) + localAlias: chat.chatInfo.localAlias ) } label: { HStack{