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/session/session.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.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/email_address.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/email/individual_header_identifier.dart';
|
||||||
import 'package:model/email/attachment.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/download_attachment_for_web_state.dart';
|
||||||
import 'package:tmail_ui_user/features/email/domain/state/get_html_content_from_attachment_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) {
|
static EmailUnsubscribe? parsingUnsubscribe(String listUnsubscribe) {
|
||||||
if (listUnsubscribe.isEmpty) {
|
if (listUnsubscribe.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -176,32 +176,40 @@ class ThreadRepositoryImpl extends ThreadRepository {
|
|||||||
Properties? updatedProperties,
|
Properties? updatedProperties,
|
||||||
List<Email>? emailCacheList
|
List<Email>? emailCacheList
|
||||||
}) async {
|
}) async {
|
||||||
if (emailUpdated != null && emailUpdated.isNotEmpty) {
|
if (emailUpdated == null || emailUpdated.isEmpty) return emailUpdated;
|
||||||
if (updatedProperties == null) {
|
|
||||||
return null;
|
if (updatedProperties == null) return null;
|
||||||
}
|
|
||||||
final newEmailUpdated = emailUpdated
|
if (updatedProperties.value.containsAll(ThreadConstants.propertiesDefault.value)) {
|
||||||
.map((updatedEmail) => _combineUpdatedWithEmailInCache(updatedEmail, emailCacheList))
|
log('ThreadRepositoryImpl::_combineEmailCache(): Update use properties default');
|
||||||
.where((tuple) => tuple.value2 != null)
|
return emailUpdated;
|
||||||
.map((tuple) => tuple.value2!.combineEmail(tuple.value1, updatedProperties))
|
}
|
||||||
|
|
||||||
|
final combinedEmails = emailUpdated
|
||||||
|
.map((email) => _combineUpdatedWithEmailInCache(email, emailCacheList))
|
||||||
|
.where((record) => record.oldEmail != null)
|
||||||
|
.map((record) => record.oldEmail!.combineEmail(
|
||||||
|
record.updatedEmail,
|
||||||
|
updatedProperties,
|
||||||
|
))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return newEmailUpdated;
|
return combinedEmails;
|
||||||
}
|
|
||||||
return emailUpdated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dartz.Tuple2<Email, Email?> _combineUpdatedWithEmailInCache(Email updatedEmail, List<Email>? emailCacheList) {
|
({Email updatedEmail, Email? oldEmail}) _combineUpdatedWithEmailInCache(
|
||||||
final emailOld = updatedEmail.id != null
|
Email updatedEmail,
|
||||||
? emailCacheList?.findEmailById(updatedEmail.id!)
|
List<Email>? emailCacheList,
|
||||||
: null;
|
) {
|
||||||
if (emailOld != null) {
|
final oldEmail = updatedEmail.id != null
|
||||||
log('ThreadRepositoryImpl::_combineUpdatedWithEmailInCache(): cache hit');
|
? emailCacheList?.findEmailById(updatedEmail.id!)
|
||||||
return dartz.Tuple2(updatedEmail, emailOld);
|
: 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 {
|
} else {
|
||||||
log('ThreadRepositoryImpl::_combineUpdatedWithEmailInCache(): cache miss');
|
log('ThreadRepositoryImpl::_combineUpdatedWithEmailInCache(): cache miss for emailId ${updatedEmail.id}');
|
||||||
return dartz.Tuple2(updatedEmail, null);
|
|
||||||
}
|
}
|
||||||
|
return (oldEmail: oldEmail, updatedEmail: updatedEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateEmailCache(
|
Future<void> _updateEmailCache(
|
||||||
|
|||||||
@@ -26,10 +26,7 @@ class ThreadConstants {
|
|||||||
IndividualHeaderIdentifier.importanceHeader.value,
|
IndividualHeaderIdentifier.importanceHeader.value,
|
||||||
IndividualHeaderIdentifier.priorityHeader.value,
|
IndividualHeaderIdentifier.priorityHeader.value,
|
||||||
});
|
});
|
||||||
static final propertiesUpdatedDefault = Properties({
|
static final propertiesUpdatedDefault = propertiesDefault;
|
||||||
EmailProperty.keywords,
|
|
||||||
EmailProperty.mailboxIds,
|
|
||||||
});
|
|
||||||
|
|
||||||
static final propertiesGetEmailContent = Properties({
|
static final propertiesGetEmailContent = Properties({
|
||||||
EmailProperty.bodyValues,
|
EmailProperty.bodyValues,
|
||||||
|
|||||||
+4
-1
@@ -48,7 +48,10 @@ extension HandlePullToRefreshListEmailExtension on ThreadController {
|
|||||||
mailboxId: selectedMailboxId,
|
mailboxId: selectedMailboxId,
|
||||||
),
|
),
|
||||||
propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod(session, accountId),
|
propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod(session, accountId),
|
||||||
propertiesUpdated: ThreadConstants.propertiesUpdatedDefault,
|
propertiesUpdated: EmailUtils.getPropertiesForEmailChangeMethod(
|
||||||
|
session,
|
||||||
|
accountId,
|
||||||
|
),
|
||||||
getLatestChanges: true,
|
getLatestChanges: true,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -554,7 +554,10 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
mailboxId: selectedMailboxId
|
mailboxId: selectedMailboxId
|
||||||
),
|
),
|
||||||
propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod(_session!, _accountId!),
|
propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod(_session!, _accountId!),
|
||||||
propertiesUpdated: ThreadConstants.propertiesUpdatedDefault,
|
propertiesUpdated: EmailUtils.getPropertiesForEmailChangeMethod(
|
||||||
|
_session!,
|
||||||
|
_accountId!,
|
||||||
|
),
|
||||||
getLatestChanges: getLatestChanges,
|
getLatestChanges: getLatestChanges,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
@@ -709,7 +712,10 @@ class ThreadController extends BaseController with EmailActionController {
|
|||||||
_session!,
|
_session!,
|
||||||
_accountId!,
|
_accountId!,
|
||||||
),
|
),
|
||||||
propertiesUpdated: ThreadConstants.propertiesUpdatedDefault,
|
propertiesUpdated: EmailUtils.getPropertiesForEmailChangeMethod(
|
||||||
|
_session!,
|
||||||
|
_accountId!,
|
||||||
|
),
|
||||||
emailFilter: EmailFilter(
|
emailFilter: EmailFilter(
|
||||||
filter: getFilterCondition(mailboxIdSelected: selectedMailboxId),
|
filter: getFilterCondition(mailboxIdSelected: selectedMailboxId),
|
||||||
filterOption: mailboxDashBoardController.filterMessageOption.value,
|
filterOption: mailboxDashBoardController.filterMessageOption.value,
|
||||||
|
|||||||
Reference in New Issue
Block a user