TF-3157 Remove unnecessary background service worker
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
|
||||
abstract class WebSocketRepository {
|
||||
Stream getWebSocketChannel(Session session, AccountId accountId);
|
||||
Future<WebSocketChannel> getWebSocketChannel(
|
||||
Session session,
|
||||
AccountId accountId);
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/push/state_change.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
|
||||
class InitializingWebSocketPushChannel extends LoadingState {}
|
||||
|
||||
class WebSocketPushStateReceived extends UIState {
|
||||
final StateChange? stateChange;
|
||||
class WebSocketConnectionSuccess extends UIState {
|
||||
final WebSocketChannel webSocketChannel;
|
||||
|
||||
WebSocketPushStateReceived(this.stateChange);
|
||||
WebSocketConnectionSuccess(this.webSocketChannel);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [stateChange];
|
||||
List<Object?> get props => [webSocketChannel];
|
||||
}
|
||||
|
||||
class WebSocketConnectionFailed extends FeatureFailure {
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
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';
|
||||
|
||||
@@ -22,31 +18,13 @@ class ConnectWebSocketInteractor {
|
||||
) async* {
|
||||
try {
|
||||
yield Right(InitializingWebSocketPushChannel());
|
||||
yield* _webSocketRepository
|
||||
.getWebSocketChannel(session, accountId)
|
||||
.map(_toStateChange);
|
||||
final webSocketChannel = await _webSocketRepository.getWebSocketChannel(
|
||||
session,
|
||||
accountId);
|
||||
yield Right(WebSocketConnectionSuccess(webSocketChannel));
|
||||
} catch (e) {
|
||||
logError('ConnectWebSocketInteractor::execute: $e');
|
||||
yield Left(WebSocketConnectionFailed(exception: e));
|
||||
}
|
||||
}
|
||||
|
||||
Either<Failure, Success> _toStateChange(dynamic 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user