diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsViewModel.swift index c8a9296c..2c5933a6 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsViewModel.swift @@ -101,7 +101,7 @@ import SwiftUI attachmentsDataSource = loadAttachments(from: messages) } - private func loadAttachments(from messages: LazyCachedMapCollection) -> [MonthlyFileAttachments] { + private func loadAttachments(from messages: [ChatMessage]) -> [MonthlyFileAttachments] { var attachmentMappings = [String: [ChatMessageFileAttachment]]() var monthAndYearArray = [String]() diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelDataSource.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelDataSource.swift index 7c69877e..43f377fe 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelDataSource.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelDataSource.swift @@ -13,7 +13,7 @@ import StreamChat /// - messages, the collection of updated messages. func dataSource( channelDataSource: ChannelDataSource, - didUpdateMessages messages: LazyCachedMapCollection, + didUpdateMessages messages: [ChatMessage], changes: [ListChange] ) @@ -35,7 +35,7 @@ import StreamChat var delegate: MessagesDataSource? { get set } /// List of the messages. - var messages: LazyCachedMapCollection { get } + var messages: [ChatMessage] { get } /// Determines whether all new messages have been fetched. var hasLoadedAllNextMessages: Bool { get } @@ -82,7 +82,7 @@ class ChatChannelDataSource: ChannelDataSource, ChatChannelControllerDelegate { let controller: ChatChannelController weak var delegate: MessagesDataSource? - var messages: LazyCachedMapCollection { + var messages: [ChatMessage] { controller.messages } @@ -166,7 +166,7 @@ class MessageThreadDataSource: ChannelDataSource, ChatMessageControllerDelegate weak var delegate: MessagesDataSource? - var messages: LazyCachedMapCollection { + var messages: [ChatMessage] { var replies = messageController.replies if let message = messageController.message, replies.last != message { replies.append(message) diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift index a545644f..8bbaef0a 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift @@ -62,7 +62,7 @@ import SwiftUI @Published var showAlertBanner = false @Published public var currentDateString: String? - @Published public var messages = LazyCachedMapCollection() { + @Published public var messages = [ChatMessage]() { didSet { if utils.messageListConfig.groupMessages { groupMessages() @@ -416,7 +416,7 @@ import SwiftUI func dataSource( channelDataSource: ChannelDataSource, - didUpdateMessages messages: LazyCachedMapCollection, + didUpdateMessages messages: [ChatMessage], changes: [ListChange] ) { if !isActive { diff --git a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListDateUtils.swift b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListDateUtils.swift index f2f7788a..dd099956 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListDateUtils.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListDateUtils.swift @@ -19,7 +19,7 @@ class MessageListDateUtils { /// - Returns: optional index. func indexForMessageDate( message: ChatMessage, - in messages: LazyCachedMapCollection + in messages: [ChatMessage] ) -> Int? { if messageListConfig.dateIndicatorPlacement != .messageList { // Index computation will be done onAppear. @@ -36,7 +36,7 @@ class MessageListDateUtils { /// - Returns: optional index. func index( for message: ChatMessage, - in messages: LazyCachedMapCollection + in messages: [ChatMessage] ) -> Int? { let index = messages.firstIndex { msg in msg.id == message.id @@ -52,7 +52,7 @@ class MessageListDateUtils { /// - Returns: optional date, shown above a message. func showMessageDate( for index: Int?, - in messages: LazyCachedMapCollection + in messages: [ChatMessage] ) -> Date? { guard let index else { return nil diff --git a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift index 85b8c050..c563e43e 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift @@ -12,7 +12,7 @@ public struct MessageListView: View, KeyboardReadable { var factory: Factory var channel: ChatChannel - var messages: LazyCachedMapCollection + var messages: [ChatMessage] var messagesGroupingInfo: [String: [String]] @Binding var scrolledId: String? @Binding var showScrollToLatestButton: Bool @@ -65,7 +65,7 @@ public struct MessageListView: View, KeyboardReadable { public init( factory: Factory, channel: ChatChannel, - messages: LazyCachedMapCollection, + messages: [ChatMessage], messagesGroupingInfo: [String: [String]], scrolledId: Binding, showScrollToLatestButton: Binding, @@ -108,10 +108,7 @@ public struct MessageListView: View, KeyboardReadable { } skipRenderingMessageIds = messageRenderingUtil.messagesToSkipRendering(newMessages: messages) if !skipRenderingMessageIds.isEmpty { - self.messages = LazyCachedMapCollection( - source: messages.filter { !skipRenderingMessageIds.contains($0.id) }, - map: { $0 } - ) + self.messages = messages.filter { !skipRenderingMessageIds.contains($0.id) } } } @@ -589,7 +586,7 @@ private class MessageRenderingUtil { self.previousTopMessage = previousTopMessage } - func messagesToSkipRendering(newMessages: LazyCachedMapCollection) -> [String] { + func messagesToSkipRendering(newMessages: [ChatMessage]) -> [String] { let newTopMessage = newMessages.first if newTopMessage?.id == previousTopMessage?.id { return [] diff --git a/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelList.swift b/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelList.swift index 7013ffab..c9e2a738 100644 --- a/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelList.swift +++ b/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelList.swift @@ -11,7 +11,7 @@ public struct ChannelList: View { @Injected(\.colors) private var colors private var factory: Factory - var channels: LazyCachedMapCollection + var channels: [ChatChannel] @Binding var selectedChannel: ChannelSelectionInfo? @Binding var swipedChannelId: String? @Binding var scrolledChannelId: String? @@ -28,7 +28,7 @@ public struct ChannelList: View { public init( factory: Factory, - channels: LazyCachedMapCollection, + channels: [ChatChannel], selectedChannel: Binding, swipedChannelId: Binding, scrolledChannelId: Binding = .constant(nil), @@ -123,7 +123,7 @@ public struct ChannelsLazyVStack: View { @Injected(\.utils) private var utils private var factory: Factory - var channels: LazyCachedMapCollection + var channels: [ChatChannel] @Binding var selectedChannel: ChannelSelectionInfo? @Binding var swipedChannelId: String? private var onlineIndicatorShown: @MainActor (ChatChannel) -> Bool @@ -138,7 +138,7 @@ public struct ChannelsLazyVStack: View { public init( factory: Factory, - channels: LazyCachedMapCollection, + channels: [ChatChannel], selectedChannel: Binding, swipedChannelId: Binding, onlineIndicatorShown: @escaping @MainActor (ChatChannel) -> Bool, diff --git a/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift index f0ef2805..e728f532 100644 --- a/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift @@ -27,7 +27,7 @@ import UIKit private var selectedChannelId: String? /// Temporarly holding changes while message list is shown. - private var queuedChannelsChanges = LazyCachedMapCollection() + private var queuedChannelsChanges = [ChatChannel]() private var timer: Timer? @@ -44,7 +44,7 @@ import UIKit @Published public var scrolledChannelId: String? /// Published variables. - @Published public var channels = LazyCachedMapCollection() { + @Published public var channels = [ChatChannel]() { didSet { if !markDirty { queuedChannelsChanges = [] @@ -539,7 +539,7 @@ import UIKit } private func updateChannels() { - channels = controller?.channels ?? LazyCachedMapCollection() + channels = controller?.channels ?? [ChatChannel]() } private func handleChannelAppearance() { @@ -586,7 +586,7 @@ import UIKit temp[index] = selected } markDirty = true - channels = LazyCachedMapCollection(source: temp, map: { $0 }) + channels = temp } private func scrollToAndOpen(channel: ChatChannel) { diff --git a/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadList.swift b/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadList.swift index c541ccb1..a087a8a6 100644 --- a/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadList.swift +++ b/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadList.swift @@ -8,7 +8,7 @@ import SwiftUI /// Stateless component for the channel list. /// If used directly, you should provide the thread list. public struct ThreadList: View { - var threads: LazyCachedMapCollection + var threads: [ChatThread] private var factory: Factory private var threadDestination: @MainActor (ChatThread) -> Factory.ThreadDestination @Binding private var selectedThread: ThreadSelectionInfo? @@ -24,7 +24,7 @@ public struct ThreadList, + threads: [ChatThread], threadDestination: @escaping @MainActor (ChatThread) -> Factory.ThreadDestination, selectedThread: Binding, onItemTap: @escaping (ChatThread) -> Void, @@ -63,7 +63,7 @@ public struct ThreadsLazyVStack: View { @Injected(\.colors) private var colors private var factory: Factory - var threads: LazyCachedMapCollection + var threads: [ChatThread] private var threadDestination: @MainActor (ChatThread) -> Factory.ThreadDestination @Binding private var selectedThread: ThreadSelectionInfo? private var onItemTap: (ChatThread) -> Void @@ -71,7 +71,7 @@ public struct ThreadsLazyVStack: View { public init( factory: Factory, - threads: LazyCachedMapCollection, + threads: [ChatThread], threadDestination: @escaping @MainActor (ChatThread) -> Factory.ThreadDestination, selectedThread: Binding, onItemTap: @escaping (ChatThread) -> Void, diff --git a/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift b/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift index 764b8ac2..867e1bec 100644 --- a/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift @@ -24,7 +24,7 @@ import StreamChat @Published public var selectedThread: ThreadSelectionInfo? /// The list of threads. - @Published public var threads = LazyCachedMapCollection() + @Published public var threads = [ChatThread]() /// A boolean indicating if it is loading data from the server and no local cache is available. @Published public var isLoading = false diff --git a/StreamChatSwiftUI.xcodeproj/project.pbxproj b/StreamChatSwiftUI.xcodeproj/project.pbxproj index f5fabfc4..1b6f9c30 100644 --- a/StreamChatSwiftUI.xcodeproj/project.pbxproj +++ b/StreamChatSwiftUI.xcodeproj/project.pbxproj @@ -2659,7 +2659,6 @@ 8434E58127707F19001E1B83 /* GridMediaView.swift in Sources */, ADE0F5662CB962470053B8B9 /* ActionBannerView.swift in Sources */, 84BB4C4C2841104700CBE004 /* MessageListDateUtils.swift in Sources */, - 82D64BE72AD7E5B700C5C79E /* ImageTask.swift in Sources */, 84EB881A2E8ABA610076DC17 /* ParticipantInfoView.swift in Sources */, 8465FDC12746A95700AF091E /* NoChannelsView.swift in Sources */, C14A465B284665B100EF498E /* SDKIdentifier.swift in Sources */, diff --git a/StreamChatSwiftUITests/Infrastructure/Mocks/ChatMessageControllerSUI_Mock.swift b/StreamChatSwiftUITests/Infrastructure/Mocks/ChatMessageControllerSUI_Mock.swift index b9affce9..5473fad2 100644 --- a/StreamChatSwiftUITests/Infrastructure/Mocks/ChatMessageControllerSUI_Mock.swift +++ b/StreamChatSwiftUITests/Infrastructure/Mocks/ChatMessageControllerSUI_Mock.swift @@ -35,8 +35,8 @@ public class ChatMessageControllerSUI_Mock: ChatMessageController, @unchecked Se } public var replies_mock: [ChatMessage]? - override public var replies: LazyCachedMapCollection { - replies_mock.map { $0.lazyCachedMap { $0 } } ?? super.replies + override public var replies: [ChatMessage] { + replies_mock ?? super.replies } public var state_mock: State? diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChannelInfoMockUtils.swift b/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChannelInfoMockUtils.swift index f6eaf246..91161cf8 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChannelInfoMockUtils.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChannelInfoMockUtils.swift @@ -48,7 +48,7 @@ enum ChannelInfoMockUtils { static func generateMessagesWithAttachments( withImages: Int = 0, withVideos: Int = 0 - ) -> LazyCachedMapCollection { + ) -> [ChatMessage] { var result = [ChatMessage]() for i in 0.. LazyCachedMapCollection { + ) -> [ChatMessage] { var result = [ChatMessage]() for i in 0.. LazyCachedMapCollection { + ) -> [ChatMessage] { var result = [ChatMessage]() for i in 0.. [ChatUser] { diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/FileAttachmentsViewModel_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/FileAttachmentsViewModel_Tests.swift index 968aa12f..f88cd33c 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/FileAttachmentsViewModel_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/FileAttachmentsViewModel_Tests.swift @@ -41,7 +41,7 @@ import XCTest let additional = Array(ChannelInfoMockUtils.generateMessagesWithFileAttachments(count: 20)) var current = Array(messages) current.append(contentsOf: additional) - messages = LazyCachedMapCollection(source: current) { $0 } + messages = current messageSearchController.messages_mock = messages // Initial load, when only the 5th attachment is displayed. diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelDataSource_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelDataSource_Tests.swift index 6d2c4e9b..6c66a3b5 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelDataSource_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelDataSource_Tests.swift @@ -234,7 +234,7 @@ import XCTest func dataSource( channelDataSource: ChannelDataSource, - didUpdateMessages messages: LazyCachedMapCollection, + didUpdateMessages messages: [ChatMessage], changes: [ListChange] ) { updateMessagesCalled = true diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelViewModel_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelViewModel_Tests.swift index 13b58189..e1189672 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelViewModel_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelViewModel_Tests.swift @@ -210,7 +210,7 @@ import XCTest viewModel.messageSentTapped() viewModel.dataSource( channelDataSource: ChatChannelDataSource(controller: channelController), - didUpdateMessages: LazyCachedMapCollection(elements: messages), + didUpdateMessages: messages, changes: [ .insert(messages[0], index: .init(item: 0, section: 0)), .update(messages[1], index: .init(item: 1, section: 0)) @@ -549,7 +549,7 @@ import XCTest let message3 = ChatMessage.mock() let channelController = makeChannelController(messages: [message1, message2]) let viewModel = ChatChannelViewModel(channelController: channelController) - let newMessages = LazyCachedMapCollection(elements: [message1, message2, message3]) + let newMessages = [message1, message2, message3] // When viewModel.dataSource( diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/MessageListDateUtils_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannel/MessageListDateUtils_Tests.swift index ca505950..af667dd8 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/MessageListDateUtils_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/MessageListDateUtils_Tests.swift @@ -29,9 +29,9 @@ class MessageListDateUtils_Tests: StreamChatTestCase { createdAt: Date(timeIntervalSince1970: -100_000) ) - private lazy var messages = LazyCachedMapCollection(source: [testMessage], map: { $0 }) - private lazy var messagesSameDay = LazyCachedMapCollection(source: [testMessage, testMessageSameDay], map: { $0 }) - private lazy var messagesDifferentDay = LazyCachedMapCollection(source: [testMessage, testMessageOtherDay], map: { $0 }) + private lazy var messages = [testMessage] + private lazy var messagesSameDay = [testMessage, testMessageSameDay] + private lazy var messagesDifferentDay = [testMessage, testMessageOtherDay] func test_indexForMessageDate_messageListConfig() { // Given diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewAvatars_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewAvatars_Tests.swift index a44f73d8..b89292b0 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewAvatars_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewAvatars_Tests.swift @@ -84,7 +84,7 @@ import XCTest text: "Test", author: .mock(id: .unique) )] - let messages = LazyCachedMapCollection(source: temp, map: { $0 }) + let messages = temp let messageListView = MessageListView( factory: DefaultViewFactory.shared, channel: channel, diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewNewMessages_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewNewMessages_Tests.swift index 3aade5e4..57163a09 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewNewMessages_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/MessageListViewNewMessages_Tests.swift @@ -99,7 +99,7 @@ import XCTest messages: [ChatMessage], channel: ChatChannel ) -> some View { - let messages = LazyCachedMapCollection(source: messages, map: { $0 }) + let messages = messages let messageListView = MessageListView( factory: DefaultViewFactory.shared, channel: channel, diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/MessageListView_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannel/MessageListView_Tests.swift index 863529a0..b42fcb7e 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/MessageListView_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/MessageListView_Tests.swift @@ -118,7 +118,7 @@ import XCTest author: .mock(id: .unique), reactionScores: reactions )] - let messages = LazyCachedMapCollection(source: temp, map: { $0 }) + let messages = temp let messageListView = MessageListView( factory: DefaultViewFactory.shared, channel: channel, diff --git a/StreamChatSwiftUITests/Tests/ChatThreadList/ChatThreadListView_Tests.swift b/StreamChatSwiftUITests/Tests/ChatThreadList/ChatThreadListView_Tests.swift index be96099b..c2ad773c 100644 --- a/StreamChatSwiftUITests/Tests/ChatThreadList/ChatThreadListView_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatThreadList/ChatThreadListView_Tests.swift @@ -202,7 +202,7 @@ private class MockChatThreadListViewModel: ChatThreadListViewModel { hasNewThreads: Bool ) { self.init(threadListController: nil, eventsController: nil) - self.threads = LazyCachedMapCollection(elements: threads) + self.threads = threads self.isLoading = isLoading self.isReloading = isReloading self.isEmpty = isEmpty diff --git a/StreamChatSwiftUITestsApp/CustomChannelHeader.swift b/StreamChatSwiftUITestsApp/CustomChannelHeader.swift index d311b522..f3b2d03a 100644 --- a/StreamChatSwiftUITestsApp/CustomChannelHeader.swift +++ b/StreamChatSwiftUITestsApp/CustomChannelHeader.swift @@ -58,7 +58,7 @@ struct CustomChannelModifier: ChannelListHeaderViewModifier { message: Text("Are you sure you want to sign out?"), primaryButton: .destructive(Text("Sign out")) { withAnimation { - Task { await chatClient.disconnect() } + chatClient.disconnect {} AppState.shared.userState = .notLoggedIn } },