Skip to content

Commit

Permalink
Fix media and files attachments not showing in channel info view
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmitrevski committed Jul 22, 2024
1 parent 84ed0cb commit 6ba59d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -28,6 +28,7 @@ class FileAttachmentsViewModel: ObservableObject {

dateFormatter.dateFormat = "MMMM yyyy"
messageSearchController = chatClient.messageSearchController()
messageSearchController.delegate = self
loadMessages()
}

Expand Down Expand Up @@ -73,6 +74,12 @@ class FileAttachmentsViewModel: ObservableObject {
}
}
}

// MARK: - ChatMessageSearchControllerDelegate

func controller(_ controller: ChatMessageSearchController, didChangeMessages changes: [ListChange<ChatMessage>]) {
updateAttachments()
}

private func loadMessages() {
let query = MessageSearchQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +27,7 @@ class MediaAttachmentsViewModel: ObservableObject {
init(channel: ChatChannel) {
self.channel = channel
messageSearchController = chatClient.messageSearchController()
messageSearchController.delegate = self
loadMessages()
}

Expand All @@ -53,6 +54,12 @@ class MediaAttachmentsViewModel: ObservableObject {
}
}
}

// MARK: - ChatMessageSearchControllerDelegate

func controller(_ controller: ChatMessageSearchController, didChangeMessages changes: [ListChange<ChatMessage>]) {
updateAttachments()
}

private func loadMessages() {
let query = MessageSearchQuery(
Expand Down

0 comments on commit 6ba59d0

Please sign in to comment.