Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
srgray opened this issue Sep 19, 2024 · 7 comments
Closed

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

srgray opened this issue Sep 19, 2024 · 7 comments
Labels
❓ Question Question regarding a specific subject

Comments

@srgray
Copy link

srgray commented Sep 19, 2024

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.

@nuno-vieira
Copy link
Member

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 nuno-vieira added the ❓ Question Question regarding a specific subject label Sep 19, 2024
@srgray
Copy link
Author

srgray commented Sep 19, 2024

@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
Copy link
Member

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

@srgray
Copy link
Author

srgray commented Sep 19, 2024

@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

@testableapple
Copy link
Contributor

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
Copy link
Member

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
Copy link
Author

srgray commented Sep 24, 2024

@nuno-vieira thank you, that works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ Question Question regarding a specific subject
Projects
None yet
Development

No branches or pull requests

3 participants