Use default properties when update email from email changed
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/get_html_content_from_attachment_state.dart';
|
||||
@@ -36,6 +37,17 @@ class EmailUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static Properties getPropertiesForEmailChangeMethod(Session session, AccountId accountId) {
|
||||
if (CapabilityIdentifier.jamesCalendarEvent.isSupported(session, accountId)) {
|
||||
return Properties({
|
||||
...ThreadConstants.propertiesUpdatedDefault.value,
|
||||
IndividualHeaderIdentifier.headerCalendarEvent.value,
|
||||
});
|
||||
} else {
|
||||
return ThreadConstants.propertiesUpdatedDefault;
|
||||
}
|
||||
}
|
||||
|
||||
static EmailUnsubscribe? parsingUnsubscribe(String listUnsubscribe) {
|
||||
if (listUnsubscribe.isEmpty) {
|
||||
return null;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -26,10 +26,7 @@ class ThreadConstants {
|
||||
IndividualHeaderIdentifier.importanceHeader.value,
|
||||
IndividualHeaderIdentifier.priorityHeader.value,
|
||||
});
|
||||
static final propertiesUpdatedDefault = Properties({
|
||||
EmailProperty.keywords,
|
||||
EmailProperty.mailboxIds,
|
||||
});
|
||||
static final propertiesUpdatedDefault = propertiesDefault;
|
||||
|
||||
static final propertiesGetEmailContent = Properties({
|
||||
EmailProperty.bodyValues,
|
||||
|
||||
+4
-1
@@ -48,7 +48,10 @@ extension HandlePullToRefreshListEmailExtension on ThreadController {
|
||||
mailboxId: selectedMailboxId,
|
||||
),
|
||||
propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod(session, accountId),
|
||||
propertiesUpdated: ThreadConstants.propertiesUpdatedDefault,
|
||||
propertiesUpdated: EmailUtils.getPropertiesForEmailChangeMethod(
|
||||
session,
|
||||
accountId,
|
||||
),
|
||||
getLatestChanges: true,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -554,7 +554,10 @@ class ThreadController extends BaseController with EmailActionController {
|
||||
mailboxId: selectedMailboxId
|
||||
),
|
||||
propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod(_session!, _accountId!),
|
||||
propertiesUpdated: ThreadConstants.propertiesUpdatedDefault,
|
||||
propertiesUpdated: EmailUtils.getPropertiesForEmailChangeMethod(
|
||||
_session!,
|
||||
_accountId!,
|
||||
),
|
||||
getLatestChanges: getLatestChanges,
|
||||
));
|
||||
} else {
|
||||
@@ -709,7 +712,10 @@ class ThreadController extends BaseController with EmailActionController {
|
||||
_session!,
|
||||
_accountId!,
|
||||
),
|
||||
propertiesUpdated: ThreadConstants.propertiesUpdatedDefault,
|
||||
propertiesUpdated: EmailUtils.getPropertiesForEmailChangeMethod(
|
||||
_session!,
|
||||
_accountId!,
|
||||
),
|
||||
emailFilter: EmailFilter(
|
||||
filter: getFilterCondition(mailboxIdSelected: selectedMailboxId),
|
||||
filterOption: mailboxDashBoardController.filterMessageOption.value,
|
||||
|
||||
Reference in New Issue
Block a user