diff --git a/apps/ios/Shared/Views/ChatList/ChatListView.swift b/apps/ios/Shared/Views/ChatList/ChatListView.swift index ecbd89de63..91e280f76a 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListView.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListView.swift @@ -20,7 +20,6 @@ struct ChatListView: View { @State private var newChatMenuOption: NewChatMenuOption? = nil @State private var userPickerVisible = false @State private var showConnectDesktop = false - @State private var showServersSummary = false @AppStorage(DEFAULT_SHOW_UNREAD_AND_FAVORITES) private var showUnreadAndFavorites = false var body: some View { @@ -63,9 +62,6 @@ struct ChatListView: View { .sheet(isPresented: $showConnectDesktop) { ConnectDesktopView() } - .sheet(isPresented: $showServersSummary) { - ServersSummaryView() - } } private var chatListView: some View { @@ -119,7 +115,7 @@ struct ChatListView: View { HStack(spacing: 4) { Text("Chats") .font(.headline) - subscriptionsStatusIcon() + SubsStatusIndicator() } .frame(maxWidth: .infinity, alignment: .center) } @@ -133,15 +129,6 @@ struct ChatListView: View { } } - private func subscriptionsStatusIcon() -> some View { - Button { - showServersSummary = true - } label: { - // TODO backend to periodically send updates to model - SubscriptionStatusView(activeSubs: 100, pendingSubs: 0) - } - } - @ViewBuilder private var chatList: some View { let cs = filteredChats() ZStack { @@ -276,6 +263,34 @@ struct ChatListView: View { } } +struct SubsStatusIndicator: View { + @State private var subs: SMPServerSubs = SMPServerSubs(ssActive: 0, ssPending: 0) + @State private var showServersSummary = false + + var body: some View { + Button { + showServersSummary = true + } label: { + SubscriptionStatusView(activeSubs: subs.ssActive, pendingSubs: subs.ssPending) + } + .onAppear { + // TODO update + getSubsSummary() + } + .sheet(isPresented: $showServersSummary) { + ServersSummaryView() + } + } + + private func getSubsSummary() { + do { + subs = try getAgentSubsSummary() + } catch let error { + logger.error("getAgentSubsSummary error: \(responseError(error))") + } + } +} + struct ChatListSearchBar: View { @EnvironmentObject var m: ChatModel @Binding var searchMode: Bool diff --git a/apps/ios/SimpleXChat/APITypes.swift b/apps/ios/SimpleXChat/APITypes.swift index c6e9f47b58..c430e38a21 100644 --- a/apps/ios/SimpleXChat/APITypes.swift +++ b/apps/ios/SimpleXChat/APITypes.swift @@ -2297,6 +2297,11 @@ public struct ServerSessions: Codable { public struct SMPServerSubs: Codable { public var ssActive: Int public var ssPending: Int + + public init(ssActive: Int, ssPending: Int) { + self.ssActive = ssActive + self.ssPending = ssPending + } } public struct AgentSMPServerStatsData: Codable {