TF-1933 Add GetStoredSendingEmail interactor
(cherry picked from commit bcf27cbaa5fbc62767a82e658e543339c5197991)
This commit is contained in:
@@ -102,4 +102,6 @@ abstract class EmailDataSource {
|
|||||||
Future<void> deleteMultipleSendingEmail(AccountId accountId, UserName userName, List<String> sendingIds);
|
Future<void> deleteMultipleSendingEmail(AccountId accountId, UserName userName, List<String> sendingIds);
|
||||||
|
|
||||||
Future<List<SendingEmail>> updateMultipleSendingEmail(AccountId accountId, UserName userName, List<SendingEmail> newSendingEmails);
|
Future<List<SendingEmail>> updateMultipleSendingEmail(AccountId accountId, UserName userName, List<SendingEmail> newSendingEmails);
|
||||||
|
|
||||||
|
Future<SendingEmail> getStoredSendingEmail(AccountId accountId, UserName userName, String sendingId);
|
||||||
}
|
}
|
||||||
@@ -219,4 +219,9 @@ class EmailDataSourceImpl extends EmailDataSource {
|
|||||||
Future<List<SendingEmail>> deleteMultipleSendingEmail(AccountId accountId, UserName userName, List<String> sendingIds) {
|
Future<List<SendingEmail>> deleteMultipleSendingEmail(AccountId accountId, UserName userName, List<String> sendingIds) {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<SendingEmail> getStoredSendingEmail(AccountId accountId, UserName userName, String sendingId) {
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -279,4 +279,12 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
|||||||
return await _sendingEmailCacheManager.deleteMultipleSendingEmail(accountId, userName, sendingIds);
|
return await _sendingEmailCacheManager.deleteMultipleSendingEmail(accountId, userName, sendingIds);
|
||||||
}).catchError(_exceptionThrower.throwException);
|
}).catchError(_exceptionThrower.throwException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<SendingEmail> getStoredSendingEmail(AccountId accountId, UserName userName, String sendingId) {
|
||||||
|
return Future.sync(() async {
|
||||||
|
final sendingEmailCache = await _sendingEmailCacheManager.getStoredSendingEmail(accountId, userName, sendingId);
|
||||||
|
return sendingEmailCache.toSendingEmail();
|
||||||
|
}).catchError(_exceptionThrower.throwException);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
import 'package:core/utils/app_logger.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||||
import 'package:model/extensions/account_id_extensions.dart';
|
import 'package:model/extensions/account_id_extensions.dart';
|
||||||
@@ -24,7 +23,6 @@ class SendingEmailCacheManager {
|
|||||||
await _hiveCacheClient.insertItem(keyCache, sendingEmailHiveCache);
|
await _hiveCacheClient.insertItem(keyCache, sendingEmailHiveCache);
|
||||||
final newSendingEmailHiveCache = await _hiveCacheClient.getItem(keyCache);
|
final newSendingEmailHiveCache = await _hiveCacheClient.getItem(keyCache);
|
||||||
if (newSendingEmailHiveCache != null) {
|
if (newSendingEmailHiveCache != null) {
|
||||||
log('SendingEmailCacheManager::storeSendingEmail():sendingId: ${newSendingEmailHiveCache.sendingId} | sendingState: ${newSendingEmailHiveCache.sendingState}');
|
|
||||||
return newSendingEmailHiveCache;
|
return newSendingEmailHiveCache;
|
||||||
} else {
|
} else {
|
||||||
throw NotFoundSendingEmailHiveObject();
|
throw NotFoundSendingEmailHiveObject();
|
||||||
@@ -42,7 +40,6 @@ class SendingEmailCacheManager {
|
|||||||
await _hiveCacheClient.deleteItem(keyCache);
|
await _hiveCacheClient.deleteItem(keyCache);
|
||||||
final storedSendingEmail = await _hiveCacheClient.getItem(keyCache);
|
final storedSendingEmail = await _hiveCacheClient.getItem(keyCache);
|
||||||
if (storedSendingEmail != null) {
|
if (storedSendingEmail != null) {
|
||||||
log('SendingEmailCacheManager::deleteSendingEmail():sendingId: ${storedSendingEmail.sendingId}');
|
|
||||||
throw ExistSendingEmailHiveObject();
|
throw ExistSendingEmailHiveObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +61,6 @@ class SendingEmailCacheManager {
|
|||||||
await _hiveCacheClient.updateItem(keyCache, sendingEmailHiveCache);
|
await _hiveCacheClient.updateItem(keyCache, sendingEmailHiveCache);
|
||||||
final newSendingEmailHiveCache = await _hiveCacheClient.getItem(keyCache);
|
final newSendingEmailHiveCache = await _hiveCacheClient.getItem(keyCache);
|
||||||
if (newSendingEmailHiveCache != null) {
|
if (newSendingEmailHiveCache != null) {
|
||||||
log('SendingEmailCacheManager::updateSendingEmail():sendingId: ${newSendingEmailHiveCache.sendingId} | sendingState: ${newSendingEmailHiveCache.sendingState}');
|
|
||||||
return newSendingEmailHiveCache;
|
return newSendingEmailHiveCache;
|
||||||
} else {
|
} else {
|
||||||
throw NotFoundSendingEmailHiveObject();
|
throw NotFoundSendingEmailHiveObject();
|
||||||
@@ -82,7 +78,6 @@ class SendingEmailCacheManager {
|
|||||||
};
|
};
|
||||||
await _hiveCacheClient.updateMultipleItem(mapSendingEmailCache);
|
await _hiveCacheClient.updateMultipleItem(mapSendingEmailCache);
|
||||||
final newListSendingEmailCache = await _hiveCacheClient.getValuesByListKey(mapSendingEmailCache.keys.toList());
|
final newListSendingEmailCache = await _hiveCacheClient.getValuesByListKey(mapSendingEmailCache.keys.toList());
|
||||||
log('SendingEmailCacheManager::updateMultipleSendingEmail():newListSendingEmailCache: ${newListSendingEmailCache.map((sendingEmail) => '${sendingEmail.sendingId} | ${sendingEmail.sendingState}').toList()}');
|
|
||||||
return newListSendingEmailCache;
|
return newListSendingEmailCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,11 +85,20 @@ class SendingEmailCacheManager {
|
|||||||
final listTupleKey = sendingIds.map((sendingId) => TupleKey(sendingId, accountId.asString, userName.value).encodeKey).toList();
|
final listTupleKey = sendingIds.map((sendingId) => TupleKey(sendingId, accountId.asString, userName.value).encodeKey).toList();
|
||||||
await _hiveCacheClient.deleteMultipleItem(listTupleKey);
|
await _hiveCacheClient.deleteMultipleItem(listTupleKey);
|
||||||
final newListSendingEmailCache = await _hiveCacheClient.getValuesByListKey(listTupleKey);
|
final newListSendingEmailCache = await _hiveCacheClient.getValuesByListKey(listTupleKey);
|
||||||
log('SendingEmailCacheManager::deleteMultipleSendingEmail():newListSendingEmailCache: ${newListSendingEmailCache.map((sendingEmail) => '${sendingEmail.sendingId} | ${sendingEmail.sendingState}').toList()}');
|
|
||||||
if (newListSendingEmailCache.isNotEmpty) {
|
if (newListSendingEmailCache.isNotEmpty) {
|
||||||
throw ExistSendingEmailHiveObject();
|
throw ExistSendingEmailHiveObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<SendingEmailHiveCache> getStoredSendingEmail(AccountId accountId, UserName userName, String sendingId) async {
|
||||||
|
final keyCache = TupleKey(sendingId, accountId.asString, userName.value).encodeKey;
|
||||||
|
final storedSendingEmail = await _hiveCacheClient.getItem(keyCache);
|
||||||
|
if (storedSendingEmail != null) {
|
||||||
|
return storedSendingEmail;
|
||||||
|
} else {
|
||||||
|
throw NotFoundSendingEmailHiveObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> closeSendingEmailHiveCacheBox() => _hiveCacheClient.closeBox();
|
Future<void> closeSendingEmailHiveCacheBox() => _hiveCacheClient.closeBox();
|
||||||
}
|
}
|
||||||
@@ -39,4 +39,9 @@ class SendingQueueRepositoryImpl extends SendingQueueRepository {
|
|||||||
Future<void> deleteMultipleSendingEmail(AccountId accountId, UserName userName, List<String> sendingIds) {
|
Future<void> deleteMultipleSendingEmail(AccountId accountId, UserName userName, List<String> sendingIds) {
|
||||||
return _emailHiveCacheDataSourceImpl.deleteMultipleSendingEmail(accountId, userName, sendingIds);
|
return _emailHiveCacheDataSourceImpl.deleteMultipleSendingEmail(accountId, userName, sendingIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<SendingEmail> getStoredSendingEmail(AccountId accountId, UserName userName, String sendingId) {
|
||||||
|
return _emailHiveCacheDataSourceImpl.getStoredSendingEmail(accountId, userName, sendingId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -15,4 +15,6 @@ abstract class SendingQueueRepository {
|
|||||||
Future<SendingEmail> updateSendingEmail(AccountId accountId, UserName userName, SendingEmail newSendingEmail);
|
Future<SendingEmail> updateSendingEmail(AccountId accountId, UserName userName, SendingEmail newSendingEmail);
|
||||||
|
|
||||||
Future<List<SendingEmail>> updateMultipleSendingEmail(AccountId accountId, UserName userName, List<SendingEmail> newSendingEmails);
|
Future<List<SendingEmail>> updateMultipleSendingEmail(AccountId accountId, UserName userName, List<SendingEmail> newSendingEmails);
|
||||||
|
|
||||||
|
Future<SendingEmail> getStoredSendingEmail(AccountId accountId, UserName userName, String sendingId);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
import 'package:core/presentation/state/failure.dart';
|
||||||
|
import 'package:core/presentation/state/success.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||||
|
import 'package:tmail_ui_user/features/offline_mode/model/sending_state.dart';
|
||||||
|
import 'package:tmail_ui_user/features/sending_queue/domain/model/sending_email.dart';
|
||||||
|
|
||||||
|
class GetStoredSendingEmailLoading extends UIState {}
|
||||||
|
|
||||||
|
class GetStoredSendingEmailSuccess extends UIState {
|
||||||
|
|
||||||
|
final SendingEmail sendingEmail;
|
||||||
|
final AccountId accountId;
|
||||||
|
final UserName userName;
|
||||||
|
final SendingState sendingState;
|
||||||
|
|
||||||
|
GetStoredSendingEmailSuccess(
|
||||||
|
this.sendingEmail,
|
||||||
|
this.accountId,
|
||||||
|
this.userName,
|
||||||
|
this.sendingState
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [
|
||||||
|
sendingEmail,
|
||||||
|
accountId,
|
||||||
|
userName,
|
||||||
|
sendingState
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetStoredSendingEmailFailure extends FeatureFailure {
|
||||||
|
|
||||||
|
GetStoredSendingEmailFailure(dynamic exception) : super(exception: exception);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [exception];
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
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/user_name.dart';
|
||||||
|
import 'package:tmail_ui_user/features/offline_mode/model/sending_state.dart';
|
||||||
|
import 'package:tmail_ui_user/features/sending_queue/domain/repository/sending_queue_repository.dart';
|
||||||
|
import 'package:tmail_ui_user/features/sending_queue/domain/state/get_stored_sending_email_state.dart';
|
||||||
|
|
||||||
|
class GetStoredSendingEmailInteractor {
|
||||||
|
final SendingQueueRepository _sendingQueueRepository;
|
||||||
|
|
||||||
|
GetStoredSendingEmailInteractor(this._sendingQueueRepository);
|
||||||
|
|
||||||
|
Stream<Either<Failure, Success>> execute(
|
||||||
|
AccountId accountId,
|
||||||
|
UserName userName,
|
||||||
|
String sendingId,
|
||||||
|
SendingState sendingState
|
||||||
|
) async* {
|
||||||
|
try {
|
||||||
|
yield Right<Failure, Success>(GetStoredSendingEmailLoading());
|
||||||
|
final sendingEmail = await _sendingQueueRepository.getStoredSendingEmail(accountId, userName, sendingId);
|
||||||
|
yield Right<Failure, Success>(
|
||||||
|
GetStoredSendingEmailSuccess(
|
||||||
|
sendingEmail,
|
||||||
|
accountId,
|
||||||
|
userName,
|
||||||
|
sendingState
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
yield Left<Failure, Success>(GetStoredSendingEmailFailure(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user