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-3334 Changing flag with web socket #3362

Merged
1 change: 1 addition & 0 deletions core/lib/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export 'presentation/extensions/string_extension.dart';
export 'presentation/extensions/tap_down_details_extension.dart';
export 'domain/extensions/media_type_extension.dart';
export 'presentation/extensions/map_extensions.dart';
export 'presentation/extensions/either_view_state_extension.dart';

// Exceptions
export 'domain/exceptions/download_file_exception.dart';
Expand Down
12 changes: 12 additions & 0 deletions core/lib/presentation/extensions/either_view_state_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';

extension EitherViewStateExtension on Either<Failure, Success> {
dynamic foldSuccessWithResult<T>() {
return fold(
(failure) => failure,
(success) => success is T ? success as T : null,
);
}
}
28 changes: 14 additions & 14 deletions lib/features/base/base_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,7 @@ abstract class BaseController extends GetxController

void onData(Either<Failure, Success> newState) {
viewState.value = newState;
viewState.value.fold(
(failure) {
if (failure is FeatureFailure) {
final isUrgentException = validateUrgentException(failure.exception);
if (isUrgentException) {
handleUrgentException(failure: failure, exception: failure.exception);
} else {
handleFailureViewState(failure);
}
} else {
handleFailureViewState(failure);
}
},
handleSuccessViewState);
viewState.value.fold(onDataFailureViewState, handleSuccessViewState);
}

void onError(dynamic error, StackTrace stackTrace) {
Expand Down Expand Up @@ -272,6 +259,19 @@ abstract class BaseController extends GetxController
}
}

void onDataFailureViewState(Failure failure) {
if (failure is FeatureFailure) {
final isUrgentException = validateUrgentException(failure.exception);
if (isUrgentException) {
handleUrgentException(failure: failure, exception: failure.exception);
} else {
handleFailureViewState(failure);
}
} else {
handleFailureViewState(failure);
}
}

