Merge pull request #1072 from GetStream/hotfix/userReconnection
fix(llc): send only user_id while reconnecting
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
channel update.
|
channel update.
|
||||||
- [[#1054]](https://github.com/GetStream/stream-chat-flutter/issues/1054) Fix `Unsupported operation: Cannot remove from an unmodifiable list`.
|
- [[#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.
|
- [[#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
|
✅ Added
|
||||||
|
|
||||||
|
|||||||
@@ -328,7 +328,9 @@ class StreamChatClient {
|
|||||||
_chatPersistenceClient = _originalChatPersistenceClient;
|
_chatPersistenceClient = _originalChatPersistenceClient;
|
||||||
await _chatPersistenceClient!.connect(ownUser.id);
|
await _chatPersistenceClient!.connect(ownUser.id);
|
||||||
}
|
}
|
||||||
final connectedUser = await openConnection();
|
final connectedUser = await openConnection(
|
||||||
|
includeUserDetailsInConnectCall: true,
|
||||||
|
);
|
||||||
return state.currentUser = connectedUser;
|
return state.currentUser = connectedUser;
|
||||||
} catch (e, stk) {
|
} catch (e, stk) {
|
||||||
if (e is StreamWebSocketError && e.isRetriable) {
|
if (e is StreamWebSocketError && e.isRetriable) {
|
||||||
@@ -341,7 +343,11 @@ class StreamChatClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new WebSocket connection with the current user.
|
/// 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(
|
assert(
|
||||||
state.currentUser != null,
|
state.currentUser != null,
|
||||||
'User is not set on client, '
|
'User is not set on client, '
|
||||||
@@ -371,7 +377,10 @@ class StreamChatClient {
|
|||||||
_ws.connectionStatusStream.skip(1).listen(_connectionStatusHandler);
|
_ws.connectionStatusStream.skip(1).listen(_connectionStatusHandler);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final event = await _ws.connect(user);
|
final event = await _ws.connect(
|
||||||
|
user,
|
||||||
|
includeUserDetails: includeUserDetailsInConnectCall,
|
||||||
|
);
|
||||||
return user.merge(event.me);
|
return user.merge(event.me);
|
||||||
} catch (e, stk) {
|
} catch (e, stk) {
|
||||||
logger.severe('error connecting ws', e, stk);
|
logger.severe('error connecting ws', e, stk);
|
||||||
|
|||||||
@@ -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 user = _user!;
|
||||||
final token = await tokenManager.loadToken(refresh: refreshToken);
|
final token = await tokenManager.loadToken(refresh: refreshToken);
|
||||||
final params = {
|
final params = {
|
||||||
'user_id': user.id,
|
'user_id': user.id,
|
||||||
'user_details': user,
|
if (includeUserDetails) 'user_details': user,
|
||||||
'user_token': token.rawValue,
|
'user_token': token.rawValue,
|
||||||
'server_determines_connection_id': true,
|
'server_determines_connection_id': true,
|
||||||
};
|
};
|
||||||
@@ -176,7 +179,10 @@ class WebSocket with TimerHelper {
|
|||||||
bool _connectRequestInProgress = false;
|
bool _connectRequestInProgress = false;
|
||||||
|
|
||||||
/// Connect the WS using the parameters passed in the constructor
|
/// 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) {
|
if (_connectRequestInProgress) {
|
||||||
throw const StreamWebSocketError('''
|
throw const StreamWebSocketError('''
|
||||||
You've called connect twice,
|
You've called connect twice,
|
||||||
@@ -191,7 +197,9 @@ class WebSocket with TimerHelper {
|
|||||||
connectionCompleter = Completer<Event>();
|
connectionCompleter = Completer<Event>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final uri = await _buildUri();
|
final uri = await _buildUri(
|
||||||
|
includeUserDetails: includeUserDetails,
|
||||||
|
);
|
||||||
_initWebSocketChannel(uri);
|
_initWebSocketChannel(uri);
|
||||||
} catch (e, stk) {
|
} catch (e, stk) {
|
||||||
_onConnectionError(e, stk);
|
_onConnectionError(e, stk);
|
||||||
@@ -219,7 +227,10 @@ class WebSocket with TimerHelper {
|
|||||||
setTimer(
|
setTimer(
|
||||||
Duration(milliseconds: delay),
|
Duration(milliseconds: delay),
|
||||||
() async {
|
() async {
|
||||||
final uri = await _buildUri(refreshToken: refreshToken);
|
final uri = await _buildUri(
|
||||||
|
refreshToken: refreshToken,
|
||||||
|
includeUserDetails: false,
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
_initWebSocketChannel(uri);
|
_initWebSocketChannel(uri);
|
||||||
} catch (e, stk) {
|
} catch (e, stk) {
|
||||||
|
|||||||
@@ -124,7 +124,10 @@ class FakeWebSocket extends Fake implements WebSocket {
|
|||||||
Completer<Event>? connectionCompleter;
|
Completer<Event>? connectionCompleter;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Event> connect(User user) async {
|
Future<Event> connect(
|
||||||
|
User user, {
|
||||||
|
bool? includeUserDetails = true,
|
||||||
|
}) async {
|
||||||
connectionStatus = ConnectionStatus.connecting;
|
connectionStatus = ConnectionStatus.connecting;
|
||||||
final event = Event(
|
final event = Event(
|
||||||
type: EventType.healthCheck,
|
type: EventType.healthCheck,
|
||||||
@@ -167,7 +170,10 @@ class FakeWebSocketWithConnectionError extends Fake implements WebSocket {
|
|||||||
Completer<Event>? connectionCompleter;
|
Completer<Event>? connectionCompleter;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Event> connect(User user) async {
|
Future<Event> connect(
|
||||||
|
User user, {
|
||||||
|
bool? includeUserDetails = true,
|
||||||
|
}) async {
|
||||||
connectionStatus = ConnectionStatus.connecting;
|
connectionStatus = ConnectionStatus.connecting;
|
||||||
const error = StreamWebSocketError('Error Connecting');
|
const error = StreamWebSocketError('Error Connecting');
|
||||||
connectionCompleter = Completer()..completeError(error);
|
connectionCompleter = Completer()..completeError(error);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||||
applicationId "com.example.example"
|
applicationId "com.example.example"
|
||||||
minSdkVersion 21
|
minSdkVersion 22
|
||||||
targetSdkVersion 31
|
targetSdkVersion 31
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
|
|||||||
Reference in New Issue
Block a user