Skip to content

Commit

Permalink
TF-2646 Handle mark all as starred for selection emails
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Dec 13, 2024
1 parent ae1e2c2 commit b05496c
Show file tree
Hide file tree
Showing 22 changed files with 559 additions and 33 deletions.
5 changes: 5 additions & 0 deletions lib/features/mailbox/presentation/mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart';
import 'package:tmail_ui_user/features/thread/domain/state/delete_all_permanently_emails_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/empty_spam_folder_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/empty_trash_folder_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_all_as_starred_selection_all_emails_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_all_as_unread_selection_all_emails_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_as_multiple_email_read_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/move_all_selection_all_emails_state.dart';
Expand Down Expand Up @@ -317,6 +318,10 @@ class MailboxController extends BaseMailboxController
_refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is DeleteAllPermanentlyEmailsSuccess) {
_refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MarkAllAsStarredSelectionAllEmailsAllSuccess) {
_refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
} else if (success is MarkAllAsStarredSelectionAllEmailsHasSomeEmailFailure) {
_refreshMailboxChanges(currentMailboxState: success.currentMailboxState);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ import 'package:tmail_ui_user/features/thread/domain/usecases/delete_all_permane
import 'package:tmail_ui_user/features/thread/domain/usecases/empty_spam_folder_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/empty_trash_folder_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/get_email_by_id_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/mark_all_as_starred_selection_all_emails_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/mark_all_as_unread_selection_all_emails_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/mark_as_multiple_email_read_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/mark_as_star_multiple_email_interactor.dart';
Expand Down Expand Up @@ -190,6 +191,7 @@ class MailboxDashBoardBindings extends BaseBindings {
Get.find<MarkAllAsUnreadSelectionAllEmailsInteractor>(),
Get.find<MoveAllSelectionAllEmailsInteractor>(),
Get.find<DeleteAllPermanentlyEmailsInteractor>(),
Get.find<MarkAllAsStarredSelectionAllEmailsInteractor>(),
));
Get.put(AdvancedFilterController());
}
Expand Down Expand Up @@ -380,6 +382,11 @@ class MailboxDashBoardBindings extends BaseBindings {
Get.find<MailboxRepository>(),
Get.find<ThreadRepository>(),
));
Get.lazyPut(() => MarkAllAsStarredSelectionAllEmailsInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>(),
Get.find<ThreadRepository>(),
));
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ import 'package:tmail_ui_user/features/thread/domain/state/delete_all_permanentl
import 'package:tmail_ui_user/features/thread/domain/state/empty_spam_folder_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/empty_trash_folder_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/get_email_by_id_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_all_as_starred_selection_all_emails_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_all_as_unread_selection_all_emails_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_as_multiple_email_read_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_as_star_multiple_email_state.dart';
Expand All @@ -157,6 +158,7 @@ import 'package:tmail_ui_user/features/thread/domain/usecases/delete_all_permane
import 'package:tmail_ui_user/features/thread/domain/usecases/empty_spam_folder_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/empty_trash_folder_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/get_email_by_id_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/mark_all_as_starred_selection_all_emails_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/mark_all_as_unread_selection_all_emails_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/mark_as_multiple_email_read_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/mark_as_star_multiple_email_interactor.dart';
Expand Down Expand Up @@ -218,6 +220,7 @@ class MailboxDashBoardController extends ReloadableController
final MarkAllAsUnreadSelectionAllEmailsInteractor _markAllAsUnreadSelectionAllEmailsInteractor;
final MoveAllSelectionAllEmailsInteractor _moveAllSelectionAllEmailsInteractor;
final DeleteAllPermanentlyEmailsInteractor _deleteAllPermanentlyEmailsInteractor;
final MarkAllAsStarredSelectionAllEmailsInteractor _markAllAsStarredSelectionAllEmailsInteractor;

