From 6ba59d03e9e2a3adf6256b917a6700151c17c4a4 Mon Sep 17 00:00:00 2001 From: Stream Bot Date: Mon, 22 Jul 2024 12:46:34 +0200 Subject: [PATCH] Fix media and files attachments not showing in channel info view --- CHANGELOG.md | 3 ++- .../ChannelInfo/FileAttachmentsViewModel.swift | 11 +++++++++-- .../ChannelInfo/MediaAttachmentsViewModel.swift | 9 ++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49a5e7d2..0042dafa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). # Upcoming -### 🔄 Changed +### 🐞 Fixed +- Media and files attachments not showing in channel info view [#552](https://github.com/GetStream/stream-chat-swiftui/pull/552) # [4.60.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.60.0) _July 19, 2024_ diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsViewModel.swift index 7d1b28a4..2a9c0ee8 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsViewModel.swift @@ -7,8 +7,8 @@ import StreamChat import SwiftUI /// View model for the `FileAttachmentsView`. -class FileAttachmentsViewModel: ObservableObject { - +class FileAttachmentsViewModel: ObservableObject, ChatMessageSearchControllerDelegate { + @Published var loading = false @Published var attachmentsDataSource = [MonthlyFileAttachments]() @Published var selectedAttachment: ChatMessageFileAttachment? @@ -28,6 +28,7 @@ class FileAttachmentsViewModel: ObservableObject { dateFormatter.dateFormat = "MMMM yyyy" messageSearchController = chatClient.messageSearchController() + messageSearchController.delegate = self loadMessages() } @@ -73,6 +74,12 @@ class FileAttachmentsViewModel: ObservableObject { } } } + + // MARK: - ChatMessageSearchControllerDelegate + + func controller(_ controller: ChatMessageSearchController, didChangeMessages changes: [ListChange]) { + updateAttachments() + } private func loadMessages() { let query = MessageSearchQuery( diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/MediaAttachmentsViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/MediaAttachmentsViewModel.swift index ade8e448..22f8eca9 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/MediaAttachmentsViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/MediaAttachmentsViewModel.swift @@ -7,7 +7,7 @@ import StreamChat import SwiftUI /// View model for the `MediaAttachmentsView`. -class MediaAttachmentsViewModel: ObservableObject { +class MediaAttachmentsViewModel: ObservableObject, ChatMessageSearchControllerDelegate { @Published var mediaItems = [MediaItem]() @Published var loading = false @@ -27,6 +27,7 @@ class MediaAttachmentsViewModel: ObservableObject { init(channel: ChatChannel) { self.channel = channel messageSearchController = chatClient.messageSearchController() + messageSearchController.delegate = self loadMessages() } @@ -53,6 +54,12 @@ class MediaAttachmentsViewModel: ObservableObject { } } } + + // MARK: - ChatMessageSearchControllerDelegate + + func controller(_ controller: ChatMessageSearchController, didChangeMessages changes: [ListChange]) { + updateAttachments() + } private func loadMessages() { let query = MessageSearchQuery(