2 ChatChannelListController filter
Closed this issue · 2 comments
Hello
What did you do?
I have 2 different ChatChannelListControllers with their own filters.
I have a currentController variable that I synchronize according to the tab I'm displaying.
func tabTapped(_ index: Int) {
guard index < controllers.count else { return }
currentController = controllers[index]
synchronise()
}
private func synchronise() {
guard let controller = currentController else { return }
controller.synchronize { error in
DispatchQueue.main.async { [weak self] in
guard let self = self, error == nil else {
self?.presenter.handleError(error!)
return
}
self.handleController()
}
}
}
handleController() just map channel of my currentController to fit my format.
I got delegate to handle newMessage and update my list:
extension ChatListInteractor: ChatChannelListControllerDelegate {
func controller(_ controller: ChatChannelListController, didChangeChannels changes: [ListChange<ChatChannel>]) {
DispatchQueue.main.async { [weak self] in
self?.handleController()
}
}
func controller(_ controller: DataController, didChangeState state: DataController.State) {
print("didChangeState \(state)")
}
}
What did you expect to happen?
Chatlist update correctly on the right tab
What happened instead?
I receive a new message on the tab not displayed, but the channel appears in my list displayed because currentController returns the channel. I don't know why my filter is ignored at this point.
To sumup: My controller returns a channel that it shouldn't since there's a filter.
GetStream Environment
GetStream Chat version: 4.61.0
GetStream Chat frameworks: StreamChat, StreamChatUI
iOS version: 17.5.1
Additional context
if I change tabs and come back everything's fine, I've concluded that I need to synchronize my controller. I can not do that on didChangeChannels method of the delegate without an infinite loop so I tried to use EventsControllerDelegate instead of ChatChannelListControllerDelegate but I still got the issue
extension ChatListInteractor: EventsControllerDelegate {
func eventsController(_ controller: StreamChat.EventsController, didReceiveEvent event: StreamChat.Event) {
switch event {
case _ as MessageNewEvent:
self.synchronise()
default:
break
}
}
}
I tried with only one controller. And my filter is ignored when I receive a new message. I forgot to tell you that it's a filter on an extra data value
I fix my problem by using filter like in this doc https://getstream.io/chat/docs/sdk/ios/client/controllers/channels/
But it is quite strange that filters work on first synchronize method but not on update.