TF-437 Store state change of mailbox in background/terminate

This commit is contained in:
dab246
2022-11-30 11:51:46 +07:00
committed by Dat H. Pham
parent 49069a595c
commit 569a04844b
10 changed files with 117 additions and 22 deletions
@@ -0,0 +1,22 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class StoreMailboxStateToRefreshLoading extends UIState {}
class StoreMailboxStateToRefreshSuccess extends UIState {
StoreMailboxStateToRefreshSuccess();
@override
List<Object> get props => [];
}
class StoreMailboxStateToRefreshFailure extends FeatureFailure {
final dynamic exception;
StoreMailboxStateToRefreshFailure(this.exception);
@override
List<Object> get props => [exception];
}
@@ -4,17 +4,17 @@ import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/store_fcm_state_change_state.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/store_email_state_to_refresh_state.dart';
class StoreEmailStateToRefreshInteractor {
final FCMRepository _fcmRepository;
StoreEmailStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(TypeName typeName, jmap.State newState) async* {
Stream<Either<Failure, Success>> execute(jmap.State newState) async* {
try {
yield Right<Failure, Success>(StoreEmailStateToRefreshLoading());
await _fcmRepository.storeStateToRefresh(typeName, newState);
await _fcmRepository.storeStateToRefresh(TypeName.emailType, newState);
yield Right<Failure, Success>(StoreEmailStateToRefreshSuccess());
} catch (e) {
yield Left<Failure, Success>(StoreEmailStateToRefreshFailure(e));
@@ -0,0 +1,23 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/store_mailbox_state_to_refresh_state.dart';
class StoreMailboxStateToRefreshInteractor {
final FCMRepository _fcmRepository;
StoreMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(jmap.State newState) async* {
try {
yield Right<Failure, Success>(StoreMailboxStateToRefreshLoading());
await _fcmRepository.storeStateToRefresh(TypeName.mailboxType, newState);
yield Right<Failure, Success>(StoreMailboxStateToRefreshSuccess());
} catch (e) {
yield Left<Failure, Success>(StoreMailboxStateToRefreshFailure(e));
}
}
}