Skip to content

Commit b71f723

Browse files
Added sync config for channel controllers
1 parent 6709e82 commit b71f723

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
101101
scrollToMessage: ChatMessage? = nil
102102
) {
103103
self.channelController = channelController
104-
channelController.synchronize()
104+
if InjectedValues[\.utils].shouldSyncChannelControllerOnAppear(channelController) {
105+
channelController.synchronize()
106+
}
105107
if let messageController = messageController {
106108
self.messageController = messageController
107109
messageController.synchronize()

Sources/StreamChatSwiftUI/Utils.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44

55
import Foundation
6+
import StreamChat
67

78
/// Class providing implementations of several utilities used in the SDK.
89
/// The default implementations can be replaced in the init method, or directly via the variables.
@@ -20,6 +21,7 @@ public class Utils {
2021
public var commandsConfig: CommandsConfig
2122
public var messageListConfig: MessageListConfig
2223
public var composerConfig: ComposerConfig
24+
public var shouldSyncChannelControllerOnAppear: (ChatChannelController) -> Bool
2325

2426
var messageCachingUtils = MessageCachingUtils()
2527

@@ -36,7 +38,8 @@ public class Utils {
3638
commandsConfig: CommandsConfig = DefaultCommandsConfig(),
3739
messageListConfig: MessageListConfig = MessageListConfig(),
3840
composerConfig: ComposerConfig = ComposerConfig(),
39-
channelNamer: @escaping ChatChannelNamer = DefaultChatChannelNamer()
41+
channelNamer: @escaping ChatChannelNamer = DefaultChatChannelNamer(),
42+
shouldSyncChannelControllerOnAppear: @escaping (ChatChannelController) -> Bool = { _ in true }
4043
) {
4144
self.dateFormatter = dateFormatter
4245
self.videoPreviewLoader = videoPreviewLoader
@@ -51,5 +54,6 @@ public class Utils {
5154
self.commandsConfig = commandsConfig
5255
self.messageListConfig = messageListConfig
5356
self.composerConfig = composerConfig
57+
self.shouldSyncChannelControllerOnAppear = shouldSyncChannelControllerOnAppear
5458
}
5559
}

0 commit comments

Comments
 (0)