diff --git a/DemoAppSwiftUI/CustomChannelHeader.swift b/DemoAppSwiftUI/CustomChannelHeader.swift index 6ade4327..5788038a 100644 --- a/DemoAppSwiftUI/CustomChannelHeader.swift +++ b/DemoAppSwiftUI/CustomChannelHeader.swift @@ -79,7 +79,7 @@ struct CustomChannelModifier: ChannelListHeaderViewModifier { message: Text("Are you sure you want to sign out?"), primaryButton: .destructive(Text("Sign out")) { withAnimation { - chatClient.disconnect { + chatClient.logout { UnsecureRepository.shared.removeCurrentUser() DispatchQueue.main.async { AppState.shared.userState = .notLoggedIn diff --git a/DemoAppSwiftUI/DemoAppSwiftUIApp.swift b/DemoAppSwiftUI/DemoAppSwiftUIApp.swift index ee0759b5..234e6ee1 100644 --- a/DemoAppSwiftUI/DemoAppSwiftUIApp.swift +++ b/DemoAppSwiftUI/DemoAppSwiftUIApp.swift @@ -15,8 +15,10 @@ struct DemoAppSwiftUIApp: App { @ObservedObject var appState = AppState.shared @ObservedObject var notificationsHandler = NotificationsHandler.shared - @State var channelListController: ChatChannelListController? - + var channelListController: ChatChannelListController? { + appState.channelListController + } + var body: some Scene { WindowGroup { switch appState.userState { @@ -51,7 +53,7 @@ struct DemoAppSwiftUIApp: App { .init(key: .updatedAt) ] ) - channelListController = chatClient.channelListController(query: channelListQuery) + appState.channelListController = chatClient.channelListController(query: channelListQuery) } notificationsHandler.setupRemoteNotifications() } @@ -61,7 +63,15 @@ struct DemoAppSwiftUIApp: App { class AppState: ObservableObject { - @Published var userState: UserState = .launchAnimation + @Published var userState: UserState = .launchAnimation { + willSet { + if newValue == .notLoggedIn && userState == .loggedIn { + channelListController = nil + } + } + } + + var channelListController: ChatChannelListController? static let shared = AppState()