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

fix(llc): send only user_id while reconnecting #1072

Merged
merged 7 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
channel update.
- [[#1054]](https://github.com/GetStream/stream-chat-flutter/issues/1054) Fix `Unsupported operation: Cannot remove from an unmodifiable list`.
- [[#1033]](https://github.com/GetStream/stream-chat-flutter/issues/1033) Hard delete from dashboard does not delete message from client.
- Send only `user_id` while reconnecting.

✅ Added

Expand Down
15 changes: 12 additions & 3 deletions packages/stream_chat/lib/src/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ class StreamChatClient {
_chatPersistenceClient = _originalChatPersistenceClient;
await _chatPersistenceClient!.connect(ownUser.id);
}
final connectedUser = await openConnection();
final connectedUser = await openConnection(
includeUserDetailsInConnectCall: true,
);
return state.currentUser = connectedUser;
} catch (e, stk) {
if (e is StreamWebSocketError && e.isRetriable) {
Expand All @@ -341,7 +343,11 @@ class StreamChatClient {
}

/// Creates a new WebSocket connection with the current user.
Future<OwnUser> openConnection() async {
/// If [includeUserDetailsInConnectCall] is true it will include the current
/// user details in the connect call.
Future<OwnUser> openConnection({
bool includeUserDetailsInConnectCall = false,
}) async {
assert(
state.currentUser != null,
'User is not set on client, '
Expand Down Expand Up @@ -371,7 +377,10 @@ class StreamChatClient {
_ws.connectionStatusStream.skip(1).listen(_connectionStatusHandler);

try {
final event = await _ws.connect(user);
final event = await _ws.connect(
user,
includeUserDetails: includeUserDetailsInConnectCall,
);
return user.merge(event.me);
} catch (e, stk) {
logger.severe('error connecting ws', e, stk);
Expand Down
21 changes: 16 additions & 5 deletions packages/stream_chat/lib/src/ws/websocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ class WebSocket with TimerHelper {
}
}

Future<Uri> _buildUri({bool refreshToken = false}) async {
Future<Uri> _buildUri({
bool refreshToken = false,
bool includeUserDetails = true,
}) async {
final user = _user!;
final token = await tokenManager.loadToken(refresh: refreshToken);
final params = {
'user_id': user.id,
'user_details': user,
if (includeUserDetails) 'user_details': user,
'user_token': token.rawValue,
'server_determines_connection_id': true,
};
Expand All @@ -176,7 +179,10 @@ class WebSocket with TimerHelper {
bool _connectRequestInProgress = false;

/// Connect the WS using the parameters passed in the constructor
Future<Event> connect(User user) async {
Future<Event> connect(
User user, {
bool includeUserDetails = false,
}) async {
if (_connectRequestInProgress) {
throw const StreamWebSocketError('''
You've called connect twice,
Expand All @@ -191,7 +197,9 @@ class WebSocket with TimerHelper {
connectionCompleter = Completer<Event>();

try {
final uri = await _buildUri();
final uri = await _buildUri(
includeUserDetails: includeUserDetails,
);
_initWebSocketChannel(uri);
} catch (e, stk) {
_onConnectionError(e, stk);
Expand Down Expand Up @@ -219,7 +227,10 @@ class WebSocket with TimerHelper {
setTimer(
Duration(milliseconds: delay),
() async {
final uri = await _buildUri(refreshToken: refreshToken);
final uri = await _buildUri(
refreshToken: refreshToken,
includeUserDetails: false,
);
try {
_initWebSocketChannel(uri);
} catch (e, stk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 21
minSdkVersion 22
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down