Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF-2668 Add warning icon when email rule has target mailbox no exist #2790

Open
wants to merge 2 commits into
base: refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/features/mailbox/data/datasource/mailbox_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ abstract class MailboxDataSource {
Future<GetMailboxByRoleResponse> getMailboxByRole(Session session, AccountId accountId, Role role);

Future<void> clearAllMailboxCache(AccountId accountId, UserName userName);

Future<List<MailboxId>> getListMailboxById(Session session, AccountId accountId, List<MailboxId> mailboxIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
return await _mailboxCacheManager.clearAll(accountId, userName);
}).catchError(_exceptionThrower.throwException);
}

@override
Future<List<MailboxId>> getListMailboxById(Session session, AccountId accountId, List<MailboxId> mailboxIds) {
throw UnimplementedError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,11 @@ class MailboxDataSourceImpl extends MailboxDataSource {
Future<void> clearAllMailboxCache(AccountId accountId, UserName userName) {
throw UnimplementedError();
}

@override
Future<List<MailboxId>> getListMailboxById(Session session, AccountId accountId, List<MailboxId> mailboxIds) {
return Future.sync(() async {
return await mailboxAPI.getListMailboxById(session, accountId, mailboxIds);
}).catchError(_exceptionThrower.throwException);
}
}
31 changes: 31 additions & 0 deletions lib/features/mailbox/data/network/mailbox_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exc
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_change_response.dart';
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/mailbox_exception.dart';
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/set_mailbox_method_exception.dart';
import 'package:tmail_ui_user/features/mailbox/domain/extensions/list_mailbox_extension.dart';
import 'package:tmail_ui_user/features/mailbox/domain/extensions/list_mailbox_id_extension.dart';
import 'package:tmail_ui_user/features/mailbox/domain/extensions/role_extension.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
Expand Down Expand Up @@ -555,4 +556,34 @@ class MailboxAPI with HandleSetErrorMixin {
throw NotFoundMailboxException();
}
}

Future<List<MailboxId>> getListMailboxById(Session session, AccountId accountId, List<MailboxId> mailboxIds) async {
final processingInvocation = ProcessingInvocation();

final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation);

final getMailboxCreated = GetMailboxMethod(accountId)
..addIds(mailboxIds.ids)
..addProperties(Properties({MailboxProperty.id}));

final queryInvocation = jmapRequestBuilder.invocation(getMailboxCreated);

final capabilities = getMailboxCreated.requiredCapabilities
.toCapabilitiesSupportTeamMailboxes(session, accountId);

final result = await (jmapRequestBuilder
..usings(capabilities))
.build()
.execute();

final getMailboxResponse = result.parse<GetMailboxResponse>(
queryInvocation.methodCallId,
GetMailboxResponse.deserialize);

