TF-1900 Auto sync Sending Queue after work manager completed
(cherry picked from commit e68a8fdc49c600224b93e25f60ed6b8ecf1afe84)
This commit is contained in:
@@ -11,7 +11,7 @@ class SendingQueueRepositoryImpl extends SendingQueueRepository {
|
||||
SendingQueueRepositoryImpl(this._emailHiveCacheDataSourceImpl);
|
||||
|
||||
@override
|
||||
Future<List<SendingEmail>> getAllSendingEmails(AccountId accountId, UserName userName) {
|
||||
return _emailHiveCacheDataSourceImpl.getAllSendingEmails(accountId, userName);
|
||||
Future<List<SendingEmail>> getAllSendingEmails(AccountId accountId, UserName userName, {bool needToReopen = false}) {
|
||||
return _emailHiveCacheDataSourceImpl.getAllSendingEmails(accountId, userName, needToReopen: needToReopen);
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,5 @@ import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/model/sending_email.dart';
|
||||
|
||||
abstract class SendingQueueRepository {
|
||||
Future<List<SendingEmail>> getAllSendingEmails(AccountId accountId, UserName userName);
|
||||
Future<List<SendingEmail>> getAllSendingEmails(AccountId accountId, UserName userName, {bool needToReopen = false});
|
||||
}
|
||||
@@ -11,10 +11,10 @@ class GetAllSendingEmailInteractor {
|
||||
|
||||
GetAllSendingEmailInteractor(this._sendingQueueRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName, {bool needToReopen = false}) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetAllSendingEmailLoading());
|
||||
final sendingEmails = await _sendingQueueRepository.getAllSendingEmails(accountId, userName);
|
||||
final sendingEmails = await _sendingQueueRepository.getAllSendingEmails(accountId, userName, needToReopen: needToReopen);
|
||||
yield Right<Failure, Success>(GetAllSendingEmailSuccess(sendingEmails));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(GetAllSendingEmailFailure(e));
|
||||
|
||||
@@ -1,22 +1,54 @@
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/offline_mode/scheduler/worker_state.dart';
|
||||
import 'package:tmail_ui_user/features/sending_queue/presentation/utils/sending_queue_isolate_manager.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
class SendingQueueController extends BaseController {
|
||||
|
||||
final dashboardController = getBinding<MailboxDashBoardController>();
|
||||
final sendingQueueIsolateManager = getBinding<SendingQueueIsolateManager>();
|
||||
|
||||
final listSendingEmailController = ScrollController();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
sendingQueueIsolateManager?.initial(
|
||||
onData: _handleSendingQueueEvent,
|
||||
onError: (error, stackTrace) {
|
||||
logError('SendingQueueController::onInit():onError:error: $error | stackTrace: $stackTrace');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void _handleSendingQueueEvent(Object? event) {
|
||||
log('SendingQueueController::_handleSendingQueueEvent():event: $event');
|
||||
if (event is String) {
|
||||
final workState = WorkerState.values.firstWhereOrNull((state) => state.name == event);
|
||||
log('SendingQueueController::_handleSendingQueueEvent():workState: $workState');
|
||||
if (workState != null) {
|
||||
_refreshSendingQueue(needToReopen: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _refreshSendingQueue({bool needToReopen = false}) {
|
||||
dashboardController?.getAllSendingEmails(needToReopen: needToReopen);
|
||||
}
|
||||
|
||||
void openMailboxMenu() {
|
||||
dashboardController!.openMailboxMenuDrawer();
|
||||
dashboardController?.openMailboxMenuDrawer();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
listSendingEmailController.dispose();
|
||||
sendingQueueIsolateManager?.release();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user