TF-3157 Update web socket with background service worker
TF-3157 Stub BroadcastChannel for mobile build
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/push/state_change.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/data/model/web_socket_echo.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/web_socket_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/web_socket_push_state.dart';
|
||||
|
||||
@@ -31,9 +32,21 @@ class ConnectWebSocketInteractor {
|
||||
}
|
||||
|
||||
Either<Failure, Success> _toStateChange(dynamic data) {
|
||||
if (data is String) {
|
||||
data = jsonDecode(data);
|
||||
StateChange? possibleStateChange;
|
||||
try {
|
||||
if (data is String) {
|
||||
data = jsonDecode(data);
|
||||
}
|
||||
possibleStateChange = StateChange.fromJson(data);
|
||||
return Right(WebSocketPushStateReceived(possibleStateChange));
|
||||
} catch (e) {
|
||||
logError('ConnectWebSocketInteractor::_toStateChange: '
|
||||
'websocket message is not StateChange: $data');
|
||||
final dataIsWebSocketEcho = WebSocketEcho.isValid(data);
|
||||
if (dataIsWebSocketEcho) {
|
||||
return Right(WebSocketPushStateReceived(null));
|
||||
}
|
||||
return Left(WebSocketConnectionFailed(exception: e));
|
||||
}
|
||||
return Right(WebSocketPushStateReceived(StateChange.fromJson(data)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user