Code Monkey home page Code Monkey logo

Comments (5)

esarbanis avatar esarbanis commented on May 30, 2024

Hi @flodaniel , why do you use the client itself and not client.currentUserStream?

from stream-chat-flutter.

flodaniel avatar flodaniel commented on May 30, 2024

The stream here is a custom stream in my app, that I used to resolve issues when a user logged out and a new user logged in. When that happens I create a new StreamChatClient and this stream emits the new client.

from stream-chat-flutter.

flodaniel avatar flodaniel commented on May 30, 2024

I can reproduce a crash on final userId = StreamChat.of(context).currentUser!.id; in the message_list_view after a disconnect and reconnet with a new user when using the belwo code. Other operations like queryChannels work as expected with the new user.

To disconnect:

  Future<void> logout() async {
    try {
      await _tokenRefreshListener?.cancel();
      await _badgeListener?.cancel();
      final token = await _getDeviceToken();
      if (token != null) {
        try {
          await client.removeDevice(token);
        } catch (_) {}
      }
      await client.disconnectUser(flushChatPersistence: true);
    } catch (error, stackTrace) {
      unawaited(SentryService().recordError(error, stackTrace: stackTrace));
    } finally {
      _initialized = null;
    }
  }

To connect:

  Future<OwnUser> _connectUser() async {
    final paveUser = _userRepository.user;
    final streamUsername =
        StreamChatHelper.convertUsernameToStreamUsername(paveUser.username);
    final streamChatUser = User(
      id: streamUsername,
      name: paveUser.displayName,
      image: paveUser.username,
    );
    final tokens = await _authenticationRepository.tokens();
    final streamChatToken = tokens.streamChatToken;
    return await client.connectUser(
      streamChatUser,
      streamChatToken,
    );
  }

Worth to note that the StreamChat widget is not destroyed when the user logs out and logs in again.

Edit:
I fixed it by moving the StreamChat widget further down the tree where it gets destroyed if the user logs out. Not sure if this is still considered a bug then?

from stream-chat-flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.