TF-3515 Add save email as template feature
This commit is contained in:
@@ -123,6 +123,24 @@ abstract class EmailDataSource {
|
||||
{CancelToken? cancelToken}
|
||||
);
|
||||
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email email,
|
||||
{
|
||||
CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken
|
||||
}
|
||||
);
|
||||
|
||||
Future<Email> updateEmailTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
);
|
||||
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
|
||||
@@ -221,6 +221,46 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email email,
|
||||
{
|
||||
CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken
|
||||
}
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.saveEmailAsTemplate(
|
||||
session,
|
||||
accountId,
|
||||
email,
|
||||
createNewMailboxRequest: createNewMailboxRequest,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.updateEmailTemplate(
|
||||
session,
|
||||
accountId,
|
||||
newEmail,
|
||||
oldEmailId,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List> downloadAttachmentForWeb(
|
||||
DownloadTaskId taskId,
|
||||
|
||||
@@ -275,6 +275,36 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
return email;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email email,
|
||||
{
|
||||
CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken
|
||||
}
|
||||
) async {
|
||||
await _emailCacheManager.update(accountId, session.username, created: [email]);
|
||||
return email;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
) async {
|
||||
await _emailCacheManager.update(
|
||||
accountId,
|
||||
session.username,
|
||||
updated: [newEmail],
|
||||
);
|
||||
return newEmail;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> sendEmail(
|
||||
Session session,
|
||||
|
||||
@@ -355,4 +355,26 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
return htmlDocument;
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email email, {
|
||||
CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId, {
|
||||
CancelToken? cancelToken,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -271,4 +271,26 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
Future<String> generateEntireMessageAsDocument(ViewEntireMessageRequest entireMessageRequest) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email email, {
|
||||
CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId, {
|
||||
CancelToken? cancelToken,
|
||||
}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -656,18 +656,45 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
return (emailIdsSuccess: updatedEmailIds, mapErrors: mapErrors);
|
||||
}
|
||||
|
||||
Future<Email> saveEmailAsDrafts(
|
||||
Future<Email> _emailSetCreateMethod(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email email,
|
||||
{CancelToken? cancelToken}
|
||||
{
|
||||
CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken
|
||||
}
|
||||
) async {
|
||||
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
|
||||
MailboxId? mailboxId;
|
||||
if (createNewMailboxRequest != null) {
|
||||
final generateCreateId = Id(_uuid.v1());
|
||||
final setMailboxMethod = SetMailboxMethod(accountId)
|
||||
..addCreate(
|
||||
generateCreateId,
|
||||
Mailbox(
|
||||
name: createNewMailboxRequest.newName,
|
||||
parentId: createNewMailboxRequest.parentId,
|
||||
isSubscribed: IsSubscribed(createNewMailboxRequest.isSubscribed)
|
||||
)
|
||||
);
|
||||
|
||||
requestBuilder.invocation(setMailboxMethod);
|
||||
|
||||
mailboxId = MailboxId(ReferenceId(
|
||||
ReferencePrefix.defaultPrefix,
|
||||
generateCreateId));
|
||||
} else {
|
||||
mailboxId = email.mailboxIds?.keys.first;
|
||||
}
|
||||
if (mailboxId != null) {
|
||||
email.mailboxIds?.addAll({mailboxId: true});
|
||||
}
|
||||
final idCreateMethod = Id(_uuid.v1());
|
||||
final setEmailMethod = SetEmailMethod(accountId)
|
||||
..addCreate(idCreateMethod, email);
|
||||
|
||||
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
|
||||
final setEmailInvocation = requestBuilder.invocation(setEmailMethod);
|
||||
|
||||
final capabilities = setEmailMethod.requiredCapabilities
|
||||
@@ -693,7 +720,7 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> removeEmailDrafts(
|
||||
Future<bool> _emailSetDestroyMethod(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
@@ -728,6 +755,20 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Email> saveEmailAsDrafts(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email email,
|
||||
{CancelToken? cancelToken}
|
||||
) => _emailSetCreateMethod(session, accountId, email, cancelToken: cancelToken);
|
||||
|
||||
Future<bool> removeEmailDrafts(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
{CancelToken? cancelToken}
|
||||
) => _emailSetDestroyMethod(session, accountId, emailId, cancelToken: cancelToken);
|
||||
|
||||
Future<Email> updateEmailDrafts(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
@@ -756,6 +797,51 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
return emailCreated;
|
||||
}
|
||||
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email email,
|
||||
{
|
||||
CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken
|
||||
}
|
||||
) => _emailSetCreateMethod(session, accountId, email, createNewMailboxRequest: createNewMailboxRequest, cancelToken: cancelToken);
|
||||
|
||||
Future<bool> removeEmailTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
{CancelToken? cancelToken}
|
||||
) => _emailSetDestroyMethod(session, accountId, emailId, cancelToken: cancelToken);
|
||||
|
||||
Future<Email> updateEmailTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
) async {
|
||||
final emailCreated = await saveEmailAsTemplate(
|
||||
session,
|
||||
accountId,
|
||||
newEmail,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
|
||||
try {
|
||||
await removeEmailTemplate(
|
||||
session,
|
||||
accountId,
|
||||
oldEmailId,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
} catch (e) {
|
||||
logError('EmailAPI::updateEmailTemplate: Exception = $e');
|
||||
}
|
||||
|
||||
return emailCreated;
|
||||
}
|
||||
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
|
||||
@@ -336,6 +336,65 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> saveEmailAsTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email email,
|
||||
{
|
||||
CreateNewMailboxRequest? createNewMailboxRequest,
|
||||
CancelToken? cancelToken,
|
||||
}
|
||||
) async {
|
||||
final result = await emailDataSource[DataSourceType.network]!.saveEmailAsTemplate(
|
||||
session,
|
||||
accountId,
|
||||
email,
|
||||
createNewMailboxRequest: createNewMailboxRequest,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
try {
|
||||
await emailDataSource[DataSourceType.hiveCache]!.saveEmailAsTemplate(
|
||||
session,
|
||||
accountId,
|
||||
result,
|
||||
createNewMailboxRequest: createNewMailboxRequest,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
} catch (e) {
|
||||
logError('EmailRepositoryImpl::saveEmailAsTemplate:exception $e');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailTemplate(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Email newEmail,
|
||||
EmailId oldEmailId,
|
||||
{CancelToken? cancelToken}
|
||||
) async {
|
||||
final result = await emailDataSource[DataSourceType.network]!.updateEmailTemplate(
|
||||
session,
|
||||
accountId,
|
||||
newEmail,
|
||||
oldEmailId,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
try {
|
||||
await emailDataSource[DataSourceType.hiveCache]!.updateEmailTemplate(
|
||||
session,
|
||||
accountId,
|
||||
result,
|
||||
oldEmailId,
|
||||
);
|
||||
} catch (e) {
|
||||
logError('EmailRepositoryImpl::updateEmailTemplate:exception $e');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List> downloadAttachmentForWeb(
|
||||
DownloadTaskId taskId,
|
||||
|
||||
Reference in New Issue
Block a user