TF-1869: Double check email have been duplicated and remove it
(cherry picked from commit d1d448502228633554ea6eeb9a4bb9c98f849b18)
This commit is contained in:
@@ -6,5 +6,5 @@ import 'package:tmail_ui_user/features/offline_mode/model/detailed_email_hive_ca
|
||||
class DetailedEmailHiveCacheClient extends HiveCacheClient<DetailedEmailHiveCache> {
|
||||
|
||||
@override
|
||||
String get tableName => CachingConstants.detailedEmailCacheBoxName;
|
||||
String get tableName => CachingConstants.incomingEmailedCacheBoxName;
|
||||
}
|
||||
@@ -19,8 +19,8 @@ class CachingConstants {
|
||||
static const int DETAILED_EMAIL_HIVE_CACHE_ID = 17;
|
||||
|
||||
static const String fcmCacheBoxName = 'fcm_cache_box';
|
||||
static const String detailedEmailCacheBoxName = 'detailed_email_cache_box';
|
||||
static const String newEmailContentFolderName = 'new_email';
|
||||
static const String incomingEmailedCacheBoxName = 'incoming_emailed_cache_box';
|
||||
static const String incomingEmailedContentFolderName = 'incoming_emailed';
|
||||
static const String openedEmailContentFolderName = 'opened_email';
|
||||
static const String openedEmailCacheBoxName = 'opened_email_cache_box';
|
||||
|
||||
|
||||
@@ -80,11 +80,11 @@ abstract class EmailDataSource {
|
||||
|
||||
Future<void> storeEmail(Session session, AccountId accountId, Email email);
|
||||
|
||||
Future<Email?> getEmailFromCache(Session session, AccountId accountId, EmailId emailId);
|
||||
Future<Email?> getEmailStored(Session session, AccountId accountId, EmailId emailId);
|
||||
|
||||
Future<void> storeOpenedEmail(Session session, AccountId accountId, DetailedEmail detailedEmail);
|
||||
|
||||
Future<DetailedEmail?> getOpenedEmail(Session session, AccountId accountId, EmailId emailId);
|
||||
|
||||
Future<DetailedEmail?> getDetailedEmail(Session session, AccountId accountId, EmailId emailId);
|
||||
Future<DetailedEmail?> getIncomingEmailedStored(Session session, AccountId accountId, EmailId emailId);
|
||||
}
|
||||
@@ -178,12 +178,12 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DetailedEmail?> getDetailedEmail(Session session, AccountId accountId, EmailId emailId) {
|
||||
Future<DetailedEmail?> getIncomingEmailedStored(Session session, AccountId accountId, EmailId emailId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email?> getEmailFromCache(Session session, AccountId accountId, EmailId emailId) {
|
||||
Future<Email?> getEmailStored(Session session, AccountId accountId, EmailId emailId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -211,18 +211,19 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DetailedEmail?> getDetailedEmail(Session session, AccountId accountId, EmailId emailId) {
|
||||
Future<DetailedEmail?> getIncomingEmailedStored(Session session, AccountId accountId, EmailId emailId) {
|
||||
return Future.sync(() async {
|
||||
final detailedEmailHiveCache = await _detailedEmailCacheManager.getDetailEmailExistedInCache(accountId, session.username, emailId);
|
||||
|
||||
if (detailedEmailHiveCache == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
log('EmailHiveCacheDataSourceImpl::getDetailedEmail():folderPath: ${detailedEmailHiveCache.emailContentPath}');
|
||||
|
||||
final emailContent = await _fileUtils.getContentFromFile(
|
||||
nameFile: emailId.asString,
|
||||
folderPath: CachingConstants.newEmailContentFolderName
|
||||
folderPath: CachingConstants.incomingEmailedContentFolderName
|
||||
);
|
||||
|
||||
return detailedEmailHiveCache.toDetailedEmailWithContent(emailContent);
|
||||
@@ -230,9 +231,8 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email?> getEmailFromCache(Session session, AccountId accountId, EmailId emailId) {
|
||||
Future<Email?> getEmailStored(Session session, AccountId accountId, EmailId emailId) {
|
||||
return Future.sync(() async {
|
||||
log('EmailHiveCacheDataSourceImpl::getEmailFromCache():emailId: ${emailId.asString}');
|
||||
final email = await _emailCacheManager.getEmailFromCache(accountId, session.username, emailId);
|
||||
log('EmailHiveCacheDataSourceImpl::getEmailFromCache():emailId: $email');
|
||||
return email?.toEmail();
|
||||
|
||||
@@ -206,17 +206,17 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
|
||||
@override
|
||||
Future<DetailedEmail?> getOpenedEmail(Session session, AccountId accountId, EmailId emailId) async {
|
||||
final detailedEmail = await emailDataSource[DataSourceType.hiveCache]!.getDetailedEmail(session, accountId, emailId);
|
||||
final getIncomingEmailedStored = await emailDataSource[DataSourceType.hiveCache]!.getIncomingEmailedStored(session, accountId, emailId);
|
||||
final openedEmail = await emailDataSource[DataSourceType.hiveCache]!.getOpenedEmail(session, accountId, emailId);
|
||||
if (detailedEmail != null) {
|
||||
return detailedEmail;
|
||||
if (getIncomingEmailedStored != null) {
|
||||
return getIncomingEmailedStored;
|
||||
} else {
|
||||
return openedEmail;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email?> getEmailFromCache(Session session, AccountId accountId, EmailId emailId) {
|
||||
return emailDataSource[DataSourceType.hiveCache]!.getEmailFromCache(session, accountId, emailId);
|
||||
Future<Email?> getEmailStored(Session session, AccountId accountId, EmailId emailId) {
|
||||
return emailDataSource[DataSourceType.hiveCache]!.getEmailStored(session, accountId, emailId);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ extension DetailedEmailExtension on DetailedEmail {
|
||||
);
|
||||
}
|
||||
|
||||
String get newEmailFolderPath => CachingConstants.newEmailContentFolderName;
|
||||
String get newEmailFolderPath => CachingConstants.incomingEmailedContentFolderName;
|
||||
|
||||
String get openedEmailFolderPath => CachingConstants.openedEmailContentFolderName;
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ abstract class EmailRepository {
|
||||
|
||||
Future<void> storeEmailToCache(Session session, AccountId accountId, Email email);
|
||||
|
||||
Future<Email?> getEmailFromCache(Session session, AccountId accountId, EmailId emailId);
|
||||
Future<Email?> getEmailStored(Session session, AccountId accountId, EmailId emailId);
|
||||
|
||||
Future<void> storeOpenedEmail(Session session, AccountId accountId, DetailedEmail detailedEmail);
|
||||
|
||||
|
||||
@@ -92,10 +92,10 @@ class GetEmailContentInteractor {
|
||||
bool draftsEmail = false
|
||||
}
|
||||
) async* {
|
||||
log('GetEmailContentInteractor::_getOpenedEmailCache():');
|
||||
try {
|
||||
final detailedEmail = await emailRepository.getOpenedEmail(session, accountId, emailId);
|
||||
if (detailedEmail != null) {
|
||||
log('GetEmailContentInteractor::_tryToGetOpenedEmailCache(): $detailedEmail');
|
||||
yield Right<Failure, Success>(GetEmailContentFromCacheSuccess(
|
||||
detailedEmail.htmlEmailContent ?? "",
|
||||
detailedEmail.attachments ?? [],
|
||||
|
||||
@@ -77,7 +77,7 @@ class DetailedEmailCacheManager {
|
||||
EmailId emailId
|
||||
) async {
|
||||
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
|
||||
final detailedEmailCache = await _cacheClient.getItem(keyCache);
|
||||
final detailedEmailCache = await _cacheClient.getItem(keyCache, needToReopen: true);
|
||||
log('DetailedEmailCacheManager::getDetailEmailExistedInCache():Email: $detailedEmailCache');
|
||||
return detailedEmailCache;
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ class OpenedEmailCacheManager {
|
||||
EmailId emailId
|
||||
) async {
|
||||
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
|
||||
final detailedEmailCache = await _cacheClient.getItem(keyCache);
|
||||
log('OpenedEmailCacheManager::_getDetailedEmailCache():_getDetailedEmailCache: $detailedEmailCache');
|
||||
final detailedEmailCache = await _cacheClient.getItem(keyCache,needToReopen: true);
|
||||
log('OpenedEmailCacheManager::getOpenedEmailExistedInCache(): $detailedEmailCache');
|
||||
return detailedEmailCache;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class GetEmailByIdInteractor {
|
||||
) async* {
|
||||
try {
|
||||
|
||||
final email = await _emailRepository.getEmailFromCache(session, accountId, emailId);
|
||||
final email = await _emailRepository.getEmailStored(session, accountId, emailId);
|
||||
|
||||
if (email != null) {
|
||||
yield Right<Failure, Success>(GetEmailByIdSuccess(email.toPresentationEmail()));
|
||||
|
||||
Reference in New Issue
Block a user