11//
2- // Copyright © 2023 Stream.io Inc. All rights reserved.
2+ // Copyright © 2024 Stream.io Inc. All rights reserved.
33//
44
55import StreamChat
@@ -14,6 +14,8 @@ struct DemoAppSwiftUIApp: App {
1414
1515 @ObservedObject var appState = AppState . shared
1616 @ObservedObject var notificationsHandler = NotificationsHandler . shared
17+
18+ @State var channelListController : ChatChannelListController ?
1719
1820 var body : some Scene {
1921 WindowGroup {
@@ -26,17 +28,31 @@ struct DemoAppSwiftUIApp: App {
2628 if notificationsHandler. notificationChannelId != nil {
2729 ChatChannelListView (
2830 viewFactory: DemoAppFactory . shared,
31+ channelListController: channelListController,
2932 selectedChannelId: notificationsHandler. notificationChannelId
3033 )
3134 } else {
3235 ChatChannelListView (
33- viewFactory: DemoAppFactory . shared
36+ viewFactory: DemoAppFactory . shared,
37+ channelListController: channelListController
3438 )
3539 }
3640 }
3741 }
3842 . onChange ( of: appState. userState) { newValue in
3943 if newValue == . loggedIn {
44+ if let currentUserId = chatClient. currentUserId {
45+ let pinnedByKey = ChatChannel . isPinnedBy ( keyForUserId: currentUserId)
46+ let channelListQuery = ChannelListQuery (
47+ filter: . containMembers( userIds: [ currentUserId] ) ,
48+ sort: [
49+ . init( key: . custom( keyPath: \. isPinned, key: pinnedByKey) , isAscending: true ) ,
50+ . init( key: . lastMessageAt) ,
51+ . init( key: . updatedAt)
52+ ]
53+ )
54+ channelListController = chatClient. channelListController ( query: channelListQuery)
55+ }
4056 notificationsHandler. setupRemoteNotifications ( )
4157 }
4258 }
0 commit comments