GetAllVacationInteractor? _getAllVacationInteractor;
UpdateVacationInteractor? _updateVacationInteractor;
Expand Down Expand Up @@ -255,6 +258,7 @@ class MailboxDashBoardController extends ReloadableController
final markAllAsUnreadSelectionAllEmailsViewState = Rx<Either<Failure, Success>>(Right(UIState.idle));
final moveAllSelectionAllEmailsViewState = Rx<Either<Failure, Success>>(Right(UIState.idle));
final deleteAllPermanentlyEmailsViewState = Rx<Either<Failure, Success>>(Right(UIState.idle));
final markAllAsStarredSelectionAllEmailsViewState = Rx<Either<Failure, Success>>(Right(UIState.idle));

Session? sessionCurrent;
Map<Role, MailboxId> mapDefaultMailboxIdByRole = {};
Expand All @@ -276,6 +280,7 @@ class MailboxDashBoardController extends ReloadableController
late StreamSubscription _markAllAsUnreadSelectionAllEmailsStreamSubscription;
late StreamSubscription _moveAllSelectionAllEmailsStreamSubscription;
late StreamSubscription _deleteAllPermanentlyEmailsStreamSubscription;
late StreamSubscription _markAllAsStarredSelectionAllEmailsStreamSubscription;

final StreamController<Either<Failure, Success>> _markAsReadMailboxStreamController =
StreamController<Either<Failure, Success>>.broadcast();
Expand All @@ -287,6 +292,8 @@ class MailboxDashBoardController extends ReloadableController
StreamController<Either<Failure, Success>>.broadcast();
final StreamController<Either<Failure, Success>> _deleteAllPermanentlyEmailsStreamController =
StreamController<Either<Failure, Success>>.broadcast();
final StreamController<Either<Failure, Success>> _markAllAsStarredSelectionAllEmailsStreamController =
StreamController<Either<Failure, Success>>.broadcast();

final _notificationManager = LocalNotificationManager.instance;
final _fcmService = FcmService.instance;
Expand Down Expand Up @@ -320,6 +327,7 @@ class MailboxDashBoardController extends ReloadableController
this._markAllAsUnreadSelectionAllEmailsInteractor,
this._moveAllSelectionAllEmailsInteractor,
this._deleteAllPermanentlyEmailsInteractor,
this._markAllAsStarredSelectionAllEmailsInteractor,
);

@override
Expand Down Expand Up @@ -451,6 +459,9 @@ class MailboxDashBoardController extends ReloadableController
_handleMoveAllSelectionAllEmailsSuccess(success);
} else if (success is DeleteAllPermanentlyEmailsSuccess) {
_handleDeleteAllPermanentlyEmailsSuccess(success);
} else if (success is MarkAllAsStarredSelectionAllEmailsAllSuccess
|| success is MarkAllAsStarredSelectionAllEmailsHasSomeEmailFailure) {
_handleMarkAllAsStarredSelectionAllEmailsSuccess(success);
}
}

Expand Down Expand Up @@ -487,6 +498,9 @@ class MailboxDashBoardController extends ReloadableController
_handleMoveAllSelectionAllEmailsFailure(failure);
} else if (failure is DeleteAllPermanentlyEmailsFailure) {
_handleDeleteAllPermanentlyEmailsFailure(failure);
} else if (failure is MarkAllAsStarredSelectionAllEmailsFailure
|| failure is MarkAllAsStarredSelectionAllEmailsAllFailure) {
_handleMarkAllAsStarredSelectionAllEmailsFailure(failure);
}
}

Expand Down Expand Up @@ -688,6 +702,10 @@ class MailboxDashBoardController extends ReloadableController
deleteAllPermanentlyEmailsViewState.value = state;
});

_markAllAsStarredSelectionAllEmailsStreamSubscription = _markAllAsStarredSelectionAllEmailsStreamController.stream.listen((state) {
markAllAsStarredSelectionAllEmailsViewState.value = state;
});

_registerLocalNotificationStreamListener();
}

Expand Down Expand Up @@ -3203,6 +3221,47 @@ class MailboxDashBoardController extends ReloadableController
);
}

