TF-3719 Delete email in cache when get notFound in Email/get

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2025-05-14 12:42:15 +07:00
committed by Dat H. Pham
parent 8bb428b8b9
commit 2b88f07f6d
3 changed files with 45 additions and 8 deletions
@@ -96,8 +96,14 @@ class ThreadAPI {
queryEmailResponse: responseOfQueryEmailMethod,
);
final notFoundEmailIds = responseOfGetEmailMethod
?.notFound
?.toEmailIds()
.toList();
log('ThreadAPI::getAllEmail:notFoundEmailIds = $notFoundEmailIds');
return EmailsResponse(
emailList: emailList,
notFoundEmailIds: notFoundEmailIds,
state: responseOfGetEmailMethod?.state,
);
}
@@ -274,10 +280,10 @@ class ThreadAPI {
changesEmailInvocation.methodCallId,
ChangesEmailResponse.deserialize);
List<EmailId>? destroyedEmailIds = resultChanges
List<EmailId> destroyedEmailIds = resultChanges
?.destroyed
.toEmailIds()
.toList();
.toList() ?? [];
State? newStateChanges = resultChanges?.newState;
bool hasMoreChanges = resultChanges?.hasMoreChanges ?? false;
List<Email>? updatedEmail;
@@ -291,6 +297,9 @@ class ThreadAPI {
);
updatedEmail = emailResponseUpdated?.list;
newStateEmail = emailResponseUpdated?.state;
final notFoundIdsUpdated = emailResponseUpdated?.notFound?.toEmailIds().toList() ?? [];
log('ThreadAPI::getChanges:notFoundIdsUpdated = $notFoundIdsUpdated');
destroyedEmailIds.addAll(notFoundIdsUpdated);
}
if (getEmailCreatedInvocation != null) {
@@ -300,8 +309,13 @@ class ThreadAPI {
);
createdEmail = emailResponseCreated?.list;
newStateEmail = emailResponseCreated?.state;
final notFoundIdsCreated = emailResponseCreated?.notFound?.toEmailIds().toList() ?? [];
log('ThreadAPI::getChanges:notFoundIdsCreated = $notFoundIdsCreated');
destroyedEmailIds.addAll(notFoundIdsCreated);
}
log('ThreadAPI::getChanges:newStateChanges = $newStateChanges | newStateEmail = $newStateEmail | hasMoreChanges = $hasMoreChanges');
log('ThreadAPI::getChanges:updatedEmailSize = ${updatedEmail?.length} | createdEmailSize = ${createdEmail?.length}');
log('ThreadAPI::getChanges:destroyedEmailIds = $destroyedEmailIds');
return EmailChangeResponse(
updated: updatedEmail,
created: createdEmail,
@@ -93,7 +93,12 @@ class ThreadRepositoryImpl extends ThreadRepository {
}
if (networkEmailResponse != null) {
await _updateEmailCache(accountId, session.username, newCreated: networkEmailResponse.emailList);
await _updateEmailCache(
accountId,
session.username,
newCreated: networkEmailResponse.emailList,
newDestroyed: networkEmailResponse.notFoundEmailIds,
);
}
if (localEmailResponse.hasState()) {
@@ -156,7 +161,12 @@ class ThreadRepositoryImpl extends ThreadRepository {
filter: filter ?? EmailFilterCondition(inMailbox: mailboxId),
properties: propertiesCreated,
);
await _updateEmailCache(accountId, session.username, newCreated: networkEmailResponse.emailList);
await _updateEmailCache(
accountId,
session.username,
newCreated: networkEmailResponse.emailList,
newDestroyed: networkEmailResponse.notFoundEmailIds,
);
return networkEmailResponse;
}
@@ -268,7 +278,12 @@ class ThreadRepositoryImpl extends ThreadRepository {
@override
Stream<EmailsResponse> loadMoreEmails(GetEmailRequest emailRequest) async* {
final response = await _getAllEmailsWithoutLastEmailId(emailRequest);
await _updateEmailCache(emailRequest.accountId, emailRequest.session.username, newCreated: response.emailList);
await _updateEmailCache(
emailRequest.accountId,
emailRequest.session.username,
newCreated: response.emailList,
newDestroyed: response.notFoundEmailIds,
);
yield response;
}
@@ -287,7 +302,11 @@ class ThreadRepositoryImpl extends ThreadRepository {
if (emailRequest.lastEmailId != null && listEmails?.isNotEmpty == true) {
listEmails?.removeWhere((email) => email.id == emailRequest.lastEmailId);
}
return EmailsResponse(emailList: listEmails, state: response.state);
return EmailsResponse(
emailList: listEmails,
state: response.state,
notFoundEmailIds: response.notFoundEmailIds,
);
});
return emailResponse;
@@ -5,10 +5,12 @@ import 'package:jmap_dart_client/jmap/mail/email/email.dart';
class EmailsResponse with EquatableMixin {
final List<Email>? emailList;
final List<EmailId>? notFoundEmailIds;
final State? state;
const EmailsResponse({
this.emailList,
this.notFoundEmailIds,
this.state
});
@@ -16,6 +18,8 @@ class EmailsResponse with EquatableMixin {
bool hasState() => state != null;
bool get existNotFoundEmails => notFoundEmailIds?.isNotEmpty == true;
@override
List<Object?> get props => [emailList, state];
List<Object?> get props => [emailList, notFoundEmailIds, state];
}