Skip to content

Commit d406d7a

Browse files
authored
[V5] Replace StreamCollection and LazyCachedMapCollection with Array (#993)
1 parent 891a18b commit d406d7a

21 files changed

+47
-51
lines changed

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/FileAttachmentsViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ import SwiftUI
101101
attachmentsDataSource = loadAttachments(from: messages)
102102
}
103103

104-
private func loadAttachments(from messages: LazyCachedMapCollection<ChatMessage>) -> [MonthlyFileAttachments] {
104+
private func loadAttachments(from messages: [ChatMessage]) -> [MonthlyFileAttachments] {
105105
var attachmentMappings = [String: [ChatMessageFileAttachment]]()
106106
var monthAndYearArray = [String]()
107107

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelDataSource.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import StreamChat
1313
/// - messages, the collection of updated messages.
1414
func dataSource(
1515
channelDataSource: ChannelDataSource,
16-
didUpdateMessages messages: LazyCachedMapCollection<ChatMessage>,
16+
didUpdateMessages messages: [ChatMessage],
1717
changes: [ListChange<ChatMessage>]
1818
)
1919

@@ -35,7 +35,7 @@ import StreamChat
3535
var delegate: MessagesDataSource? { get set }
3636

3737
/// List of the messages.
38-
var messages: LazyCachedMapCollection<ChatMessage> { get }
38+
var messages: [ChatMessage] { get }
3939

4040
/// Determines whether all new messages have been fetched.
4141
var hasLoadedAllNextMessages: Bool { get }
@@ -82,7 +82,7 @@ class ChatChannelDataSource: ChannelDataSource, ChatChannelControllerDelegate {
8282
let controller: ChatChannelController
8383
weak var delegate: MessagesDataSource?
8484

85-
var messages: LazyCachedMapCollection<ChatMessage> {
85+
var messages: [ChatMessage] {
8686
controller.messages
8787
}
8888

@@ -166,7 +166,7 @@ class MessageThreadDataSource: ChannelDataSource, ChatMessageControllerDelegate
166166

167167
weak var delegate: MessagesDataSource?
168168

169-
var messages: LazyCachedMapCollection<ChatMessage> {
169+
var messages: [ChatMessage] {
170170
var replies = messageController.replies
171171
if let message = messageController.message, replies.last != message {
172172
replies.append(message)

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import SwiftUI
6262
@Published var showAlertBanner = false
6363

6464
@Published public var currentDateString: String?
65-
@Published public var messages = LazyCachedMapCollection<ChatMessage>() {
65+
@Published public var messages = [ChatMessage]() {
6666
didSet {
6767
if utils.messageListConfig.groupMessages {
6868
groupMessages()
@@ -416,7 +416,7 @@ import SwiftUI
416416

417417
func dataSource(
418418
channelDataSource: ChannelDataSource,
419-
didUpdateMessages messages: LazyCachedMapCollection<ChatMessage>,
419+
didUpdateMessages messages: [ChatMessage],
420420
changes: [ListChange<ChatMessage>]
421421
) {
422422
if !isActive {

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListDateUtils.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class MessageListDateUtils {
1919
/// - Returns: optional index.
2020
func indexForMessageDate(
2121
message: ChatMessage,
22-
in messages: LazyCachedMapCollection<ChatMessage>
22+
in messages: [ChatMessage]
2323
) -> Int? {
2424
if messageListConfig.dateIndicatorPlacement != .messageList {
2525
// Index computation will be done onAppear.
@@ -36,7 +36,7 @@ class MessageListDateUtils {
3636
/// - Returns: optional index.
3737
func index(
3838
for message: ChatMessage,
39-
in messages: LazyCachedMapCollection<ChatMessage>
39+
in messages: [ChatMessage]
4040
) -> Int? {
4141
let index = messages.firstIndex { msg in
4242
msg.id == message.id
@@ -52,7 +52,7 @@ class MessageListDateUtils {
5252
/// - Returns: optional date, shown above a message.
5353
func showMessageDate(
5454
for index: Int?,
55-
in messages: LazyCachedMapCollection<ChatMessage>
55+
in messages: [ChatMessage]
5656
) -> Date? {
5757
guard let index else {
5858
return nil

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListView.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
1212

1313
var factory: Factory
1414
var channel: ChatChannel
15-
var messages: LazyCachedMapCollection<ChatMessage>
15+
var messages: [ChatMessage]
1616
var messagesGroupingInfo: [String: [String]]
1717
@Binding var scrolledId: String?
1818
@Binding var showScrollToLatestButton: Bool
@@ -65,7 +65,7 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
6565
public init(
6666
factory: Factory,
6767
channel: ChatChannel,
68-
messages: LazyCachedMapCollection<ChatMessage>,
68+
messages: [ChatMessage],
6969
messagesGroupingInfo: [String: [String]],
7070
scrolledId: Binding<String?>,
7171
showScrollToLatestButton: Binding<Bool>,
@@ -108,10 +108,7 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
108108
}
109109
skipRenderingMessageIds = messageRenderingUtil.messagesToSkipRendering(newMessages: messages)
110110
if !skipRenderingMessageIds.isEmpty {
111-
self.messages = LazyCachedMapCollection(
112-
source: messages.filter { !skipRenderingMessageIds.contains($0.id) },
113-
map: { $0 }
114-
)
111+
self.messages = messages.filter { !skipRenderingMessageIds.contains($0.id) }
115112
}
116113
}
117114

@@ -589,7 +586,7 @@ private class MessageRenderingUtil {
589586
self.previousTopMessage = previousTopMessage
590587
}
591588

592-
func messagesToSkipRendering(newMessages: LazyCachedMapCollection<ChatMessage>) -> [String] {
589+
func messagesToSkipRendering(newMessages: [ChatMessage]) -> [String] {
593590
let newTopMessage = newMessages.first
594591
if newTopMessage?.id == previousTopMessage?.id {
595592
return []

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelList.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct ChannelList<Factory: ViewFactory>: View {
1111
@Injected(\.colors) private var colors
1212

1313
private var factory: Factory
14-
var channels: LazyCachedMapCollection<ChatChannel>
14+
var channels: [ChatChannel]
1515
@Binding var selectedChannel: ChannelSelectionInfo?
1616
@Binding var swipedChannelId: String?
1717
@Binding var scrolledChannelId: String?
@@ -28,7 +28,7 @@ public struct ChannelList<Factory: ViewFactory>: View {
2828

2929
public init(
3030
factory: Factory,
31-
channels: LazyCachedMapCollection<ChatChannel>,
31+
channels: [ChatChannel],
3232
selectedChannel: Binding<ChannelSelectionInfo?>,
3333
swipedChannelId: Binding<String?>,
3434
scrolledChannelId: Binding<String?> = .constant(nil),
@@ -123,7 +123,7 @@ public struct ChannelsLazyVStack<Factory: ViewFactory>: View {
123123
@Injected(\.utils) private var utils
124124

125125
private var factory: Factory
126-
var channels: LazyCachedMapCollection<ChatChannel>
126+
var channels: [ChatChannel]
127127
@Binding var selectedChannel: ChannelSelectionInfo?
128128
@Binding var swipedChannelId: String?
129129
private var onlineIndicatorShown: @MainActor (ChatChannel) -> Bool
@@ -138,7 +138,7 @@ public struct ChannelsLazyVStack<Factory: ViewFactory>: View {
138138

139139
public init(
140140
factory: Factory,
141-
channels: LazyCachedMapCollection<ChatChannel>,
141+
channels: [ChatChannel],
142142
selectedChannel: Binding<ChannelSelectionInfo?>,
143143
swipedChannelId: Binding<String?>,
144144
onlineIndicatorShown: @escaping @MainActor (ChatChannel) -> Bool,

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import UIKit
2727
private var selectedChannelId: String?
2828

2929
/// Temporarly holding changes while message list is shown.
30-
private var queuedChannelsChanges = LazyCachedMapCollection<ChatChannel>()
30+
private var queuedChannelsChanges = [ChatChannel]()
3131

3232
private var timer: Timer?
3333

@@ -44,7 +44,7 @@ import UIKit
4444
@Published public var scrolledChannelId: String?
4545

4646
/// Published variables.
47-
@Published public var channels = LazyCachedMapCollection<ChatChannel>() {
47+
@Published public var channels = [ChatChannel]() {
4848
didSet {
4949
if !markDirty {
5050
queuedChannelsChanges = []
@@ -539,7 +539,7 @@ import UIKit
539539
}
540540

541541
private func updateChannels() {
542-
channels = controller?.channels ?? LazyCachedMapCollection<ChatChannel>()
542+
channels = controller?.channels ?? [ChatChannel]()
543543
}
544544

545545
private func handleChannelAppearance() {
@@ -586,7 +586,7 @@ import UIKit
586586
temp[index] = selected
587587
}
588588
markDirty = true
589-
channels = LazyCachedMapCollection(source: temp, map: { $0 })
589+
channels = temp
590590
}
591591

592592
private func scrollToAndOpen(channel: ChatChannel) {

Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadList.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import SwiftUI
88
/// Stateless component for the channel list.
99
/// If used directly, you should provide the thread list.
1010
public struct ThreadList<Factory: ViewFactory, HeaderView: View, FooterView: View>: View {
11-
var threads: LazyCachedMapCollection<ChatThread>
11+
var threads: [ChatThread]
1212
private var factory: Factory
1313
private var threadDestination: @MainActor (ChatThread) -> Factory.ThreadDestination
1414
@Binding private var selectedThread: ThreadSelectionInfo?
@@ -24,7 +24,7 @@ public struct ThreadList<Factory: ViewFactory, HeaderView: View, FooterView: Vie
2424

2525
public init(
2626
factory: Factory,
27-
threads: LazyCachedMapCollection<ChatThread>,
27+
threads: [ChatThread],
2828
threadDestination: @escaping @MainActor (ChatThread) -> Factory.ThreadDestination,
2929
selectedThread: Binding<ThreadSelectionInfo?>,
3030
onItemTap: @escaping (ChatThread) -> Void,
@@ -63,15 +63,15 @@ public struct ThreadsLazyVStack<Factory: ViewFactory>: View {
6363
@Injected(\.colors) private var colors
6464

6565
private var factory: Factory
66-
var threads: LazyCachedMapCollection<ChatThread>
66+
var threads: [ChatThread]
6767
private var threadDestination: @MainActor (ChatThread) -> Factory.ThreadDestination
6868
@Binding private var selectedThread: ThreadSelectionInfo?
6969
private var onItemTap: (ChatThread) -> Void
7070
private var onItemAppear: (Int) -> Void
7171

7272
public init(
7373
factory: Factory,
74-
threads: LazyCachedMapCollection<ChatThread>,
74+
threads: [ChatThread],
7575
threadDestination: @escaping @MainActor (ChatThread) -> Factory.ThreadDestination,
7676
selectedThread: Binding<ThreadSelectionInfo?>,
7777
onItemTap: @escaping (ChatThread) -> Void,

Sources/StreamChatSwiftUI/ChatThreadList/ChatThreadListViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import StreamChat
2424
@Published public var selectedThread: ThreadSelectionInfo?
2525

2626
/// The list of threads.
27-
@Published public var threads = LazyCachedMapCollection<ChatThread>()
27+
@Published public var threads = [ChatThread]()
2828

2929
/// A boolean indicating if it is loading data from the server and no local cache is available.
3030
@Published public var isLoading = false

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2659,7 +2659,6 @@
26592659
8434E58127707F19001E1B83 /* GridMediaView.swift in Sources */,
26602660
ADE0F5662CB962470053B8B9 /* ActionBannerView.swift in Sources */,
26612661
84BB4C4C2841104700CBE004 /* MessageListDateUtils.swift in Sources */,
2662-
82D64BE72AD7E5B700C5C79E /* ImageTask.swift in Sources */,
26632662
84EB881A2E8ABA610076DC17 /* ParticipantInfoView.swift in Sources */,
26642663
8465FDC12746A95700AF091E /* NoChannelsView.swift in Sources */,
26652664
C14A465B284665B100EF498E /* SDKIdentifier.swift in Sources */,

0 commit comments

Comments
 (0)