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