TF-145 Add presentation layer for getAllEmail in Caching
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:core/core.dart';
|
|||||||
import 'package:core/presentation/utils/responsive_utils.dart';
|
import 'package:core/presentation/utils/responsive_utils.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:tmail_ui_user/features/caching/state_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource/email_datasource.dart';
|
import 'package:tmail_ui_user/features/email/data/datasource/email_datasource.dart';
|
||||||
import 'package:tmail_ui_user/features/email/data/datasource_impl/email_datasource_impl.dart';
|
import 'package:tmail_ui_user/features/email/data/datasource_impl/email_datasource_impl.dart';
|
||||||
import 'package:tmail_ui_user/features/email/data/network/email_api.dart';
|
import 'package:tmail_ui_user/features/email/data/network/email_api.dart';
|
||||||
@@ -10,8 +11,12 @@ import 'package:tmail_ui_user/features/email/domain/repository/email_repository.
|
|||||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart';
|
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_email_read_interactor.dart';
|
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_email_read_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/email/domain/usecases/move_to_mailbox_interactor.dart';
|
import 'package:tmail_ui_user/features/email/domain/usecases/move_to_mailbox_interactor.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/state_datasource_impl.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/data/datasource/thread_datasource.dart';
|
import 'package:tmail_ui_user/features/thread/data/datasource/thread_datasource.dart';
|
||||||
|
import 'package:tmail_ui_user/features/thread/data/datasource_impl/local_thread_datasource_impl.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/data/datasource_impl/thread_datasource_impl.dart';
|
import 'package:tmail_ui_user/features/thread/data/datasource_impl/thread_datasource_impl.dart';
|
||||||
|
import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/data/network/thread_api.dart';
|
import 'package:tmail_ui_user/features/thread/data/network/thread_api.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/data/repository/thread_repository_impl.dart';
|
import 'package:tmail_ui_user/features/thread/data/repository/thread_repository_impl.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/domain/repository/thread_repository.dart';
|
import 'package:tmail_ui_user/features/thread/domain/repository/thread_repository.dart';
|
||||||
@@ -26,7 +31,16 @@ class ThreadBindings extends Bindings {
|
|||||||
void dependencies() {
|
void dependencies() {
|
||||||
Get.lazyPut(() => ThreadDataSourceImpl(Get.find<ThreadAPI>()));
|
Get.lazyPut(() => ThreadDataSourceImpl(Get.find<ThreadAPI>()));
|
||||||
Get.lazyPut<ThreadDataSource>(() => Get.find<ThreadDataSourceImpl>());
|
Get.lazyPut<ThreadDataSource>(() => Get.find<ThreadDataSourceImpl>());
|
||||||
Get.lazyPut(() => ThreadRepositoryImpl(Get.find<ThreadDataSource>()));
|
Get.lazyPut(() => LocalThreadDataSourceImpl(Get.find<EmailCacheManager>()));
|
||||||
|
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
|
||||||
|
Get.lazyPut<StateDataSource>(() => Get.find<StateDataSourceImpl>());
|
||||||
|
Get.lazyPut(() => ThreadRepositoryImpl(
|
||||||
|
{
|
||||||
|
DataSourceType.network: Get.find<ThreadDataSource>(),
|
||||||
|
DataSourceType.local: Get.find<LocalThreadDataSourceImpl>()
|
||||||
|
},
|
||||||
|
Get.find<StateDataSource>()
|
||||||
|
));
|
||||||
Get.lazyPut<ThreadRepository>(() => Get.find<ThreadRepositoryImpl>());
|
Get.lazyPut<ThreadRepository>(() => Get.find<ThreadRepositoryImpl>());
|
||||||
Get.lazyPut(() => GetEmailsInMailboxInteractor(Get.find<ThreadRepository>()));
|
Get.lazyPut(() => GetEmailsInMailboxInteractor(Get.find<ThreadRepository>()));
|
||||||
Get.lazyPut(() => ScrollController());
|
Get.lazyPut(() => ScrollController());
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import 'package:dartz/dartz.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/filter/filter.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
|
||||||
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
|
import 'package:jmap_dart_client/jmap/core/sort/comparator.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||||
@@ -36,6 +34,7 @@ import 'package:tmail_ui_user/features/thread/presentation/model/load_more_state
|
|||||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||||
|
|
||||||
class ThreadController extends BaseController {
|
class ThreadController extends BaseController {
|
||||||
|
|
||||||
@@ -49,18 +48,21 @@ class ThreadController extends BaseController {
|
|||||||
final MarkAsStarEmailInteractor _markAsStarEmailInteractor;
|
final MarkAsStarEmailInteractor _markAsStarEmailInteractor;
|
||||||
final MarkAsStarMultipleEmailInteractor _markAsStarMultipleEmailInteractor;
|
final MarkAsStarMultipleEmailInteractor _markAsStarMultipleEmailInteractor;
|
||||||
|
|
||||||
final _properties = Properties({
|
|
||||||
'id', 'subject', 'from', 'to', 'cc', 'bcc', 'keywords', 'receivedAt',
|
|
||||||
'sentAt', 'preview', 'hasAttachment', 'replyTo'
|
|
||||||
});
|
|
||||||
|
|
||||||
final emailList = <PresentationEmail>[].obs;
|
final emailList = <PresentationEmail>[].obs;
|
||||||
final loadMoreState = LoadMoreState.IDLE.obs;
|
final loadMoreState = LoadMoreState.IDLE.obs;
|
||||||
final currentSelectMode = SelectMode.INACTIVE.obs;
|
final currentSelectMode = SelectMode.INACTIVE.obs;
|
||||||
|
|
||||||
int positionCurrent = 0;
|
int _currentPosition = 0;
|
||||||
int lastGetTotal = 0;
|
int _totalNumberOfEmails = 0;
|
||||||
MailboxId? _currentMailboxId;
|
MailboxId? _currentMailboxId;
|
||||||
|
jmap.State? _currentEmailState;
|
||||||
|
|
||||||
|
EmailFilterCondition? get _filterCondition => EmailFilterCondition(
|
||||||
|
inMailbox: mailboxDashBoardController.selectedMailbox.value?.id);
|
||||||
|
|
||||||
|
Set<Comparator>? get _sortOrder => Set()
|
||||||
|
..add(EmailComparator(EmailComparatorProperty.sentAt)
|
||||||
|
..setIsAscending(false));
|
||||||
|
|
||||||
ThreadController(
|
ThreadController(
|
||||||
this.responsiveUtils,
|
this.responsiveUtils,
|
||||||
@@ -85,8 +87,8 @@ class ThreadController extends BaseController {
|
|||||||
mailboxDashBoardController.selectedMailbox.listen((selectedMailbox) {
|
mailboxDashBoardController.selectedMailbox.listen((selectedMailbox) {
|
||||||
if (_currentMailboxId != selectedMailbox?.id) {
|
if (_currentMailboxId != selectedMailbox?.id) {
|
||||||
_currentMailboxId = selectedMailbox?.id;
|
_currentMailboxId = selectedMailbox?.id;
|
||||||
emailList.value = <PresentationEmail>[];
|
_resetToOriginalValue();
|
||||||
refreshGetAllEmailAction();
|
_getAllEmail();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -116,6 +118,16 @@ class ThreadController extends BaseController {
|
|||||||
super.onClose();
|
super.onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onData(Either<Failure, Success> newState) {
|
||||||
|
super.onData(newState);
|
||||||
|
newState.map((success) {
|
||||||
|
if (success is GetAllEmailSuccess) {
|
||||||
|
_getAllEmailSuccess(success);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onDone() {
|
void onDone() {
|
||||||
viewState.value.fold(
|
viewState.value.fold(
|
||||||
@@ -131,9 +143,7 @@ class ThreadController extends BaseController {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(success) {
|
(success) {
|
||||||
if (success is GetAllEmailSuccess) {
|
if (success is MarkAsMultipleEmailReadAllSuccess
|
||||||
_getAllEmailSuccess(success);
|
|
||||||
} else if (success is MarkAsMultipleEmailReadAllSuccess
|
|
||||||
|| success is MarkAsMultipleEmailReadHasSomeEmailFailure) {
|
|| success is MarkAsMultipleEmailReadHasSomeEmailFailure) {
|
||||||
_markAsSelectedEmailReadSuccess(success);
|
_markAsSelectedEmailReadSuccess(success);
|
||||||
} else if (success is MoveMultipleEmailToMailboxAllSuccess
|
} else if (success is MoveMultipleEmailToMailboxAllSuccess
|
||||||
@@ -150,90 +160,78 @@ class ThreadController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onError(error) {
|
void onError(error) {}
|
||||||
|
|
||||||
|
void _getAllEmail() {
|
||||||
|
final accountId = mailboxDashBoardController.accountId.value;
|
||||||
|
|
||||||
|
if (accountId != null) {
|
||||||
|
_getAllEmailAction(accountId, inMailboxId: _currentMailboxId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _resetToOriginalValue() {
|
||||||
|
dispatchState(Right(LoadingState()));
|
||||||
|
emailList.value = <PresentationEmail>[];
|
||||||
|
loadMoreState.value = LoadMoreState.IDLE;
|
||||||
|
_currentPosition = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getAllEmailSuccess(Success success) {
|
void _getAllEmailSuccess(Success success) {
|
||||||
if (success is GetAllEmailSuccess) {
|
if (success is GetAllEmailSuccess) {
|
||||||
|
_currentEmailState = success.currentEmailState;
|
||||||
|
|
||||||
if (loadMoreState.value == LoadMoreState.LOADING) {
|
if (loadMoreState.value == LoadMoreState.LOADING) {
|
||||||
emailList.addAll(success.emailList);
|
emailList.addAll(success.emailList);
|
||||||
} else {
|
} else {
|
||||||
emailList.value = success.emailList;
|
emailList.value = success.emailList;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastGetTotal = emailList.length;
|
_totalNumberOfEmails = emailList.length;
|
||||||
loadMoreState.value = success.emailList.isEmpty ? LoadMoreState.COMPLETED : LoadMoreState.IDLE;
|
loadMoreState.value = success.emailList.isEmpty ? LoadMoreState.COMPLETED : LoadMoreState.IDLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EmailFilterCondition? _getFilterConditionCurrent() {
|
|
||||||
return EmailFilterCondition(inMailbox: mailboxDashBoardController.selectedMailbox.value?.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Comparator>? _getSortCurrent() {
|
|
||||||
return Set()
|
|
||||||
..add(EmailComparator(EmailComparatorProperty.sentAt)
|
|
||||||
..setIsAscending(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
void _resetPositionCurrentAndLoadMoreState() {
|
void _resetPositionCurrentAndLoadMoreState() {
|
||||||
if (loadMoreState.value == LoadMoreState.LOADING) {
|
if (loadMoreState.value == LoadMoreState.LOADING) {
|
||||||
positionCurrent -= lastGetTotal;
|
_currentPosition -= _totalNumberOfEmails;
|
||||||
}
|
}
|
||||||
loadMoreState.value = LoadMoreState.IDLE;
|
loadMoreState.value = LoadMoreState.IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getAllEmailAction(AccountId accountId,
|
void _getAllEmailAction(AccountId accountId, {MailboxId? inMailboxId}) {
|
||||||
{
|
|
||||||
UnsignedInt? limit,
|
|
||||||
int position = 0,
|
|
||||||
Set<Comparator>? sort,
|
|
||||||
Filter? filter,
|
|
||||||
Properties? properties,
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
consumeState(_getEmailsInMailboxInteractor.execute(
|
consumeState(_getEmailsInMailboxInteractor.execute(
|
||||||
accountId,
|
accountId,
|
||||||
limit: limit,
|
limit: ThreadConstants.defaultLimit,
|
||||||
position: position,
|
position: _currentPosition,
|
||||||
sort: sort,
|
sort: _sortOrder,
|
||||||
filter: filter,
|
filter: _filterCondition,
|
||||||
properties: properties
|
propertiesCreated: ThreadConstants.propertiesDefault,
|
||||||
|
propertiesUpdated: ThreadConstants.propertiesUpdatedDefault,
|
||||||
|
inMailboxId: inMailboxId ?? _currentMailboxId
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshGetAllEmailAction() {
|
void refreshGetAllEmailAction() {
|
||||||
loadMoreState.value = LoadMoreState.IDLE;
|
loadMoreState.value = LoadMoreState.IDLE;
|
||||||
positionCurrent = 0;
|
_currentPosition = 0;
|
||||||
dispatchState(Right(LoadingState()));
|
dispatchState(Right(LoadingState()));
|
||||||
|
|
||||||
final accountId = mailboxDashBoardController.accountId.value;
|
final accountId = mailboxDashBoardController.accountId.value;
|
||||||
|
|
||||||
if (accountId != null) {
|
if (accountId != null) {
|
||||||
_getAllEmailAction(
|
_getAllEmailAction(accountId);
|
||||||
accountId,
|
|
||||||
limit: ThreadConstants.defaultLimit,
|
|
||||||
position: positionCurrent,
|
|
||||||
sort: _getSortCurrent(),
|
|
||||||
properties: _properties,
|
|
||||||
filter: _getFilterConditionCurrent());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadMoreEmailAction() {
|
void loadMoreEmailAction() {
|
||||||
loadMoreState.value = LoadMoreState.LOADING;
|
loadMoreState.value = LoadMoreState.LOADING;
|
||||||
positionCurrent += lastGetTotal;
|
_currentPosition += _totalNumberOfEmails;
|
||||||
|
|
||||||
final accountId = mailboxDashBoardController.accountId.value;
|
final accountId = mailboxDashBoardController.accountId.value;
|
||||||
|
|
||||||
if (accountId != null) {
|
if (accountId != null) {
|
||||||
_getAllEmailAction(
|
_getAllEmailAction(accountId);
|
||||||
accountId,
|
|
||||||
limit: ThreadConstants.defaultLimit,
|
|
||||||
position: positionCurrent,
|
|
||||||
sort: _getSortCurrent(),
|
|
||||||
properties: _properties,
|
|
||||||
filter: _getFilterConditionCurrent());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,13 +281,16 @@ class ThreadController extends BaseController {
|
|||||||
final accountId = mailboxDashBoardController.accountId.value;
|
final accountId = mailboxDashBoardController.accountId.value;
|
||||||
|
|
||||||
if (accountId != null) {
|
if (accountId != null) {
|
||||||
_getAllEmailAction(
|
consumeState(_getEmailsInMailboxInteractor.execute(
|
||||||
accountId,
|
accountId,
|
||||||
limit: newLimit,
|
limit: newLimit,
|
||||||
position: 0,
|
position: 0,
|
||||||
sort: _getSortCurrent(),
|
sort: _sortOrder,
|
||||||
properties: _properties,
|
filter: _filterCondition,
|
||||||
filter: _getFilterConditionCurrent());
|
propertiesCreated: ThreadConstants.propertiesDefault,
|
||||||
|
propertiesUpdated: ThreadConstants.propertiesUpdatedDefault,
|
||||||
|
inMailboxId: _currentMailboxId
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user