Use default properties when update email from email changed

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2025-05-27 15:49:40 +07:00
committed by Dat H. Pham
parent d2f0d9e180
commit 19cede1a5f
5 changed files with 53 additions and 27 deletions
@@ -176,32 +176,40 @@ class ThreadRepositoryImpl extends ThreadRepository {
Properties? updatedProperties,
List<Email>? emailCacheList
}) async {
if (emailUpdated != null && emailUpdated.isNotEmpty) {
if (updatedProperties == null) {
return null;
}
final newEmailUpdated = emailUpdated
.map((updatedEmail) => _combineUpdatedWithEmailInCache(updatedEmail, emailCacheList))
.where((tuple) => tuple.value2 != null)
.map((tuple) => tuple.value2!.combineEmail(tuple.value1, updatedProperties))
if (emailUpdated == null || emailUpdated.isEmpty) return emailUpdated;
if (updatedProperties == null) return null;
if (updatedProperties.value.containsAll(ThreadConstants.propertiesDefault.value)) {
log('ThreadRepositoryImpl::_combineEmailCache(): Update use properties default');
return emailUpdated;
}
final combinedEmails = emailUpdated
.map((email) => _combineUpdatedWithEmailInCache(email, emailCacheList))
.where((record) => record.oldEmail != null)
.map((record) => record.oldEmail!.combineEmail(
record.updatedEmail,
updatedProperties,
))
.toList();
return newEmailUpdated;
}
return emailUpdated;
return combinedEmails;
}
dartz.Tuple2<Email, Email?> _combineUpdatedWithEmailInCache(Email updatedEmail, List<Email>? emailCacheList) {
final emailOld = updatedEmail.id != null
? emailCacheList?.findEmailById(updatedEmail.id!)
: null;
if (emailOld != null) {
log('ThreadRepositoryImpl::_combineUpdatedWithEmailInCache(): cache hit');
return dartz.Tuple2(updatedEmail, emailOld);
({Email updatedEmail, Email? oldEmail}) _combineUpdatedWithEmailInCache(
Email updatedEmail,
List<Email>? emailCacheList,
) {
final oldEmail = updatedEmail.id != null
? emailCacheList?.findEmailById(updatedEmail.id!)
: null;
if (oldEmail != null) {
log('ThredRepositoryImpl::_combineUpdatedWithEmailInCache(): cache hit for this email -> ${oldEmail.id} - ${oldEmail.subject} - ${oldEmail.keywords} - ${oldEmail.mailboxIds} - new update in $updatedEmail');
} else {
log('ThreadRepositoryImpl::_combineUpdatedWithEmailInCache(): cache miss');
return dartz.Tuple2(updatedEmail, null);
log('ThreadRepositoryImpl::_combineUpdatedWithEmailInCache(): cache miss for emailId ${updatedEmail.id}');
}
return (oldEmail: oldEmail, updatedEmail: updatedEmail);
}
Future<void> _updateEmailCache(