TF-438 Implement method for get/store/delete StateToRefresh and get email changes
This commit is contained in:
@@ -2,4 +2,6 @@ class NotFoundStoredFCMException implements Exception {}
|
||||
|
||||
class NotSupportFCMException implements Exception {}
|
||||
|
||||
class NotFoundStateToRefreshException implements Exception {}
|
||||
|
||||
class NotFoundEmailDeliveryStateException implements Exception {}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
|
||||
class DeleteEmailStateToRefreshLoading extends UIState {}
|
||||
|
||||
class DeleteEmailStateToRefreshSuccess extends UIState {
|
||||
|
||||
DeleteEmailStateToRefreshSuccess();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DeleteEmailStateToRefreshFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
DeleteEmailStateToRefreshFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
|
||||
class GetEmailChangesToPushNotificationLoading extends UIState {}
|
||||
|
||||
class GetEmailChangesToPushNotificationSuccess extends UIState {
|
||||
|
||||
final List<PresentationEmail> emailList;
|
||||
|
||||
GetEmailChangesToPushNotificationSuccess(this.emailList);
|
||||
|
||||
@override
|
||||
List<Object> get props => [emailList];
|
||||
}
|
||||
|
||||
class GetEmailChangesToPushNotificationFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
GetEmailChangesToPushNotificationFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
@@ -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 GetEmailStateToRefreshLoading extends UIState {}
|
||||
|
||||
class GetEmailStateToRefreshSuccess extends UIState {
|
||||
|
||||
final jmap.State storedState;
|
||||
|
||||
GetEmailStateToRefreshSuccess(this.storedState);
|
||||
|
||||
@override
|
||||
List<Object> get props => [storedState];
|
||||
}
|
||||
|
||||
class GetEmailStateToRefreshFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
GetEmailStateToRefreshFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
@@ -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 GetStoredEmailDeliveryStateLoading extends UIState {}
|
||||
|
||||
class GetStoredEmailDeliveryStateSuccess extends UIState {
|
||||
|
||||
final jmap.State state;
|
||||
|
||||
GetStoredEmailDeliveryStateSuccess(this.state);
|
||||
|
||||
@override
|
||||
List<Object> get props => [state];
|
||||
}
|
||||
|
||||
class GetStoredEmailDeliveryStateFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
GetStoredEmailDeliveryStateFailure(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';
|
||||
|
||||
class StoreEmailDeliveryStateLoading extends UIState {}
|
||||
|
||||
class StoreEmailDeliveryStateSuccess extends UIState {
|
||||
|
||||
StoreEmailDeliveryStateSuccess();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class StoreEmailDeliveryStateFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
StoreEmailDeliveryStateFailure(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';
|
||||
|
||||
class StoreEmailStateToRefreshLoading extends UIState {}
|
||||
|
||||
class StoreEmailStateToRefreshSuccess extends UIState {
|
||||
|
||||
StoreEmailStateToRefreshSuccess();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class StoreEmailStateToRefreshFailure extends FeatureFailure {
|
||||
final dynamic exception;
|
||||
|
||||
StoreEmailStateToRefreshFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
+22
@@ -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/delete_email_state_to_refresh_state.dart';
|
||||
|
||||
class DeleteEmailStateToRefreshInteractor {
|
||||
final FCMRepository _fcmRepository;
|
||||
|
||||
DeleteEmailStateToRefreshInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(TypeName typeName) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(DeleteEmailStateToRefreshLoading());
|
||||
await _fcmRepository.deleteStateToRefresh(typeName);
|
||||
yield Right<Failure, Success>(DeleteEmailStateToRefreshSuccess());
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(DeleteEmailStateToRefreshFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:model/extensions/email_extension.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_email_changes_state.dart';
|
||||
|
||||
class GetEmailChangesToPushNotificationInteractor {
|
||||
final FCMRepository _fcmRepository;
|
||||
|
||||
GetEmailChangesToPushNotificationInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
AccountId accountId,
|
||||
jmap.State currentState,
|
||||
{
|
||||
Properties? propertiesCreated,
|
||||
Properties? propertiesUpdated
|
||||
}
|
||||
) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetEmailChangesToPushNotificationLoading());
|
||||
|
||||
final emailsResponse = await _fcmRepository.getEmailChangesToPushNotification(
|
||||
accountId,
|
||||
currentState,
|
||||
propertiesCreated: propertiesCreated,
|
||||
propertiesUpdated: propertiesUpdated);
|
||||
|
||||
final presentationEmailList = emailsResponse.emailList
|
||||
?.map((email) => email.toPresentationEmail())
|
||||
.toList() ?? List.empty();
|
||||
|
||||
yield Right<Failure, Success>(GetEmailChangesToPushNotificationSuccess(presentationEmailList));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetEmailChangesToPushNotificationFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -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_email_state_to_refresh_state.dart';
|
||||
|
||||
class GetEmailStateToRefreshInteractor {
|
||||
final FCMRepository _fcmRepository;
|
||||
|
||||
GetEmailStateToRefreshInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute() async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetEmailStateToRefreshLoading());
|
||||
final storedState = await _fcmRepository.getStateToRefresh(TypeName.emailType);
|
||||
yield Right<Failure, Success>(GetEmailStateToRefreshSuccess(storedState));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetEmailStateToRefreshFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -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_stored_email_delivery_state.dart';
|
||||
|
||||
class GetStoredEmailDeliveryStateInteractor {
|
||||
final FCMRepository _fcmRepository;
|
||||
|
||||
GetStoredEmailDeliveryStateInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute() async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetStoredEmailDeliveryStateLoading());
|
||||
final storedState = await _fcmRepository.getStateToRefresh(TypeName.emailDelivery);
|
||||
yield Right<Failure, Success>(GetStoredEmailDeliveryStateSuccess(storedState));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetStoredEmailDeliveryStateFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -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_email_delivery_state.dart';
|
||||
|
||||
class StoreEmailDeliveryStateInteractor {
|
||||
final FCMRepository _fcmRepository;
|
||||
|
||||
StoreEmailDeliveryStateInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(jmap.State newState) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StoreEmailDeliveryStateLoading());
|
||||
await _fcmRepository.storeStateToRefresh(TypeName.emailDelivery, newState);
|
||||
yield Right<Failure, Success>(StoreEmailDeliveryStateSuccess());
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(StoreEmailDeliveryStateFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -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_fcm_state_change_state.dart';
|
||||
|
||||
class StoreEmailStateToRefreshInteractor {
|
||||
final FCMRepository _fcmRepository;
|
||||
|
||||
StoreEmailStateToRefreshInteractor(this._fcmRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(TypeName typeName, jmap.State newState) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StoreEmailStateToRefreshLoading());
|
||||
await _fcmRepository.storeStateToRefresh(typeName, newState);
|
||||
yield Right<Failure, Success>(StoreEmailStateToRefreshSuccess());
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(StoreEmailStateToRefreshFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user