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