TF-60 Add domain get device contact suggestion
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
|
||||
enum ContactSuggestionSource {
|
||||
all, localContact, deviceContact
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/model/auto_complete_pattern.dart';
|
||||
|
||||
abstract class ContactRepository {
|
||||
Future<List<Contact>> getContactSuggestions(AutoCompletePattern autoCompletePattern);
|
||||
}
|
||||
+4
-4
@@ -1,20 +1,20 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
|
||||
class SearchEmailAddressSuccess extends UIState {
|
||||
class GetAutoCompleteSuccess extends UIState {
|
||||
|
||||
final List<EmailAddress> listEmailAddress;
|
||||
|
||||
SearchEmailAddressSuccess(this.listEmailAddress);
|
||||
GetAutoCompleteSuccess(this.listEmailAddress);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [listEmailAddress];
|
||||
}
|
||||
|
||||
class SearchEmailAddressFailure extends FeatureFailure {
|
||||
class GetAutoCompleteFailure extends FeatureFailure {
|
||||
final exception;
|
||||
|
||||
SearchEmailAddressFailure(this.exception);
|
||||
GetAutoCompleteFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class GetDeviceContactSuggestionsSuccess extends UIState {
|
||||
final List<Contact> results;
|
||||
|
||||
GetDeviceContactSuggestionsSuccess(this.results);
|
||||
|
||||
@override
|
||||
List<Object> get props => [results];
|
||||
}
|
||||
|
||||
class GetDeviceContactSuggestionsFailure extends FeatureFailure {
|
||||
final exception;
|
||||
|
||||
GetDeviceContactSuggestionsFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
+5
-6
@@ -2,20 +2,19 @@ import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/model/auto_complete_pattern.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/auto_complete_repository.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/save_email_address_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/search_email_address_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/get_autocomplete_state.dart';
|
||||
|
||||
class SearchEmailAddressInteractor {
|
||||
class GetAutoCompleteInteractor {
|
||||
final AutoCompleteRepository autoCompleteRepository;
|
||||
|
||||
SearchEmailAddressInteractor(this.autoCompleteRepository);
|
||||
GetAutoCompleteInteractor(this.autoCompleteRepository);
|
||||
|
||||
Future<Either<Failure, Success>> execute(AutoCompletePattern autoCompletePattern) async {
|
||||
try {
|
||||
final listEmailAddress = await autoCompleteRepository.getAutoComplete(autoCompletePattern);
|
||||
return Right(SearchEmailAddressSuccess(listEmailAddress));
|
||||
return Right(GetAutoCompleteSuccess(listEmailAddress));
|
||||
} catch (e) {
|
||||
return Left(SaveEmailAddressFailure(e));
|
||||
return Left(GetAutoCompleteFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/model/auto_complete_pattern.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/get_autocomplete_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/get_device_contact_suggestions_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/get_autocomplete_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/usecases/get_device_contact_suggestions_interactor.dart';
|
||||
|
||||
class GetAutoCompleteWithDeviceContactInteractor {
|
||||
final GetAutoCompleteInteractor _getAutoCompleteInteractor;
|
||||
final GetDeviceContactSuggestionsInteractor _getDeviceContactSuggestionsInteractor;
|
||||
|
||||
GetAutoCompleteWithDeviceContactInteractor(this._getAutoCompleteInteractor, this._getDeviceContactSuggestionsInteractor);
|
||||
|
||||
Future<Either<Failure, Success>> execute(AutoCompletePattern autoCompletePattern) async {
|
||||
try {
|
||||
final resultExecutions = await Future.wait([
|
||||
_getAutoCompleteInteractor.execute(autoCompletePattern),
|
||||
_getDeviceContactSuggestionsInteractor.execute(autoCompletePattern)
|
||||
]);
|
||||
|
||||
final autoCompleteResults = resultExecutions.first.fold(
|
||||
(failure) => <EmailAddress>[],
|
||||
(success) => success is GetAutoCompleteSuccess ? success.listEmailAddress : <EmailAddress>[]);
|
||||
|
||||
resultExecutions.last.map((success) {
|
||||
if (success is GetDeviceContactSuggestionsSuccess && success.results.isNotEmpty) {
|
||||
autoCompleteResults.addAll(success.results.map((contact) => contact.toEmailAddress()));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return Right<Failure, Success>(GetAutoCompleteSuccess(autoCompleteResults));
|
||||
} catch (exception) {
|
||||
return Left<Failure, Success>(GetAutoCompleteFailure(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/model/auto_complete_pattern.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/contact_repository.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/get_device_contact_suggestions_state.dart';
|
||||
|
||||
class GetDeviceContactSuggestionsInteractor {
|
||||
final ContactRepository _contactRepository;
|
||||
|
||||
GetDeviceContactSuggestionsInteractor(this._contactRepository);
|
||||
|
||||
Future<Either<Failure, Success>> execute(AutoCompletePattern autoCompletePattern) async {
|
||||
try {
|
||||
final resultList = await _contactRepository.getContactSuggestions(autoCompletePattern);
|
||||
return Right<Failure, Success>(GetDeviceContactSuggestionsSuccess(resultList));
|
||||
} catch (exception) {
|
||||
return Left<Failure, Success>(GetDeviceContactSuggestionsFailure(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
|
||||
abstract class Contact with EquatableMixin {
|
||||
final String displayName;
|
||||
final String email;
|
||||
|
||||
Contact(this.displayName, this.email);
|
||||
|
||||
@override
|
||||
List<Object> get props => [displayName, email];
|
||||
}
|
||||
|
||||
extension ContactExtension on Contact {
|
||||
EmailAddress toEmailAddress() => EmailAddress(displayName, email);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:model/contact/contact.dart';
|
||||
|
||||
class DeviceContact extends Contact implements EquatableMixin {
|
||||
DeviceContact(String displayName, String email) : super(displayName, email);
|
||||
|
||||
@override
|
||||
List<Object> get props => super.props;
|
||||
}
|
||||
@@ -37,4 +37,8 @@ export 'extensions/keyword_identifier_extension.dart';
|
||||
export 'extensions/presentation_mailbox_extension.dart';
|
||||
|
||||
// Download
|
||||
export 'download/download_task_id.dart';
|
||||
export 'download/download_task_id.dart';
|
||||
|
||||
// Contact
|
||||
export 'contact/contact.dart';
|
||||
export 'contact/device_contact.dart';
|
||||
@@ -113,6 +113,12 @@ dependencies:
|
||||
# share
|
||||
share: 2.0.4
|
||||
|
||||
# flutter_contacts
|
||||
contacts_service:
|
||||
git:
|
||||
url: git://github.com/linagora/flutter_contacts.git
|
||||
ref: master
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
Reference in New Issue
Block a user