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-2302 Support Stalwart #2315

Merged
merged 10 commits into from
Nov 9, 2023
Merged
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: 1 addition & 1 deletion contact/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ packages:
description:
path: "."
ref: master
resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9
resolved-ref: a1b79695b844888ec8330d41964d1a054c348bc2
url: "https://github.com/linagora/jmap-dart-client.git"
source: git
version: "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion fcm/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ packages:
description:
path: "."
ref: master
resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9
resolved-ref: a1b79695b844888ec8330d41964d1a054c348bc2
url: "https://github.com/linagora/jmap-dart-client.git"
source: git
version: "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion forward/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ packages:
description:
path: "."
ref: master
resolved-ref: e8005e28b48ee06259d4f51045a58f20c891e0b9
resolved-ref: a1b79695b844888ec8330d41964d1a054c348bc2
url: "https://github.com/linagora/jmap-dart-client.git"
source: git
version: "0.0.1"
Expand Down
13 changes: 9 additions & 4 deletions lib/features/base/base_mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
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/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
Expand Down Expand Up @@ -530,13 +531,17 @@ abstract class BaseMailboxController extends BaseController {
void refreshMailboxChanges(
Session session,
AccountId accountId,
jmap.State currentMailboxState
jmap.State currentMailboxState,
{Properties? properties}
) {
if (refreshAllMailboxInteractor != null) {
log('BaseMailboxController::refreshMailboxChanges(): currentMailboxState: $currentMailboxState');
final newMailboxState = currentMailboxState;
log('BaseMailboxController::refreshMailboxChanges(): newMailboxState: $newMailboxState');
consumeState(refreshAllMailboxInteractor!.execute(session, accountId, newMailboxState));
consumeState(refreshAllMailboxInteractor!.execute(
session,
accountId,
currentMailboxState,
properties: properties
));
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/features/base/mixin/handle_error_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ mixin HandleSetErrorMixin {
}
}

List<MapEntry<Id, SetError>> handleSetResponse(List<SetResponse?> listSetResponse) {
Map<Id, SetError> handleSetResponse(List<SetResponse?> listSetResponse) {
final listSetResponseNotNull = listSetResponse.whereNotNull().toList();
if (listSetResponseNotNull.isEmpty) {
return [];
return <Id, SetError>{};
}

final List<MapEntry<Id, SetError>> remainedErrors = [];
final Map<Id, SetError> remainedErrors = <Id, SetError>{};
for (var response in listSetResponseNotNull) {
handleSetErrors(
notDestroyedError: response.notDestroyed,
notUpdatedError: response.notUpdated,
notCreatedError: response.notCreated,
unCatchErrorHandler: (setErrorEntry) {
remainedErrors.add(setErrorEntry);
remainedErrors.addEntries({setErrorEntry});
return false;
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import 'package:jmap_dart_client/jmap/core/error/set_error.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';

class SetEmailMethodException implements Exception {
class SetMethodException implements Exception {

final Map<Id, SetError> mapErrors;

SetEmailMethodException(this.mapErrors);
SetMethodException(this.mapErrors);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:model/contact/contact.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';

class GetDeviceContactSuggestionsSuccess extends UIState {
final List<Contact> results;
final List<EmailAddress> listEmailAddress;

GetDeviceContactSuggestionsSuccess(this.results);
GetDeviceContactSuggestionsSuccess(this.listEmailAddress);

@override
List<Object> get props => [results];
List<Object> get props => [listEmailAddress];
}

class GetDeviceContactSuggestionsFailure extends FeatureFailure {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/autocomplete/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 GetAllAutoCompleteInteractor {
final GetAutoCompleteInteractor _getAutoCompleteInteractor;
final GetDeviceContactSuggestionsInteractor _getDeviceContactSuggestionsInteractor;

GetAllAutoCompleteInteractor(
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 = List<EmailAddress>.empty(growable: true);

final listEmailAddressFromServer = resultExecutions[0].fold(
(failure) => <EmailAddress>[],
(success) => success is GetAutoCompleteSuccess
? success.listEmailAddress
: <EmailAddress>[]
);
log('GetAllAutoCompleteInteractor::execute:listEmailAddressFromServer: $listEmailAddressFromServer');
autoCompleteResults.addAll(listEmailAddressFromServer);

final listEmailAddressFromDevice = resultExecutions[1].fold(
(failure) => <EmailAddress>[],
(success) => success is GetDeviceContactSuggestionsSuccess
? success.listEmailAddress
: <EmailAddress>[]
);
log('GetAllAutoCompleteInteractor::execute:listEmailAddressFromDevice: $listEmailAddressFromDevice');
autoCompleteResults.addAll(listEmailAddressFromDevice);

return Right<Failure, Success>(GetAutoCompleteSuccess(autoCompleteResults));
} catch (exception) {
return Left<Failure, Success>(GetAutoCompleteFailure(exception));
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

import 'package:core/core.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
import 'package:dartz/dartz.dart';
import 'package:model/autocomplete/auto_complete_pattern.dart';
import 'package:model/contact/contact.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';

Expand All @@ -13,7 +16,9 @@ class GetDeviceContactSuggestionsInteractor {
Future<Either<Failure, Success>> execute(AutoCompletePattern autoCompletePattern) async {
try {
final resultList = await _contactRepository.getContactSuggestions(autoCompletePattern);
return Right<Failure, Success>(GetDeviceContactSuggestionsSuccess(resultList));
final listEmailAddress = resultList.map((contact) => contact.toEmailAddress()).toList();
log('GetDeviceContactSuggestionsInteractor::execute:listEmailAddress: $listEmailAddress');
return Right<Failure, Success>(GetDeviceContactSuggestionsSuccess(listEmailAddress));
} catch (exception) {
return Left<Failure, Success>(GetDeviceContactSuggestionsFailure(exception));
}
Expand Down
78 changes: 41 additions & 37 deletions lib/features/composer/presentation/composer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:html_editor_enhanced/html_editor.dart' as web_html_editor;
import 'package:http_parser/http_parser.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
Expand All @@ -40,11 +38,13 @@ import 'package:tmail_ui_user/features/composer/domain/model/contact_suggestion_
import 'package:tmail_ui_user/features/composer/domain/model/email_request.dart';
import 'package:tmail_ui_user/features/composer/domain/state/download_image_as_base64_state.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/state/save_email_as_drafts_state.dart';
import 'package:tmail_ui_user/features/composer/domain/state/update_email_drafts_state.dart';
import 'package:tmail_ui_user/features/composer/domain/usecases/download_image_as_base64_interactor.dart';
import 'package:tmail_ui_user/features/composer/domain/usecases/get_autocomplete_interactor.dart';
import 'package:tmail_ui_user/features/composer/domain/usecases/get_autocomplete_with_device_contact_interactor.dart';
import 'package:tmail_ui_user/features/composer/domain/usecases/get_all_autocomplete_interactor.dart';
import 'package:tmail_ui_user/features/composer/domain/usecases/get_device_contact_suggestions_interactor.dart';
import 'package:tmail_ui_user/features/composer/presentation/controller/rich_text_web_controller.dart';
import 'package:tmail_ui_user/features/composer/presentation/controller/rich_text_mobile_tablet_controller.dart';
import 'package:tmail_ui_user/features/composer/presentation/extensions/email_action_type_extension.dart';
Expand Down Expand Up @@ -129,8 +129,9 @@ class ComposerController extends BaseController {
final DownloadImageAsBase64Interactor _downloadImageAsBase64Interactor;
final TransformHtmlEmailContentInteractor _transformHtmlEmailContentInteractor;

GetAutoCompleteWithDeviceContactInteractor? _getAutoCompleteWithDeviceContactInteractor;
GetAllAutoCompleteInteractor? _getAllAutoCompleteInteractor;
GetAutoCompleteInteractor? _getAutoCompleteInteractor;
GetDeviceContactSuggestionsInteractor? _getDeviceContactSuggestionsInteractor;

List<EmailAddress> listToEmailAddress = <EmailAddress>[];
List<EmailAddress> listCcEmailAddress = <EmailAddress>[];
Expand Down Expand Up @@ -1029,52 +1030,41 @@ class ComposerController extends BaseController {
}
}

@override
void injectAutoCompleteBindings(Session? session, AccountId? accountId) {
try {
super.injectAutoCompleteBindings(session, accountId);
_getAutoCompleteWithDeviceContactInteractor = Get.find<GetAutoCompleteWithDeviceContactInteractor>();
_getAutoCompleteInteractor = Get.find<GetAutoCompleteInteractor>();
} catch (e) {
logError('ComposerController::injectAutoCompleteBindings(): $e');
}
}

Future<List<EmailAddress>> getAutoCompleteSuggestion(String word) async {
log('ComposerController::getAutoCompleteSuggestion(): $word | $_contactSuggestionSource');
try {
_getAutoCompleteWithDeviceContactInteractor = Get.find<GetAutoCompleteWithDeviceContactInteractor>();
_getAutoCompleteInteractor = Get.find<GetAutoCompleteInteractor>();
} catch (e) {
logError('ComposerController::getAutoCompleteSuggestion(): Exception $e');
}

final accountId = mailboxDashBoardController.accountId.value;
_getAllAutoCompleteInteractor = getBinding<GetAllAutoCompleteInteractor>();
_getAutoCompleteInteractor = getBinding<GetAutoCompleteInteractor>();
_getDeviceContactSuggestionsInteractor = getBinding<GetDeviceContactSuggestionsInteractor>();

if (_contactSuggestionSource == ContactSuggestionSource.all) {
if (_getAutoCompleteWithDeviceContactInteractor == null || _getAutoCompleteInteractor == null) {
if (_getAllAutoCompleteInteractor != null) {
return await _getAllAutoCompleteInteractor!
.execute(AutoCompletePattern(word: word, accountId: mailboxDashBoardController.accountId.value))
.then((value) => value.fold(
(failure) => <EmailAddress>[],
(success) => _getAutoCompleteSuccess(success, word)
));
} else if (_getDeviceContactSuggestionsInteractor != null) {
return await _getDeviceContactSuggestionsInteractor!
.execute(AutoCompletePattern(word: word, accountId: mailboxDashBoardController.accountId.value))
.then((value) => value.fold(
(failure) => <EmailAddress>[],
(success) => _getAutoCompleteSuccess(success, word)
));
} else {
return <EmailAddress>[];
}

final listEmailAddress = await _getAutoCompleteWithDeviceContactInteractor!
.execute(AutoCompletePattern(word: word, accountId: accountId))
.then((value) => value.fold(
(failure) => <EmailAddress>[],
(success) => _getAutoCompleteSuccess(success, word)
));
return listEmailAddress;
} else {
if (_getAutoCompleteInteractor == null) {
return <EmailAddress>[];
}

final listEmailAddress = await _getAutoCompleteInteractor!
.execute(AutoCompletePattern(word: word, accountId: accountId))
} else {
return await _getAutoCompleteInteractor!
.execute(AutoCompletePattern(word: word, accountId: mailboxDashBoardController.accountId.value))
.then((value) => value.fold(
(failure) => <EmailAddress>[],
(success) => _getAutoCompleteSuccess(success, word)
));
return listEmailAddress;
}
}
}

Expand All @@ -1093,6 +1083,20 @@ class ComposerController extends BaseController {
}
}
return success.listEmailAddress;
} else if (success is GetDeviceContactSuggestionsSuccess) {
if (success.listEmailAddress.isEmpty == true && GetUtils.isEmail(word)) {
final unknownEmailAddress = EmailAddress(word, word);
return <EmailAddress>[unknownEmailAddress];
}
if (GetUtils.isEmail(word)) {
bool isContainsTypedEmail = success.listEmailAddress.any((emailAddress) => emailAddress.email == word);
if (!isContainsTypedEmail) {
final unknownEmailAddress = EmailAddress(word, word);
success.listEmailAddress.insert(0, unknownEmailAddress);
return success.listEmailAddress;
}
}
return success.listEmailAddress;
} else {
return <EmailAddress>[];
}
Expand Down
Loading
Loading