if (getMailboxResponse != null && getMailboxResponse.list.isNotEmpty) {
return getMailboxResponse.list.mailboxIds;
} else {
throw NotFoundMailboxException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,9 @@ class MailboxRepositoryImpl extends MailboxRepository {
Future<GetMailboxByRoleResponse> getMailboxByRole(Session session, AccountId accountId, Role role, {UnsignedInt? limit}) {
return mapDataSource[DataSourceType.network]!.getMailboxByRole(session, accountId, role);
}

@override
Future<List<MailboxId>> getListMailboxById(Session session, AccountId accountId, List<MailboxId> mailboxIds) {
return mapDataSource[DataSourceType.network]!.getListMailboxById(session, accountId, mailboxIds);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:built_collection/built_collection.dart';
import 'package:collection/collection.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/model.dart';
Expand All @@ -18,4 +19,6 @@ extension ListMailboxExtensions on List<Mailbox> {
validBuilder.build().toList(),
invalidBuilder.build().toList());
}

List<MailboxId> get mailboxIds => map((mailbox) => mailbox.id).whereNotNull().toList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ extension ListMailboxIdExtension on List<MailboxId> {
};
return maps;
}

Set<Id> get ids => map((mailboxId) => mailboxId.id).toSet();
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ abstract class MailboxRepository {
Future<void> setRoleDefaultMailbox(Session session, AccountId accountId, List<Mailbox> listMailbox);

Future<GetMailboxByRoleResponse> getMailboxByRole(Session session, AccountId accountId, Role role, {UnsignedInt? limit});

Future<List<MailboxId>> getListMailboxById(Session session, AccountId accountId, List<MailboxId> mailboxIds);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';

class GetListMailboxByIdLoading extends LoadingState {}

class GetListMailboxByIdSuccess extends UIState {
final List<MailboxId> mailboxIds;

GetListMailboxByIdSuccess(this.mailboxIds);

@override
List<Object?> get props => [mailboxIds];
}

class GetListMailboxByIdFailure extends FeatureFailure {

GetListMailboxByIdFailure(dynamic exception) : super(exception: exception);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
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/mailbox/mailbox.dart';
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
import 'package:tmail_ui_user/features/mailbox/domain/state/get_list_mailbox_by_id_state.dart';

class GetListMailboxByIdInteractor {
final MailboxRepository _mailboxRepository;

GetListMailboxByIdInteractor(this._mailboxRepository);

Stream<Either<Failure, Success>> execute(
Session session,
AccountId accountId,
List<MailboxId> mailboxIds
) async* {
try {
yield Right<Failure, Success>(GetListMailboxByIdLoading());
final mailboxIdsExist = await _mailboxRepository.getListMailboxById(session, accountId, mailboxIds);
yield Right<Failure, Success>(GetListMailboxByIdSuccess(mailboxIdsExist));
} catch (e) {
yield Left<Failure, Success>(GetListMailboxByIdFailure(e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:rule_filter/rule_filter/tmail_rule.dart';

class GetAllRulesLoading extends LoadingState {}

class GetAllRulesSuccess extends UIState {
final List<TMailRule>? rules;
final List<TMailRule> rules;

GetAllRulesSuccess(this.rules);

@override
List<Object?> get props => [rules];
List<Object> get props => [rules];
}

class GetAllRulesFailure extends FeatureFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DeleteEmailRuleInteractor {

Stream<Either<Failure, Success>> execute(AccountId accountId, DeleteEmailRuleRequest deleteEmailRuleRequest) async* {
try {
final result = await _ruleFilterRepository.deleteTMailRule(accountId, deleteEmailRuleRequest);
final result = await _ruleFilterRepository.deleteTMailRule(accountId, deleteEmailRuleRequest);
yield Right(DeleteEmailRuleSuccess(result));
} catch (exception) {
yield Left(DeleteEmailRuleFailure(exception));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import 'package:core/data/model/source_type/data_source_type.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/base/interactors_bindings.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_datasource_impl.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/state_datasource_impl.dart';
import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart';
import 'package:tmail_ui_user/features/mailbox/data/local/state_cache_manager.dart';
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_isolate_worker.dart';
import 'package:tmail_ui_user/features/mailbox/data/repository/mailbox_repository_impl.dart';
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_list_mailbox_by_id_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/data/datasource/rule_filter_datasource.dart';
import 'package:tmail_ui_user/features/manage_account/data/datasource_impl/rule_filter_datasource_impl.dart';
import 'package:tmail_ui_user/features/manage_account/data/network/rule_filter_api.dart';
Expand All @@ -9,20 +22,35 @@ import 'package:tmail_ui_user/features/manage_account/domain/usecases/delete_ema
import 'package:tmail_ui_user/features/manage_account/domain/usecases/create_new_email_rule_filter_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/domain/usecases/edit_email_rule_filter_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_rules_interactor.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
import 'package:tmail_ui_user/main/utils/ios_sharing_manager.dart';

class EmailRulesInteractorBindings extends InteractorsBindings {

@override
void bindingsDataSource() {
Get.lazyPut<RuleFilterDataSource>(() => Get.find<RuleFilterDataSourceImpl>());
Get.lazyPut<MailboxDataSource>(() => Get.find<MailboxDataSourceImpl>());
Get.lazyPut<StateDataSource>(() => Get.find<StateDataSourceImpl>());
}

@override
void bindingsDataSourceImpl() {
Get.lazyPut(() => RuleFilterDataSourceImpl(
Get.find<RuleFilterAPI>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => StateDataSourceImpl(
Get.find<StateCacheManager>(),
Get.find<IOSSharingManager>(),
Get.find<CacheExceptionThrower>()));
}

@override
Expand All @@ -31,15 +59,24 @@ class EmailRulesInteractorBindings extends InteractorsBindings {
Get.lazyPut(() => DeleteEmailRuleInteractor(Get.find<RuleFilterRepository>()));
Get.lazyPut(() => CreateNewEmailRuleFilterInteractor(Get.find<RuleFilterRepository>()));
Get.lazyPut(() => EditEmailRuleFilterInteractor(Get.find<RuleFilterRepository>()));
Get.lazyPut(() => GetListMailboxByIdInteractor(Get.find<MailboxRepository>()));
}

@override
void bindingsRepository() {
Get.lazyPut<RuleFilterRepository>(() => Get.find<RuleFilterRepositoryImpl>());
Get.lazyPut<MailboxRepository>(() => Get.find<MailboxRepositoryImpl>());
}

@override
void bindingsRepositoryImpl() {
Get.lazyPut(() => RuleFilterRepositoryImpl(Get.find<RuleFilterDataSource>()));
Get.lazyPut(() => MailboxRepositoryImpl(
{
DataSourceType.network: Get.find<MailboxDataSource>(),
DataSourceType.local: Get.find<MailboxCacheDataSourceImpl>()
},
Get.find<StateDataSource>(),
));
}
}
Loading
Loading