TF-437 Handle Mailbox/changes in background/terminated

This commit is contained in:
dab246
2022-11-30 12:09:00 +07:00
committed by Dat H. Pham
parent 569a04844b
commit b37de97d6b
4 changed files with 59 additions and 0 deletions
@@ -0,0 +1,25 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
class GetMailboxStateToRefreshLoading extends UIState {}
class GetMailboxStateToRefreshSuccess extends UIState {
final jmap.State storedState;
GetMailboxStateToRefreshSuccess(this.storedState);
@override
List<Object> get props => [storedState];
}
class GetMailboxStateToRefreshFailure extends FeatureFailure {
final dynamic exception;
GetMailboxStateToRefreshFailure(this.exception);
@override
List<Object> get props => [exception];
}
@@ -0,0 +1,22 @@
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:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_mailbox_state_to_refresh_state.dart';
class GetMailboxStateToRefreshInteractor {
final FCMRepository _fcmRepository;
GetMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute() async* {
try {
yield Right<Failure, Success>(GetMailboxStateToRefreshLoading());
final storedState = await _fcmRepository.getStateToRefresh(TypeName.mailboxType);
yield Right<Failure, Success>(GetMailboxStateToRefreshSuccess(storedState));
} catch (e) {
yield Left<Failure, Success>(GetMailboxStateToRefreshFailure(e));
}
}
}