TF-1869: Duplicate check for OpenedEmail and DetailedEmail when get contents
(cherry picked from commit 674312c3dd515b5699c84d3572bdc7bed9e7415d)
This commit is contained in:
@@ -21,7 +21,7 @@ class CachingConstants {
|
||||
static const String fcmCacheBoxName = 'fcm_cache_box';
|
||||
static const String detailedEmailCacheBoxName = 'detailed_email_cache_box';
|
||||
static const String newEmailContentFolderName = 'new_email';
|
||||
static const String openedEmailContentFolderNamee = 'opened_email';
|
||||
static const String openedEmailContentFolderName = 'opened_email';
|
||||
static const String openedEmailCacheBoxName = 'opened_email_cache_box';
|
||||
|
||||
static const int maxNumberNewEmailsForOffline = 10;
|
||||
|
||||
@@ -80,7 +80,11 @@ abstract class EmailDataSource {
|
||||
|
||||
Future<void> storeEmail(Session session, AccountId accountId, Email email);
|
||||
|
||||
Future<Email?> getEmailFromCache(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);
|
||||
}
|
||||
@@ -176,4 +176,14 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
Future<DetailedEmail> getOpenedEmail(Session session, AccountId accountId, EmailId emailId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DetailedEmail?> getDetailedEmail(Session session, AccountId accountId, EmailId emailId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email?> getEmailFromCache(Session session, AccountId accountId, EmailId emailId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import 'package:tmail_ui_user/features/offline_mode/manager/detailed_email_cache
|
||||
import 'package:tmail_ui_user/features/offline_mode/manager/opened_email_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/features/offline_mode/manager/opened_email_cache_worker_queue.dart';
|
||||
import 'package:tmail_ui_user/features/offline_mode/worker/hive_task.dart';
|
||||
import 'package:tmail_ui_user/features/thread/data/extensions/email_cache_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread/data/extensions/email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.dart';
|
||||
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
|
||||
@@ -192,14 +193,49 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
@override
|
||||
Future<DetailedEmail?> getOpenedEmail(Session session, AccountId accountId, EmailId emailId) {
|
||||
return Future.sync(() async {
|
||||
final detailedEmailHiveCache = await _openedEmailCacheManager.getDetailEmailExistedInCache(accountId, session.username, emailId);
|
||||
final openedEmailHiveCache = await _openedEmailCacheManager.getOpenedEmailExistedInCache(accountId, session.username, emailId);
|
||||
|
||||
if (openedEmailHiveCache == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
log('EmailHiveCacheDataSourceImpl::getOpenedEmail():folderPath: ${openedEmailHiveCache.emailContentPath}');
|
||||
|
||||
final emailContent = await _fileUtils.getContentFromFile(
|
||||
nameFile: emailId.asString,
|
||||
folderPath: CachingConstants.openedEmailContentFolderNamee
|
||||
nameFile: emailId.asString,
|
||||
folderPath: CachingConstants.openedEmailContentFolderName
|
||||
);
|
||||
|
||||
return detailedEmailHiveCache?.toDetailedEmailWithContent(emailContent);
|
||||
return openedEmailHiveCache.toDetailedEmailWithContent(emailContent);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DetailedEmail?> getDetailedEmail(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
|
||||
);
|
||||
|
||||
return detailedEmailHiveCache.toDetailedEmailWithContent(emailContent);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email?> getEmailFromCache(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();
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ extension DetailedEmailExtension on DetailedEmail {
|
||||
|
||||
String get newEmailFolderPath => CachingConstants.newEmailContentFolderName;
|
||||
|
||||
String get openedEmailFolderPath => CachingConstants.openedEmailContentFolderNamee;
|
||||
String get openedEmailFolderPath => CachingConstants.openedEmailContentFolderName;
|
||||
|
||||
DetailedEmail fromEmailContentPath(String path) {
|
||||
return DetailedEmail(
|
||||
|
||||
@@ -96,4 +96,9 @@ class EmailCacheManager {
|
||||
final keyCache = TupleKey(emailCache.id, accountId.asString, userName.value).encodeKey;
|
||||
return _emailCacheClient.insertItem(keyCache, emailCache);
|
||||
}
|
||||
|
||||
Future<EmailCache?> getEmailFromCache(AccountId accountId, UserName userName, EmailId emailId) {
|
||||
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
|
||||
return _emailCacheClient.getItem(keyCache);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user