Fix missing notification when execute receive new email & mark as read at same time in terminated app
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user