void handleFailureViewState(Failure failure) async {
logError('$runtimeType::handleFailureViewState():Failure = $failure');
if (failure is LogoutOidcFailure) {
Expand Down
3 changes: 1 addition & 2 deletions lib/features/base/base_mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ abstract class BaseMailboxController extends BaseController {
teamMailboxesTree.value = tupleTree.value3;
}

Future<void> syncAllMailboxWithDisplayName(BuildContext context) async {
log("BaseMailboxController::syncAllMailboxWithDisplayName");
void syncAllMailboxWithDisplayName(BuildContext context) {
final syncedMailbox = allMailboxes
.map((mailbox) => mailbox.withDisplayName(mailbox.getDisplayName(context)))
.toList();
Expand Down
12 changes: 2 additions & 10 deletions lib/features/composer/domain/state/save_email_as_drafts_state.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/base/state/ui_action_state.dart';

class SaveEmailAsDraftsLoading extends LoadingState {}

class SaveEmailAsDraftsSuccess extends UIActionState {
class SaveEmailAsDraftsSuccess extends UIState {

final EmailId emailId;

SaveEmailAsDraftsSuccess(
this.emailId,
{
jmap.State? currentEmailState,
jmap.State? currentMailboxState,
}
) : super(currentEmailState, currentMailboxState);
SaveEmailAsDraftsSuccess(this.emailId);

@override
List<Object?> get props => [emailId, ...super.props];
Expand Down
9 changes: 2 additions & 7 deletions lib/features/composer/domain/state/send_email_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.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/core/state.dart' as jmap;
import 'package:tmail_ui_user/features/base/state/ui_action_state.dart';
import 'package:tmail_ui_user/features/composer/domain/model/email_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
import 'package:tmail_ui_user/features/sending_queue/presentation/model/sending_email_action_type.dart';

class SendEmailLoading extends LoadingState {}

class SendEmailSuccess extends UIActionState {
class SendEmailSuccess extends UIState {

final EmailRequest emailRequest;

SendEmailSuccess({
jmap.State? currentEmailState,
jmap.State? currentMailboxState,
required this.emailRequest,
}) : super(currentEmailState, currentMailboxState);
});

@override
List<Object?> get props => [
...super.props,
emailRequest,
];
}
Expand Down
12 changes: 2 additions & 10 deletions lib/features/composer/domain/state/update_email_drafts_state.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/base/state/ui_action_state.dart';

class UpdatingEmailDrafts extends LoadingState {}

class UpdateEmailDraftsSuccess extends UIActionState {
class UpdateEmailDraftsSuccess extends UIState {

final EmailId emailId;

UpdateEmailDraftsSuccess(
this.emailId,
{
jmap.State? currentEmailState,
jmap.State? currentMailboxState,
}
) : super(currentEmailState, currentMailboxState);
UpdateEmailDraftsSuccess(this.emailId);

@override
List<Object?> get props => [emailId, ...super.props];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
import 'package:dartz/dartz.dart' as dartz;
import 'package:dio/dio.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/core/state.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/composer/domain/exceptions/compose_email_exception.dart';
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
Expand All @@ -15,17 +12,14 @@ import 'package:tmail_ui_user/features/composer/domain/state/update_email_drafts
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.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/mailbox/domain/repository/mailbox_repository.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';

class CreateNewAndSaveEmailToDraftsInteractor {
final EmailRepository _emailRepository;
final MailboxRepository _mailboxRepository;
final ComposerRepository _composerRepository;

CreateNewAndSaveEmailToDraftsInteractor(
this._emailRepository,
this._mailboxRepository,
this._composerRepository,
);

Expand All @@ -36,11 +30,6 @@ class CreateNewAndSaveEmailToDraftsInteractor {
try {
yield dartz.Right<Failure, Success>(GenerateEmailLoading());

final listCurrentState = await _getStoredCurrentState(
session: createEmailRequest.session,
accountId: createEmailRequest.accountId
);

final emailCreated = await _createEmailObject(createEmailRequest);

if (emailCreated != null) {
Expand All @@ -55,11 +44,7 @@ class CreateNewAndSaveEmailToDraftsInteractor {
);

yield dartz.Right<Failure, Success>(
SaveEmailAsDraftsSuccess(
emailDraftSaved.id!,
currentMailboxState: listCurrentState?.value1,
currentEmailState: listCurrentState?.value2
)
SaveEmailAsDraftsSuccess(emailDraftSaved.id!)
);
} else {
yield dartz.Right<Failure, Success>(UpdatingEmailDrafts());
Expand All @@ -73,11 +58,7 @@ class CreateNewAndSaveEmailToDraftsInteractor {
);

yield dartz.Right<Failure, Success>(
UpdateEmailDraftsSuccess(
emailDraftSaved.id!,
currentMailboxState: listCurrentState?.value1,
currentEmailState: listCurrentState?.value2
)
UpdateEmailDraftsSuccess(emailDraftSaved.id!)
);
}
} else {
Expand Down Expand Up @@ -112,24 +93,4 @@ class CreateNewAndSaveEmailToDraftsInteractor {
return null;
}
}

Future<dartz.Tuple2<State?, State?>?> _getStoredCurrentState({
required Session session,
required AccountId accountId
}) async {
try {
final listState = await Future.wait([
_mailboxRepository.getMailboxState(session, accountId),
_emailRepository.getEmailState(session, accountId),
]);

final mailboxState = listState.first;
final emailState = listState.last;

return dartz.Tuple2(mailboxState, emailState);
} catch (e) {
logError('CreateNewAndSaveEmailToDraftsInteractor::_getStoredCurrentState: Exception: $e');
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:dartz/dartz.dart' as dartz;
import 'package:dio/dio.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/core/state.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/composer/domain/exceptions/compose_email_exception.dart';
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
Expand All @@ -15,18 +14,15 @@ import 'package:tmail_ui_user/features/composer/presentation/extensions/create_e
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.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/mailbox/domain/repository/mailbox_repository.dart';
import 'package:tmail_ui_user/features/sending_queue/presentation/model/sending_email_arguments.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';

class CreateNewAndSendEmailInteractor {
final EmailRepository _emailRepository;
final MailboxRepository _mailboxRepository;
final ComposerRepository _composerRepository;

CreateNewAndSendEmailInteractor(
this._emailRepository,
this._mailboxRepository,
this._composerRepository,
);

Expand All @@ -38,11 +34,6 @@ class CreateNewAndSendEmailInteractor {
try {
yield dartz.Right<Failure, Success>(GenerateEmailLoading());

final listCurrentState = await _getStoredCurrentState(
session: createEmailRequest.session,
accountId: createEmailRequest.accountId
);

sendingEmailArguments = await _createEmailObject(createEmailRequest);

if (sendingEmailArguments != null) {
Expand All @@ -67,8 +58,6 @@ class CreateNewAndSendEmailInteractor {

yield dartz.Right<Failure, Success>(
SendEmailSuccess(
currentMailboxState: listCurrentState?.value1,
currentEmailState: listCurrentState?.value2,
emailRequest: sendingEmailArguments.emailRequest
)
);
Expand Down Expand Up @@ -108,26 +97,6 @@ class CreateNewAndSendEmailInteractor {
}
}

Future<dartz.Tuple2<State?, State?>?> _getStoredCurrentState({
required Session session,
required AccountId accountId
}) async {
try {
final listState = await Future.wait([
_mailboxRepository.getMailboxState(session, accountId),
_emailRepository.getEmailState(session, accountId),
]);

final mailboxState = listState.first;
final emailState = listState.last;

return dartz.Tuple2(mailboxState, emailState);
} catch (e) {
logError('CreateNewAndSendEmailInteractor::_getStoredCurrentState: Exception: $e');
return null;
}
}

Future<void> _deleteOldDraftsEmail({
required Session session,
required AccountId accountId,
Expand Down
20 changes: 2 additions & 18 deletions lib/features/composer/domain/usecases/send_email_interactor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import 'package:tmail_ui_user/features/composer/domain/model/email_request.dart'
import 'package:tmail_ui_user/features/composer/domain/state/send_email_state.dart';
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
import 'package:tmail_ui_user/features/sending_queue/presentation/model/sending_email_action_type.dart';

class SendEmailInteractor {
final EmailRepository _emailRepository;
final MailboxRepository _mailboxRepository;

SendEmailInteractor(
this._emailRepository,
this._mailboxRepository);
SendEmailInteractor(this._emailRepository);

Stream<Either<Failure, Success>> execute(
Session session,
Expand All @@ -30,14 +26,6 @@ class SendEmailInteractor {
try {
yield Right<Failure, Success>(SendEmailLoading());

final listState = await Future.wait([
_mailboxRepository.getMailboxState(session, accountId),
_emailRepository.getEmailState(session, accountId),
], eagerError: true);

final currentMailboxState = listState.first;
final currentEmailState = listState.last;

await _emailRepository.sendEmail(
session,
accountId,
Expand All @@ -50,11 +38,7 @@ class SendEmailInteractor {
}

yield Right<Failure, Success>(
SendEmailSuccess(
currentEmailState: currentEmailState,
currentMailboxState: currentMailboxState,
emailRequest: emailRequest
)
SendEmailSuccess(emailRequest: emailRequest)
);
} catch (e) {
yield Left<Failure, Success>(SendEmailFailure(
Expand Down
2 changes: 0 additions & 2 deletions lib/features/composer/presentation/composer_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,10 @@ class ComposerBindings extends BaseBindings {
Get.lazyPut(() => GetAlwaysReadReceiptSettingInteractor(Get.find<ServerSettingsRepository>()));
Get.lazyPut(() => CreateNewAndSendEmailInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>(),
Get.find<ComposerRepository>(),
));
Get.lazyPut(() => CreateNewAndSaveEmailToDraftsInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>(),
Get.find<ComposerRepository>(),
));
Get.lazyPut(() => RestoreEmailInlineImagesInteractor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ class DestinationPickerController extends BaseMailboxController {
await buildTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes);
}
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
syncAllMailboxWithDisplayName(currentContext!);
}
} else if (success is RefreshChangesAllMailboxSuccess) {
await refreshTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes);
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
syncAllMailboxWithDisplayName(currentContext!);
}
} else if (success is SearchMailboxSuccess) {
_searchMailboxSuccess(success);
Expand Down
Loading
Loading