TF-3157 Remove unnecessary background service worker

This commit is contained in:
DatDang
2024-11-04 16:28:13 +07:00
committed by Dat H. Pham
parent 7d59982cc9
commit b76e8bb725
20 changed files with 151 additions and 447 deletions
@@ -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));
}
}
}