How can I refresh an existing Stream view when the Stream user changes
Closed this issue ยท 7 comments
What did you do?
I switched Stream users while a Stream view (ChatChannelListVC
) was visible (and didn't recreate it).
What did you expect to happen?
I expected Stream to refresh ChatChannelListVC
with the new data after the other user was logged in.
What happened instead?
ChatChannelListVC
shows empty data after disconnect/connect sequence.
GetStream Environment
GetStream Chat version: 4.63.0
GetStream Chat frameworks: StreamChat, StreamChatUI
iOS version: 18.0
Swift version: 5
Xcode version: 16
Device: iPhone 16 Pro simulator
Additional context
See attached sample project:
StreamSwitchUsers 2.zip
Steps to reproduce:
- Open sample app
- Tap 'Login as user1'
- See user1 channel list
- Tap 'user1' button in nav bar to disconnect user1 and connect user2
- Notice the empty channel list is displayed (instead of user2 channels)
How can I tell ChatChannelListVC
to refresh after a new user is connected? I know that I can change my app navigation to recreate the ChatChannelListVC
after the new user is connected, but I would like to know if I can avoid that. This goes for other Stream views like ChatChannelVC
, too.
Hi @srgray,
You will need to create a new controller and use replaceQuery()
or replaceChannelListController()
to refresh the data in this scenario.
Thank you,
Nuno
@nuno-vieira That works great, thank you. Does ChatChannelVC
have a way to refresh the data after the user changes? Or do I need to recreate it?
@srgray You don't need to recreate the view, you only need to recreate the controller and refresh the data ๐
@nuno-vieira Can you take a look at this modified sample project? I'm recreating the controller for ChatChannelVC, but I don't know how to refresh the data:
StreamSwitchUsers 3.zip
Steps:
- Run app
- Tap 'Login as user1'
- Tap chat channel to enter
- Tap 'user1' button in nav bar to switch to user2
- Chat channel is now empty
Hi @srgray,
When you set the new controller than you need to call synchornize. Something like this:
channelController.delegate = self
channelController.synchronize { [weak self] error in
self?.didFinishSynchronizing(with: error)
}
@nuno-vieira thank you, that works!