Fix missing notification when execute receive new email & mark as read at same time in terminated app

This commit is contained in:
dab246
2024-05-10 14:13:59 +07:00
committed by Dat H. Pham
parent 43732a66d9
commit fde095523f
8 changed files with 144 additions and 80 deletions
@@ -1,16 +1,18 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/push/state_change.dart';
class GetSessionLoading extends LoadingState {}
class GetSessionSuccess extends UIState {
final Session session;
final StateChange? stateChange;
GetSessionSuccess(this.session);
GetSessionSuccess(this.session, {this.stateChange});
@override
List<Object> get props => [session];
List<Object?> get props => [session, stateChange];
}
class GetSessionFailure extends FeatureFailure {
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/platform_info.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/push/state_change.dart';
import 'package:tmail_ui_user/features/home/domain/repository/session_repository.dart';
import 'package:tmail_ui_user/features/home/domain/state/get_session_state.dart';
@@ -11,26 +12,29 @@ class GetSessionInteractor {
GetSessionInteractor(this.sessionRepository);
Stream<Either<Failure, Success>> execute() async* {
Stream<Either<Failure, Success>> execute({StateChange? stateChange}) async* {
try {
yield Right<Failure, Success>(GetSessionLoading());
final session = await sessionRepository.getSession();
yield Right<Failure, Success>(GetSessionSuccess(session));
yield Right<Failure, Success>(GetSessionSuccess(session, stateChange: stateChange));
} catch (e) {
if (PlatformInfo.isMobile) {
yield* _getStoredSessionFromCache(remoteException: e);
yield* _getStoredSessionFromCache(remoteException: e, stateChange: stateChange);
} else {
yield Left<Failure, Success>(GetSessionFailure(e));
}
}
}
Stream<Either<Failure, Success>> _getStoredSessionFromCache({dynamic remoteException}) async* {
Stream<Either<Failure, Success>> _getStoredSessionFromCache({
dynamic remoteException,
StateChange? stateChange
}) async* {
try {
log('GetSessionInteractor::_getStoredSessionFromCache:remoteException: $remoteException');
yield Right<Failure, Success>(GetSessionLoading());
final session = await sessionRepository.getStoredSession();
yield Right<Failure, Success>(GetSessionSuccess(session));
yield Right<Failure, Success>(GetSessionSuccess(session, stateChange: stateChange));
} catch (e) {
yield Left<Failure, Success>(GetSessionFailure(remoteException ?? e));
}