TF-4236 Apply BatchSetEmailProcessingMixin for some method use SetEmailMethod
This commit is contained in:
@@ -212,7 +212,10 @@ abstract class EmailDataSource {
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> addLabelToThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
@@ -226,7 +229,10 @@ abstract class EmailDataSource {
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> removeLabelFromThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> removeLabelFromThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
|
||||
@@ -572,7 +572,10 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
@@ -606,7 +609,10 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> removeLabelFromThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
|
||||
@@ -582,7 +582,10 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@@ -592,7 +595,10 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> removeLabelFromThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -358,7 +358,10 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@@ -368,7 +371,10 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> removeLabelFromThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -272,7 +272,10 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> addLabelToThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@@ -282,7 +285,10 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> removeLabelFromThread(Session session, AccountId accountId, List<EmailId> emailIds, KeyWordIdentifier labelKeyword) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -53,23 +53,27 @@ import 'package:model/extensions/list_email_id_extension.dart';
|
||||
import 'package:model/extensions/list_id_extension.dart';
|
||||
import 'package:model/extensions/mailbox_id_extension.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/batch_set_email_processing_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/handle_error_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/mail_api_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/model/email_request.dart';
|
||||
import 'package:tmail_ui_user/features/download/domain/model/download_source_view.dart';
|
||||
import 'package:tmail_ui_user/features/download/domain/state/download_all_attachments_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/download/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_to_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/restore_deleted_message_request.dart';
|
||||
import 'package:tmail_ui_user/features/download/domain/state/download_all_attachments_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/download/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/constants/thread_constants.dart';
|
||||
import 'package:tmail_ui_user/main/error/capability_validator.dart';
|
||||
import 'package:uri/uri.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
|
||||
class EmailAPI with
|
||||
HandleSetErrorMixin,
|
||||
MailAPIMixin,
|
||||
BatchSetEmailProcessingMixin {
|
||||
|
||||
final HttpClient _httpClient;
|
||||
final DownloadManager _downloadManager;
|
||||
@@ -246,51 +250,15 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
|
||||
List<EmailId> emailIds,
|
||||
ReadActions readActions,
|
||||
) async {
|
||||
final maxObjects = getMaxObjectsInSetMethod(session, accountId);
|
||||
final totalEmails = emailIds.length;
|
||||
final maxBatches = min(totalEmails, maxObjects);
|
||||
|
||||
final List<EmailId> updatedEmailIds = List.empty(growable: true);
|
||||
final Map<Id, SetError> mapErrors = <Id, SetError>{};
|
||||
|
||||
for (int start = 0; start < totalEmails; start += maxBatches) {
|
||||
int end = (start + maxBatches < totalEmails)
|
||||
? start + maxBatches
|
||||
: totalEmails;
|
||||
log('EmailAPI::markAsRead:emails from ${start + 1} to $end');
|
||||
|
||||
final currentListEmailIds = emailIds.sublist(start, end);
|
||||
|
||||
final setEmailMethod = SetEmailMethod(accountId)
|
||||
..addUpdates(
|
||||
currentListEmailIds.generateMapUpdateObjectMarkAsRead(readActions)
|
||||
);
|
||||
|
||||
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
|
||||
final setEmailInvocation = requestBuilder.invocation(setEmailMethod);
|
||||
|
||||
final capabilities = setEmailMethod.requiredCapabilities
|
||||
.toCapabilitiesSupportTeamMailboxes(session, accountId);
|
||||
|
||||
final response = await (requestBuilder
|
||||
..usings(capabilities))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
final setEmailResponse = response.parse<SetEmailResponse>(
|
||||
setEmailInvocation.methodCallId,
|
||||
SetEmailResponse.deserialize,
|
||||
);
|
||||
|
||||
final listEmailIds = setEmailResponse?.updated?.keys.toEmailIds() ?? [];
|
||||
final mapErrors = handleSetResponse([setEmailResponse]);
|
||||
|
||||
updatedEmailIds.addAll(listEmailIds);
|
||||
mapErrors.addAll(mapErrors);
|
||||
}
|
||||
|
||||
return (emailIdsSuccess: updatedEmailIds, mapErrors: mapErrors);
|
||||
return executeBatchSetEmail(
|
||||
session: session,
|
||||
accountId: accountId,
|
||||
emailIds: emailIds,
|
||||
httpClient: _httpClient,
|
||||
debugLabel: 'markAsRead',
|
||||
onGenerateUpdates: (batchIds) =>
|
||||
batchIds.generateMapUpdateObjectMarkAsRead(readActions),
|
||||
);
|
||||
}
|
||||
|
||||
Future<DownloadedResponse> exportAttachment(
|
||||
@@ -486,51 +454,15 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
|
||||
List<EmailId> emailIds,
|
||||
MarkStarAction markStarAction
|
||||
) async {
|
||||
final maxObjects = getMaxObjectsInSetMethod(session, accountId);
|
||||
final totalEmails = emailIds.length;
|
||||
final maxBatches = min(totalEmails, maxObjects);
|
||||
|
||||
final List<EmailId> updatedEmailIds = List.empty(growable: true);
|
||||
final Map<Id, SetError> mapErrors = <Id, SetError>{};
|
||||
|
||||
for (int start = 0; start < totalEmails; start += maxBatches) {
|
||||
int end = (start + maxBatches < totalEmails)
|
||||
? start + maxBatches
|
||||
: totalEmails;
|
||||
log('EmailAPI::markAsStar:emails from ${start + 1} to $end');
|
||||
|
||||
final currentListEmailIds = emailIds.sublist(start, end);
|
||||
|
||||
final setEmailMethod = SetEmailMethod(accountId)
|
||||
..addUpdates(
|
||||
currentListEmailIds.generateMapUpdateObjectMarkAsStar(markStarAction),
|
||||
);
|
||||
|
||||
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
|
||||
final setEmailInvocation = requestBuilder.invocation(setEmailMethod);
|
||||
|
||||
final capabilities = setEmailMethod.requiredCapabilities
|
||||
.toCapabilitiesSupportTeamMailboxes(session, accountId);
|
||||
|
||||
final response = await (requestBuilder
|
||||
..usings(capabilities))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
final setEmailResponse = response.parse<SetEmailResponse>(
|
||||
setEmailInvocation.methodCallId,
|
||||
SetEmailResponse.deserialize,
|
||||
);
|
||||
|
||||
final listEmailIds = setEmailResponse?.updated?.keys.toEmailIds() ?? [];
|
||||
final mapErrors = handleSetResponse([setEmailResponse]);
|
||||
|
||||
updatedEmailIds.addAll(listEmailIds);
|
||||
mapErrors.addAll(mapErrors);
|
||||
}
|
||||
|
||||
return (emailIdsSuccess: updatedEmailIds, mapErrors: mapErrors);
|
||||
return executeBatchSetEmail(
|
||||
session: session,
|
||||
accountId: accountId,
|
||||
emailIds: emailIds,
|
||||
httpClient: _httpClient,
|
||||
debugLabel: 'markAsStar',
|
||||
onGenerateUpdates: (batchIds) =>
|
||||
batchIds.generateMapUpdateObjectMarkAsStar(markStarAction),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Email> _emailSetCreateMethod(
|
||||
@@ -965,39 +897,24 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addLabelToThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) async {
|
||||
if (emailIds.isEmpty) {
|
||||
throw ArgumentError.value(emailIds, 'emailIds', 'must not be empty');
|
||||
}
|
||||
|
||||
final method = SetEmailMethod(accountId)
|
||||
..addUpdates(emailIds.generateMapUpdateObjectLabel(labelKeyword));
|
||||
|
||||
final builder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
final invocation = builder.invocation(method);
|
||||
|
||||
final capabilities = method.requiredCapabilities
|
||||
.toCapabilitiesSupportTeamMailboxes(session, accountId);
|
||||
final result = await (builder..usings(capabilities)).build().execute();
|
||||
|
||||
final response = result.parse<SetEmailResponse>(
|
||||
invocation.methodCallId,
|
||||
SetEmailResponse.deserialize,
|
||||
return executeBatchSetEmail(
|
||||
session: session,
|
||||
accountId: accountId,
|
||||
emailIds: emailIds,
|
||||
httpClient: _httpClient,
|
||||
debugLabel: 'addLabelToThread',
|
||||
onGenerateUpdates: (batchIds) =>
|
||||
batchIds.generateMapUpdateObjectLabel(labelKeyword),
|
||||
);
|
||||
|
||||
final emailIdsUpdated = response?.updated?.keys ?? <Id>[];
|
||||
final ids = emailIds.toSetIds();
|
||||
final isUpdated = ids.every(emailIdsUpdated.contains) &&
|
||||
emailIdsUpdated.length == ids.length;
|
||||
|
||||
if (emailIdsUpdated.isEmpty || !isUpdated) {
|
||||
throw parseErrorForSetResponse(response, emailIds.first.id);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeLabelFromEmail(
|
||||
@@ -1030,41 +947,25 @@ class EmailAPI with HandleSetErrorMixin, MailAPIMixin {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeLabelFromThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> removeLabelFromThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
KeyWordIdentifier labelKeyword,
|
||||
) async {
|
||||
if (emailIds.isEmpty) {
|
||||
throw ArgumentError.value(emailIds, 'emailIds', 'must not be empty');
|
||||
}
|
||||
|
||||
final method = SetEmailMethod(accountId)
|
||||
..addUpdates(emailIds.generateMapUpdateObjectLabel(
|
||||
return executeBatchSetEmail(
|
||||
session: session,
|
||||
accountId: accountId,
|
||||
emailIds: emailIds,
|
||||
httpClient: _httpClient,
|
||||
debugLabel: 'removeLabelFromThread',
|
||||
onGenerateUpdates: (batchIds) => batchIds.generateMapUpdateObjectLabel(
|
||||
labelKeyword,
|
||||
remove: true,
|
||||
));
|
||||
|
||||
final builder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
|
||||
final invocation = builder.invocation(method);
|
||||
|
||||
final capabilities = method.requiredCapabilities
|
||||
.toCapabilitiesSupportTeamMailboxes(session, accountId);
|
||||
final result = await (builder..usings(capabilities)).build().execute();
|
||||
|
||||
final response = result.parse<SetEmailResponse>(
|
||||
invocation.methodCallId,
|
||||
SetEmailResponse.deserialize,
|
||||
),
|
||||
);
|
||||
|
||||
final emailIdsUpdated = response?.updated?.keys ?? <Id>[];
|
||||
final ids = emailIds.toSetIds();
|
||||
final isUpdated = emailIdsUpdated.every(ids.contains) &&
|
||||
emailIdsUpdated.length == ids.length;
|
||||
|
||||
if (emailIdsUpdated.isEmpty || !isUpdated) {
|
||||
throw parseErrorForSetResponse(response, emailIds.first.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -497,7 +497,10 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addLabelToThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
@@ -527,7 +530,10 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> removeLabelFromThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> removeLabelFromThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
|
||||
@@ -22,4 +22,6 @@ class NotParsableBlobIdToEmailException implements Exception {
|
||||
final List<Id>? ids;
|
||||
|
||||
NotParsableBlobIdToEmailException({this.ids});
|
||||
}
|
||||
}
|
||||
|
||||
class EmailIdListIsEmptyException implements Exception {}
|
||||
@@ -169,7 +169,10 @@ abstract class EmailRepository {
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> addLabelToThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> addLabelToThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
@@ -183,7 +186,10 @@ abstract class EmailRepository {
|
||||
KeyWordIdentifier labelKeyword,
|
||||
);
|
||||
|
||||
Future<void> removeLabelFromThread(
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
})> removeLabelFromThread(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
|
||||
@@ -16,6 +16,14 @@ class AddALabelToAThreadSuccess extends UIState {
|
||||
List<Object> get props => [emailIds, labelKeyword, labelDisplay];
|
||||
}
|
||||
|
||||
class AddALabelToAThreadHasSomeFailure extends AddALabelToAThreadSuccess {
|
||||
AddALabelToAThreadHasSomeFailure(
|
||||
super.emailIds,
|
||||
super.labelKeyword,
|
||||
super.labelDisplay,
|
||||
);
|
||||
}
|
||||
|
||||
class AddALabelToAThreadFailure extends FeatureFailure {
|
||||
final String labelDisplay;
|
||||
|
||||
|
||||
@@ -20,6 +20,15 @@ class RemoveALabelFromAThreadSuccess extends UIState {
|
||||
List<Object> get props => [emailIds, labelKeyword, labelDisplay];
|
||||
}
|
||||
|
||||
class RemoveALabelFromAThreadHasSomeFailure
|
||||
extends RemoveALabelFromAThreadSuccess {
|
||||
RemoveALabelFromAThreadHasSomeFailure(
|
||||
super.emailIds,
|
||||
super.labelKeyword,
|
||||
super.labelDisplay,
|
||||
);
|
||||
}
|
||||
|
||||
class RemoveALabelFromAThreadFailure extends FeatureFailure {
|
||||
final String labelDisplay;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_a_thread_state.dart';
|
||||
|
||||
@@ -22,17 +23,30 @@ class AddALabelToAThreadInteractor {
|
||||
) async* {
|
||||
try {
|
||||
yield Right(AddingALabelToAThread());
|
||||
await _emailRepository.addLabelToThread(
|
||||
final result = await _emailRepository.addLabelToThread(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
);
|
||||
yield Right(AddALabelToAThreadSuccess(
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
labelDisplay,
|
||||
));
|
||||
if (emailIds.length == result.emailIdsSuccess.length) {
|
||||
yield Right(AddALabelToAThreadSuccess(
|
||||
result.emailIdsSuccess,
|
||||
labelKeyword,
|
||||
labelDisplay,
|
||||
));
|
||||
} else if (result.emailIdsSuccess.isEmpty) {
|
||||
yield Left(AddALabelToAThreadFailure(
|
||||
exception: EmailIdListIsEmptyException(),
|
||||
labelDisplay: labelDisplay,
|
||||
));
|
||||
} else {
|
||||
yield Right(AddALabelToAThreadHasSomeFailure(
|
||||
result.emailIdsSuccess,
|
||||
labelKeyword,
|
||||
labelDisplay,
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
yield Left(AddALabelToAThreadFailure(
|
||||
exception: e,
|
||||
|
||||
+20
-6
@@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/labels/remove_a_label_from_a_thread_state.dart';
|
||||
|
||||
@@ -22,17 +23,30 @@ class RemoveALabelFromAThreadInteractor {
|
||||
) async* {
|
||||
try {
|
||||
yield Right(RemovingALabelFromAThread());
|
||||
await _emailRepository.removeLabelFromThread(
|
||||
final result = await _emailRepository.removeLabelFromThread(
|
||||
session,
|
||||
accountId,
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
);
|
||||
yield Right(RemoveALabelFromAThreadSuccess(
|
||||
emailIds,
|
||||
labelKeyword,
|
||||
labelDisplay,
|
||||
));
|
||||
if (emailIds.length == result.emailIdsSuccess.length) {
|
||||
yield Right(RemoveALabelFromAThreadSuccess(
|
||||
result.emailIdsSuccess,
|
||||
labelKeyword,
|
||||
labelDisplay,
|
||||
));
|
||||
} else if (result.emailIdsSuccess.isEmpty) {
|
||||
yield Left(RemoveALabelFromAThreadFailure(
|
||||
exception: EmailIdListIsEmptyException(),
|
||||
labelDisplay: labelDisplay,
|
||||
));
|
||||
} else {
|
||||
yield Right(RemoveALabelFromAThreadHasSomeFailure(
|
||||
result.emailIdsSuccess,
|
||||
labelKeyword,
|
||||
labelDisplay,
|
||||
));
|
||||
}
|
||||
} catch (e) {
|
||||
yield Left(RemoveALabelFromAThreadFailure(
|
||||
exception: e,
|
||||
|
||||
@@ -169,7 +169,10 @@ extension HandleLabelForEmailExtension on SingleEmailController {
|
||||
final selectedEmail = mailboxDashBoardController.selectedEmail.value;
|
||||
if (selectedEmail?.id != emailId) return;
|
||||
|
||||
selectedEmail?.keywords?.toggleKeyword(labelKeyword, remove);
|
||||
selectedEmail?.keywords?.toggleKeyword(
|
||||
keyword: labelKeyword,
|
||||
shouldRemove: remove,
|
||||
);
|
||||
}
|
||||
|
||||
void _updateLabelOnThreadIfNeeded({
|
||||
|
||||
@@ -32,7 +32,10 @@ extension MapKeywordsExtension on Map<KeyWordIdentifier, bool>? {
|
||||
this?.remove(keyword);
|
||||
}
|
||||
|
||||
void toggleKeyword(KeyWordIdentifier keyword, bool shouldRemove) {
|
||||
void toggleKeyword({
|
||||
required KeyWordIdentifier keyword,
|
||||
required bool shouldRemove,
|
||||
}) {
|
||||
if (shouldRemove) {
|
||||
removeKeyword(keyword);
|
||||
} else {
|
||||
|
||||
+7
-3
@@ -37,7 +37,11 @@ extension AddLabelToThreadExtension on ThreadDetailController {
|
||||
emailLabels: threadLabels,
|
||||
emailIds: emailIds,
|
||||
onAddLabelToEmailsCallback: (emailIds, label, isSelected) {
|
||||
toggleLabelToThread(label, isSelected, currentEmailIds: emailIds);
|
||||
toggleLabelToThread(
|
||||
label,
|
||||
isSelected: isSelected,
|
||||
currentEmailIds: emailIds,
|
||||
);
|
||||
},
|
||||
),
|
||||
dialogLabel: 'add-label-to-thread-modal',
|
||||
@@ -45,8 +49,8 @@ extension AddLabelToThreadExtension on ThreadDetailController {
|
||||
}
|
||||
|
||||
void toggleLabelToThread(
|
||||
Label label,
|
||||
bool isSelected, {
|
||||
Label label,{
|
||||
required bool isSelected,
|
||||
List<EmailId>? currentEmailIds,
|
||||
}) {
|
||||
final accountId = mailboxDashBoardController.accountId.value;
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ extension OnThreadDetailActionClick on ThreadDetailController {
|
||||
emailInThreadDetailInfos: emailsInThreadDetailInfo,
|
||||
labels: mailboxDashBoardController.labelController.labels,
|
||||
onSelectLabelAction: (label, isSelected) {
|
||||
toggleLabelToThread(label, isSelected);
|
||||
toggleLabelToThread(label, isSelected: isSelected);
|
||||
submenuController.hide();
|
||||
popBack();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user