void markAllAsStarredSelectionAllEmails(
Session session,
AccountId accountId,
MailboxId mailboxId,
String mailboxDisplayName,
int totalEmails
) {
consumeState(_markAllAsStarredSelectionAllEmailsInteractor.execute(
session,
accountId,
mailboxId,
mailboxDisplayName,
totalEmails,
_markAllAsUnreadSelectionAllEmailsStreamController
));
}

void _handleMarkAllAsStarredSelectionAllEmailsSuccess(Success success) {
markAllAsStarredSelectionAllEmailsViewState.value = Right(UIState.idle);

if (currentContext == null || currentOverlayContext == null) return;

toastManager.showSuccessMessage(
context: currentContext!,
overlayContext: currentOverlayContext!,
success: success,
);
}

void _handleMarkAllAsStarredSelectionAllEmailsFailure(Failure failure) {
markAllAsStarredSelectionAllEmailsViewState.value = Right(UIState.idle);

if (currentContext == null || currentOverlayContext == null) return;

toastManager.showFailureMessage(
context: currentContext!,
overlayContext: currentOverlayContext!,
failure: failure,
);
}

@override
void onClose() {
if (PlatformInfo.isWeb) {
Expand All @@ -3228,6 +3287,8 @@ class MailboxDashBoardController extends ReloadableController
_moveAllSelectionAllEmailsStreamController.close();
_deleteAllPermanentlyEmailsStreamSubscription.cancel();
_deleteAllPermanentlyEmailsStreamController.close();
_markAllAsStarredSelectionAllEmailsStreamSubscription.cancel();
_markAllAsStarredSelectionAllEmailsStreamController.close();
_notificationManager.closeStream();
_fcmService.closeStream();
applicationManager.releaseUserAgent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/do
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/mark_mailbox_as_read_loading_banner.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/navigation_bar/navigation_bar_widget.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/loading/delete_all_permanently_emails_loading_widget.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/loading/mark_all_as_starred_selection_all_emails_loading_widget.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/loading/mark_all_as_unread_selection_all_emails_loading_widget.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/loading/mark_mailbox_as_read_loading_widget.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/loading/move_all_selection_all_emails_loading_widget.dart';
Expand Down Expand Up @@ -141,6 +142,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
Obx(() => MarkAllAsUnreadSelectionAllEmailsLoadingWidget(viewState: controller.markAllAsUnreadSelectionAllEmailsViewState.value)),
Obx(() => MoveAllSelectionAllEmailsLoadingWidget(viewState: controller.moveAllSelectionAllEmailsViewState.value)),
Obx(() => DeleteAllPermanentlyEmailsLoadingWidget(viewState: controller.deleteAllPermanentlyEmailsViewState.value)),
Obx(() => MarkAllAsStarredSelectionAllEmailsLoadingWidget(viewState: controller.markAllAsStarredSelectionAllEmailsViewState.value)),
Expanded(child: Obx(() {
switch(controller.dashboardRoute.value) {
case DashboardRoutes.thread:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter/material.dart';
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_all_as_starred_selection_all_emails_state.dart';

class MarkAllAsStarredSelectionAllEmailsLoadingWidget extends StatelessWidget with AppLoaderMixin {

final Either<Failure, Success> viewState;

const MarkAllAsStarredSelectionAllEmailsLoadingWidget({super.key, required this.viewState});

@override
Widget build(BuildContext context) {
return viewState.fold(
(failure) => const SizedBox.shrink(),
(success) {
if (success is MarkAllAsStarredSelectionAllEmailsLoading) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: horizontalLoadingWidget
);
} else if (success is MarkAllAsStarredSelectionAllEmailsUpdating) {
final percent = success.total > 0
? success.countStarred / success.total
: 0.0;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: horizontalPercentLoadingWidget(percent)
);
}
return const SizedBox.shrink();
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,13 @@ class TopBarThreadSelection extends StatelessWidget{
)
),
TMailButtonWidget.fromIcon(
icon: listEmail.isAllEmailStarred
? imagePaths.icUnStar
: imagePaths.icStar,
tooltipMessage: listEmail.isAllEmailStarred
? AppLocalizations.of(context).un_star
: AppLocalizations.of(context).star,
icon: _getIconForMarkAsStar(),
tooltipMessage: _getTooltipMessageForMarkAsStar(context),
backgroundColor: Colors.transparent,
iconSize: 24,
onTapActionCallback: () => onEmailActionTypeAction?.call(
List.from(listEmail),
listEmail.isAllEmailStarred ? EmailActionType.unMarkAsStarred : EmailActionType.markAsStarred
_getActionTypeForMarkAsStar()
)
),
if (canSpamAndMove)
Expand Down Expand Up @@ -241,4 +237,35 @@ class TopBarThreadSelection extends StatelessWidget{
return EmailActionType.moveToTrash;
}
}

String _getIconForMarkAsStar() {
if (isSelectAllEmailsEnabled) {
return imagePaths.icStar;
} else {
return listEmail.isAllEmailStarred
? imagePaths.icUnStar
: imagePaths.icStar;
}
}

String _getTooltipMessageForMarkAsStar(BuildContext context) {
if (isSelectAllEmailsEnabled) {
return AppLocalizations.of(context).allStarred;
} else {
return listEmail.isAllEmailStarred
? AppLocalizations.of(context).un_star
: AppLocalizations.of(context).star;
}
}


EmailActionType _getActionTypeForMarkAsStar() {
if (isSelectAllEmailsEnabled) {
return EmailActionType.markAllAsStarred;
} else {
return listEmail.isAllEmailStarred
? EmailActionType.unMarkAsStarred
: EmailActionType.markAsStarred;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dash
import 'package:tmail_ui_user/features/search/mailbox/presentation/search_mailbox_bindings.dart';
import 'package:tmail_ui_user/features/thread/domain/model/search_query.dart';
import 'package:tmail_ui_user/features/thread/domain/state/delete_all_permanently_emails_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_all_as_starred_selection_all_emails_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/mark_all_as_unread_selection_all_emails_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/move_all_selection_all_emails_state.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
Expand Down Expand Up @@ -180,6 +181,10 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
_refreshMailboxChanges(mailboxState: success.currentMailboxState);
} else if (success is DeleteAllPermanentlyEmailsSuccess) {
_refreshMailboxChanges(mailboxState: success.currentMailboxState);
} else if (success is MarkAllAsStarredSelectionAllEmailsAllSuccess) {
_refreshMailboxChanges(mailboxState: success.currentMailboxState);
} else if (success is MarkAllAsStarredSelectionAllEmailsHasSomeEmailFailure) {
_refreshMailboxChanges(mailboxState: success.currentMailboxState);
}
}

Expand Down
8 changes: 8 additions & 0 deletions lib/features/thread/data/datasource/thread_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ abstract class ThreadDataSource {
int totalEmails,
StreamController<dartz.Either<Failure, Success>> onProgressController,
);

Future<List<EmailId>> markAllAsStarredForSelectionAllEmails(
Session session,
AccountId accountId,
MailboxId mailboxId,
int totalEmails,
StreamController<dartz.Either<Failure, Success>> onProgressController
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,15 @@ class LocalThreadDataSourceImpl extends ThreadDataSource {
) {
throw UnimplementedError();
}

@override
Future<List<EmailId>> markAllAsStarredForSelectionAllEmails(
Session session,
AccountId accountId,
MailboxId mailboxId,
int totalEmails,
StreamController<dartz.Either<Failure, Success>> onProgressController
) {
throw UnimplementedError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,23 @@ class ThreadDataSourceImpl extends ThreadDataSource {
);
}).catchError(_exceptionThrower.throwException);
}

@override
Future<List<EmailId>> markAllAsStarredForSelectionAllEmails(
Session session,
AccountId accountId,
MailboxId mailboxId,
int totalEmails,
StreamController<dartz.Either<Failure, Success>> onProgressController
) {
return Future.sync(() async {
return await _threadIsolateWorker.markAllAsStarredForSelectionAllEmails(
session,
accountId,
mailboxId,
totalEmails,
onProgressController,
);
}).catchError(_exceptionThrower.throwException);
}
}
Loading

0 comments on commit b05496c

Please sign in to comment.