TF-2564 Change logic empty folder (Spam/Trash) to avoid cache still has data
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -55,7 +55,6 @@ abstract class ThreadDataSource {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
MailboxId mailboxId,
|
||||
Future<void> Function(List<EmailId>? newDestroyed) updateDestroyedEmailCache,
|
||||
);
|
||||
|
||||
Future<PresentationEmail> getEmailById(Session session, AccountId accountId, EmailId emailId, {Properties? properties});
|
||||
|
||||
@@ -96,7 +96,6 @@ class LocalThreadDataSourceImpl extends ThreadDataSource {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
MailboxId mailboxId,
|
||||
Future<void> Function(List<EmailId>? newDestroyed) updateDestroyedEmailCache
|
||||
) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@@ -90,15 +90,13 @@ class ThreadDataSourceImpl extends ThreadDataSource {
|
||||
Future<List<EmailId>> emptyMailboxFolder(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
MailboxId mailboxId,
|
||||
Future<void> Function(List<EmailId>? newDestroyed) updateDestroyedEmailCache
|
||||
MailboxId mailboxId
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await _threadIsolateWorker.emptyMailboxFolder(
|
||||
session,
|
||||
accountId,
|
||||
mailboxId,
|
||||
updateDestroyedEmailCache,
|
||||
mailboxId
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@@ -65,21 +65,21 @@ class EmailCacheManager {
|
||||
List<Email>? created,
|
||||
List<EmailId>? destroyed
|
||||
}) async {
|
||||
final emailCacheExist = await _emailCacheClient.isExistTable();
|
||||
if (emailCacheExist) {
|
||||
final updatedCacheEmails = updated?.toMapCache(accountId, userName) ?? {};
|
||||
final createdCacheEmails = created?.toMapCache(accountId, userName) ?? {};
|
||||
final destroyedCacheEmails = destroyed?.toCacheKeyList(accountId, userName) ?? [];
|
||||
|
||||
await Future.wait([
|
||||
_emailCacheClient.updateMultipleItem(updatedCacheEmails),
|
||||
_emailCacheClient.insertMultipleItem(createdCacheEmails),
|
||||
_emailCacheClient.deleteMultipleItem(destroyedCacheEmails)
|
||||
]);
|
||||
} else {
|
||||
final createdCacheEmails = created?.toMapCache(accountId, userName) ?? {};
|
||||
if (created?.isNotEmpty == true) {
|
||||
final createdCacheEmails = created!.toMapCache(accountId, userName);
|
||||
await _emailCacheClient.insertMultipleItem(createdCacheEmails);
|
||||
}
|
||||
|
||||
if (updated?.isNotEmpty == true) {
|
||||
final updatedCacheEmails = updated!.toMapCache(accountId, userName);
|
||||
await _emailCacheClient.updateMultipleItem(updatedCacheEmails);
|
||||
}
|
||||
|
||||
final emailCacheExist = await _emailCacheClient.isExistTable();
|
||||
if (destroyed?.isNotEmpty == true && emailCacheExist) {
|
||||
final destroyedCacheEmails = destroyed!.toCacheKeyList(accountId, userName);
|
||||
await _emailCacheClient.deleteMultipleItem(destroyedCacheEmails);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clean(EmailCleanupRule cleanupRule) async {
|
||||
|
||||
@@ -33,10 +33,9 @@ class ThreadIsolateWorker {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
MailboxId mailboxId,
|
||||
Future<void> Function(List<EmailId>? newDestroyed) updateDestroyedEmailCache,
|
||||
) async {
|
||||
if (PlatformInfo.isWeb) {
|
||||
return _emptyMailboxFolderOnWeb(session, accountId, mailboxId, updateDestroyedEmailCache);
|
||||
return _emptyMailboxFolderOnWeb(session, accountId, mailboxId);
|
||||
} else {
|
||||
final rootIsolateToken = RootIsolateToken.instance;
|
||||
if (rootIsolateToken == null) {
|
||||
@@ -52,13 +51,7 @@ class ThreadIsolateWorker {
|
||||
mailboxId,
|
||||
rootIsolateToken
|
||||
),
|
||||
fun1: _emptyMailboxFolderAction,
|
||||
notification: (value) {
|
||||
if (value is List<EmailId>) {
|
||||
updateDestroyedEmailCache.call(value);
|
||||
log('ThreadIsolateWorker::emptyMailboxFolder(): onUpdateProgress: PERCENT ${value.length}');
|
||||
}
|
||||
}
|
||||
fun1: _emptyMailboxFolderAction
|
||||
);
|
||||
|
||||
if (result.isEmpty) {
|
||||
@@ -102,14 +95,11 @@ class ThreadIsolateWorker {
|
||||
if (newEmailList.isNotEmpty) {
|
||||
lastEmail = newEmailList.last;
|
||||
hasEmails = true;
|
||||
final listEmailIdDeleted = await args.emailAPI.deleteMultipleEmailsPermanently(args.session, args.accountId, newEmailList.listEmailIds);
|
||||
|
||||
if (listEmailIdDeleted.isNotEmpty && listEmailIdDeleted.length == newEmailList.listEmailIds.length) {
|
||||
sendPort.send(listEmailIdDeleted);
|
||||
}
|
||||
final listEmailIdDeleted = await args.emailAPI.deleteMultipleEmailsPermanently(
|
||||
args.session,
|
||||
args.accountId,
|
||||
newEmailList.listEmailIds);
|
||||
emailListCompleted.addAll(listEmailIdDeleted);
|
||||
|
||||
sendPort.send(emailListCompleted);
|
||||
} else {
|
||||
hasEmails = false;
|
||||
}
|
||||
@@ -125,7 +115,6 @@ class ThreadIsolateWorker {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
MailboxId mailboxId,
|
||||
Future<void> Function(List<EmailId> newDestroyed) updateDestroyedEmailCache,
|
||||
) async {
|
||||
List<EmailId> emailListCompleted = List.empty(growable: true);
|
||||
try {
|
||||
@@ -152,13 +141,11 @@ class ThreadIsolateWorker {
|
||||
if (newEmailList.isNotEmpty) {
|
||||
lastEmail = newEmailList.last;
|
||||
hasEmails = true;
|
||||
final listEmailIdDeleted = await _emailAPI.deleteMultipleEmailsPermanently(session, accountId, newEmailList.listEmailIds);
|
||||
|
||||
if (listEmailIdDeleted.isNotEmpty && listEmailIdDeleted.length == newEmailList.listEmailIds.length) {
|
||||
await updateDestroyedEmailCache(listEmailIdDeleted);
|
||||
}
|
||||
final listEmailIdDeleted = await _emailAPI.deleteMultipleEmailsPermanently(
|
||||
session,
|
||||
accountId,
|
||||
newEmailList.listEmailIds);
|
||||
emailListCompleted.addAll(listEmailIdDeleted);
|
||||
|
||||
} else {
|
||||
hasEmails = false;
|
||||
}
|
||||
|
||||
@@ -309,14 +309,17 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
|
||||
@override
|
||||
Future<List<EmailId>> emptyTrashFolder(Session session, AccountId accountId, MailboxId trashMailboxId) async {
|
||||
return mapDataSource[DataSourceType.network]!.emptyMailboxFolder(
|
||||
final listEmailIdDeleted = await mapDataSource[DataSourceType.network]!.emptyMailboxFolder(
|
||||
session,
|
||||
accountId,
|
||||
trashMailboxId,
|
||||
(listEmailIdDeleted) async {
|
||||
await _updateEmailCache(accountId, session.username, newDestroyed: listEmailIdDeleted);
|
||||
},
|
||||
);
|
||||
trashMailboxId);
|
||||
|
||||
await _updateEmailCache(
|
||||
accountId,
|
||||
session.username,
|
||||
newDestroyed: listEmailIdDeleted);
|
||||
|
||||
return listEmailIdDeleted;
|
||||
}
|
||||
|
||||
Future<void> _synchronizeCacheWithChanges(
|
||||
@@ -388,18 +391,17 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<EmailId>> emptySpamFolder(Session session, AccountId accountId, MailboxId spamMailboxId) {
|
||||
return mapDataSource[DataSourceType.network]!.emptyMailboxFolder(
|
||||
Future<List<EmailId>> emptySpamFolder(Session session, AccountId accountId, MailboxId spamMailboxId) async {
|
||||
final listEmailIdDeleted = await mapDataSource[DataSourceType.network]!.emptyMailboxFolder(
|
||||
session,
|
||||
accountId,
|
||||
spamMailboxId,
|
||||
(listEmailIdDeleted) async {
|
||||
await _updateEmailCache(
|
||||
accountId,
|
||||
session.username,
|
||||
newDestroyed: listEmailIdDeleted
|
||||
);
|
||||
},
|
||||
);
|
||||
spamMailboxId);
|
||||
|
||||
await _updateEmailCache(
|
||||
accountId,
|
||||
session.username,
|
||||
newDestroyed: listEmailIdDeleted);
|
||||
|
||||
return listEmailIdDeleted;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user