GetStream / stream-chat-swift

💬 iOS Chat SDK in Swift - Build your own app chat experience for iOS using the official Stream Chat API
https://getstream.io/chat/sdk/ios/
Other
859 stars 211 forks source link

How can I refresh an existing Stream view when the Stream user changes #3425

Closed srgray closed 1 month ago

srgray commented 1 month ago

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:

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.

nuno-vieira commented 1 month ago

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

srgray commented 1 month ago

@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?

nuno-vieira commented 1 month ago

@srgray You don't need to recreate the view, you only need to recreate the controller and refresh the data 👍

srgray commented 1 month ago

@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:

testableapple commented 1 month ago

Hi @srgray, as this is more of a customisation question than an SDK issue, it is best to reach out to our support. Feel free to share the link to this ticket so the support team has more context.

Thanks!

Best, Alex

nuno-vieira commented 1 month ago

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)
        }
srgray commented 1 month ago

@nuno-vieira thank you, that works!