Skip to content

Commit 56efc8c

Browse files
Fixed bug with updating channels from message list
1 parent 5bc110d commit 56efc8c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Sources/StreamChatSwiftUI/ChatChannelList/ChatChannelListViewModel.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
4141
/// Checks if the queued changes are completely applied.
4242
private var markDirty = false
4343

44+
/// Index of the selected channel.
45+
private var selectedChannelIndex: Int?
46+
4447
/// Published variables.
4548
@Published public var channels = LazyCachedMapCollection<ChatChannel>() {
4649
didSet {
@@ -61,6 +64,15 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
6164
channels = queuedChannelsChanges
6265
}
6366
}
67+
if newValue == nil {
68+
selectedChannelIndex = nil
69+
} else {
70+
DispatchQueue.global(qos: .default).async { [unowned self] in
71+
selectedChannelIndex = channels.firstIndex(where: { channel in
72+
channel.cid.rawValue == selectedChannel?.channel.cid.rawValue
73+
})
74+
}
75+
}
6476
}
6577
}
6678

@@ -373,7 +385,7 @@ open class ChatChannelListViewModel: ObservableObject, ChatChannelListController
373385
}
374386

375387
private func updateChannelsIfNeeded() {
376-
if utils.messageListConfig.updateChannelsFromMessageList {
388+
if utils.messageListConfig.updateChannelsFromMessageList && ((selectedChannelIndex ?? 0) < 8) {
377389
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
378390
self?.handleChannelAppearance()
379391
}

0 commit comments

Comments
 (0)