TF-1360 Fix can not load new email until reload mail list
This commit is contained in:
+67
-30
@@ -165,6 +165,9 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
final StreamController<RefreshActionViewEvent> _refreshActionEventController =
|
final StreamController<RefreshActionViewEvent> _refreshActionEventController =
|
||||||
StreamController<RefreshActionViewEvent>.broadcast();
|
StreamController<RefreshActionViewEvent>.broadcast();
|
||||||
|
|
||||||
|
final _notificationManager = LocalNotificationManager.instance;
|
||||||
|
final _fcmController = FcmController.instance;
|
||||||
|
|
||||||
MailboxDashBoardController(
|
MailboxDashBoardController(
|
||||||
LogoutOidcInteractor logoutOidcInteractor,
|
LogoutOidcInteractor logoutOidcInteractor,
|
||||||
DeleteAuthorityOidcInteractor deleteAuthorityOidcInteractor,
|
DeleteAuthorityOidcInteractor deleteAuthorityOidcInteractor,
|
||||||
@@ -197,11 +200,6 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
_registerPendingFileInfo();
|
_registerPendingFileInfo();
|
||||||
_getSessionCurrent();
|
_getSessionCurrent();
|
||||||
_getAppVersion();
|
_getAppVersion();
|
||||||
if (!BuildUtils.isWeb) {
|
|
||||||
_handleOpenAppByNotification();
|
|
||||||
} else {
|
|
||||||
dispatchRoute(DashboardRoutes.thread);
|
|
||||||
}
|
|
||||||
super.onReady();
|
super.onReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,12 +270,13 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
clearState();
|
clearState();
|
||||||
} else if (failure is SaveEmailAsDraftsFailure
|
} else if (failure is SaveEmailAsDraftsFailure
|
||||||
|| failure is RemoveEmailDraftsFailure
|
|| failure is RemoveEmailDraftsFailure
|
||||||
|| failure is UpdateEmailDraftsFailure
|
|| failure is UpdateEmailDraftsFailure) {
|
||||||
|| failure is GetEmailByIdFailure) {
|
|
||||||
clearState();
|
clearState();
|
||||||
} else if (failure is MarkAsMailboxReadAllFailure ||
|
} else if (failure is MarkAsMailboxReadAllFailure ||
|
||||||
failure is MarkAsMailboxReadFailure) {
|
failure is MarkAsMailboxReadFailure) {
|
||||||
_markAsReadMailboxFailure(failure);
|
_markAsReadMailboxFailure(failure);
|
||||||
|
} else if (failure is GetEmailByIdFailure) {
|
||||||
|
_handleGetEmailDetailedFailed(failure);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(success) {
|
(success) {
|
||||||
@@ -368,15 +367,20 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
.debounceTime(const Duration(milliseconds: FcmService.durationMessageComing))
|
.debounceTime(const Duration(milliseconds: FcmService.durationMessageComing))
|
||||||
.listen(_handleRefreshActionWhenBackToApp);
|
.listen(_handleRefreshActionWhenBackToApp);
|
||||||
|
|
||||||
LocalNotificationManager.instance.localNotificationStream.listen(_handleLocalNotificationResponse);
|
_notificationManager.localNotificationStream.listen(_handleClickLocalNotificationOnForeground);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleOpenAppByNotification() async {
|
void _handleClickLocalNotificationOnTerminated() async {
|
||||||
log("_handleOpenAppByNotification(): isOpenAppByNotification: ${LocalNotificationManager.instance.isOpenAppByNotification}");
|
await _notificationManager.getNotificationDetails();
|
||||||
await LocalNotificationManager.instance.setUp();
|
final notificationResponse = _notificationManager.currentNotificationResponse;
|
||||||
if (LocalNotificationManager.instance.isOpenAppByNotification) {
|
log('MailboxDashBoardController::_handleClickLocalNotificationOnTerminated():payload: ${notificationResponse?.payload}');
|
||||||
final emailId = EmailId(Id(LocalNotificationManager.instance.getEmailIdFromNotification()!));
|
final emailIdFromPayload = notificationResponse?.payload;
|
||||||
_getPresentationEmailFromEmailId(emailId);
|
final currentAccountId = accountId.value;
|
||||||
|
if (emailIdFromPayload?.isNotEmpty == true && currentAccountId != null) {
|
||||||
|
_getPresentationEmailFromEmailIdAction(
|
||||||
|
EmailId(Id(emailIdFromPayload!)),
|
||||||
|
currentAccountId
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
dispatchRoute(DashboardRoutes.thread);
|
dispatchRoute(DashboardRoutes.thread);
|
||||||
}
|
}
|
||||||
@@ -387,6 +391,9 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _getSessionCurrent() {
|
void _getSessionCurrent() {
|
||||||
|
if (BuildUtils.isWeb) {
|
||||||
|
dispatchRoute(DashboardRoutes.thread);
|
||||||
|
}
|
||||||
final arguments = Get.arguments;
|
final arguments = Get.arguments;
|
||||||
log('MailboxDashBoardController::_getSessionCurrent(): arguments = $arguments');
|
log('MailboxDashBoardController::_getSessionCurrent(): arguments = $arguments');
|
||||||
if (arguments is Session) {
|
if (arguments is Session) {
|
||||||
@@ -398,6 +405,10 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
injectVacationBindings(sessionCurrent, accountId.value);
|
injectVacationBindings(sessionCurrent, accountId.value);
|
||||||
injectFCMBindings(sessionCurrent, accountId.value);
|
injectFCMBindings(sessionCurrent, accountId.value);
|
||||||
_getVacationResponse();
|
_getVacationResponse();
|
||||||
|
|
||||||
|
if (!BuildUtils.isWeb) {
|
||||||
|
_handleClickLocalNotificationOnTerminated();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
@@ -1371,36 +1382,62 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> haveLocalNotificationPress() async {
|
void _handleClickLocalNotificationOnForeground(NotificationResponse? response) {
|
||||||
return !(await LocalNotificationManager.instance.localNotificationStream.isEmpty);
|
log('MailboxDashBoardController::_handleClickLocalNotificationOnForeground():payload: ${response?.payload}');
|
||||||
}
|
final emailIdFromPayload = response?.payload;
|
||||||
|
final currentAccountId = accountId.value;
|
||||||
|
if (emailIdFromPayload?.isNotEmpty == true && currentAccountId != null) {
|
||||||
|
popAllRouteIfHave();
|
||||||
|
dispatchRoute(DashboardRoutes.waiting);
|
||||||
|
|
||||||
void _handleLocalNotificationResponse(NotificationResponse response) {
|
_getPresentationEmailFromEmailIdAction(
|
||||||
if(response.payload != null) {
|
EmailId(Id(emailIdFromPayload!)),
|
||||||
final emailId = EmailId(Id(response.payload!));
|
currentAccountId
|
||||||
_getPresentationEmailFromEmailId(emailId);
|
);
|
||||||
|
} else {
|
||||||
|
dispatchRoute(DashboardRoutes.thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _getPresentationEmailFromEmailId(EmailId emailId) {
|
void _getPresentationEmailFromEmailIdAction(EmailId emailId, AccountId accountId) {
|
||||||
if(accountId.value != null) {
|
log('MailboxDashBoardController:_getPresentationEmailFromEmailIdAction:emailId: $emailId');
|
||||||
log('MailboxDashBoardController: _getPresentationEmailFromEmailId: $emailId');
|
consumeState(_getEmailByIdInteractor.execute(
|
||||||
consumeState(_getEmailByIdInteractor.execute(accountId.value!, emailId, properties: ThreadConstants.propertiesDefault));
|
accountId,
|
||||||
}
|
emailId,
|
||||||
|
properties: ThreadConstants.propertiesDefault
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _moveToEmailDetailedView(GetEmailByIdSuccess success) {
|
void _moveToEmailDetailedView(GetEmailByIdSuccess success) {
|
||||||
log('MailboxDashBoardController::_moveToEmailDetailedView(): ${success.email}');
|
log('MailboxDashBoardController::_moveToEmailDetailedView(): ${success.email}');
|
||||||
setSelectedEmail(success.email);
|
setSelectedEmail(success.email);
|
||||||
dispatchRoute(DashboardRoutes.emailDetailed);
|
dispatchRoute(DashboardRoutes.emailDetailed);
|
||||||
// move to inbox so that user can back to inbox view
|
}
|
||||||
dispatchAction(ClearSearchEmailAction());
|
|
||||||
|
void _handleGetEmailDetailedFailed(GetEmailByIdFailure failure) {
|
||||||
|
logError('MailboxDashBoardController::_handleGetEmailDetailedFailed(): $failure');
|
||||||
|
dispatchRoute(DashboardRoutes.thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void popAllRouteIfHave() {
|
void popAllRouteIfHave() {
|
||||||
Get.until((route) => Get.currentRoute == AppRoutes.dashboard);
|
Get.until((route) => Get.currentRoute == AppRoutes.dashboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void handleOnFocusGained() {
|
||||||
|
log('MailboxDashBoardController::handleOnFocusGained():');
|
||||||
|
if (!BuildUtils.isWeb) {
|
||||||
|
_updateTheme();
|
||||||
|
}
|
||||||
|
refreshActionWhenBackToApp();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updateTheme() {
|
||||||
|
ThemeUtils.setSystemDarkUIStyle();
|
||||||
|
if (isDrawerOpen) {
|
||||||
|
ThemeUtils.setStatusBarTransparentColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
_emailReceiveManager.closeEmailReceiveManagerStream();
|
_emailReceiveManager.closeEmailReceiveManagerStream();
|
||||||
@@ -1409,8 +1446,8 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
_progressStateController.close();
|
_progressStateController.close();
|
||||||
_refreshActionEventController.close();
|
_refreshActionEventController.close();
|
||||||
Get.delete<DownloadController>();
|
Get.delete<DownloadController>();
|
||||||
FcmController.instance.dispose();
|
_notificationManager.dispose();
|
||||||
LocalNotificationManager.instance.dispose();
|
_fcmController.dispose();
|
||||||
super.onClose();
|
super.onClose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'package:core/presentation/extensions/color_extension.dart';
|
import 'package:core/presentation/extensions/color_extension.dart';
|
||||||
import 'package:core/presentation/utils/responsive_utils.dart';
|
import 'package:core/presentation/utils/responsive_utils.dart';
|
||||||
import 'package:core/presentation/utils/theme_utils.dart';
|
|
||||||
import 'package:core/presentation/views/responsive/responsive_widget.dart';
|
import 'package:core/presentation/views/responsive/responsive_widget.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -30,17 +29,7 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return FocusDetector(
|
return FocusDetector(
|
||||||
onFocusGained: () async {
|
onFocusGained: controller.handleOnFocusGained,
|
||||||
ThemeUtils.setSystemDarkUIStyle();
|
|
||||||
if (controller.isDrawerOpen) {
|
|
||||||
ThemeUtils.setStatusBarTransparentColor();
|
|
||||||
}
|
|
||||||
if(await controller.haveLocalNotificationPress()) {
|
|
||||||
controller.popAllRouteIfHave();
|
|
||||||
controller.dispatchRoute(DashboardRoutes.waiting);
|
|
||||||
}
|
|
||||||
controller.refreshActionWhenBackToApp();
|
|
||||||
},
|
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
drawerEnableOpenDragGesture: responsiveUtils.hasLeftMenuDrawerActive(context),
|
drawerEnableOpenDragGesture: responsiveUtils.hasLeftMenuDrawerActive(context),
|
||||||
body: Obx(() {
|
body: Obx(() {
|
||||||
|
|||||||
+11
-14
@@ -6,7 +6,7 @@ import 'package:core/presentation/extensions/html_extension.dart';
|
|||||||
import 'package:core/utils/app_logger.dart';
|
import 'package:core/utils/app_logger.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||||
import 'package:model/model.dart';
|
import 'package:model/extensions/email_address_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/presentation/notification/local_notification_config.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/notification/local_notification_config.dart';
|
||||||
|
|
||||||
class LocalNotificationManager {
|
class LocalNotificationManager {
|
||||||
@@ -28,7 +28,6 @@ class LocalNotificationManager {
|
|||||||
|
|
||||||
Future<void> setUp() async {
|
Future<void> setUp() async {
|
||||||
try {
|
try {
|
||||||
_notificationAppLaunchDetails = await _localNotificationsPlugin.getNotificationAppLaunchDetails();
|
|
||||||
await _initLocalNotification();
|
await _initLocalNotification();
|
||||||
_checkLocalNotificationPermission();
|
_checkLocalNotificationPermission();
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
@@ -41,19 +40,17 @@ class LocalNotificationManager {
|
|||||||
return Future.value();
|
return Future.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get isOpenAppByNotification => _notificationAppLaunchDetails?.didNotificationLaunchApp ?? false;
|
Future<void> getNotificationDetails() async {
|
||||||
|
try {
|
||||||
bool get isLocalNotificationStreamClosed => localNotificationsController.isClosed;
|
_notificationAppLaunchDetails = await _localNotificationsPlugin.getNotificationAppLaunchDetails();
|
||||||
|
} catch (e) {
|
||||||
String? getEmailIdFromNotification() {
|
logError('LocalNotificationManager::getNotificationDetails(): ERROR: ${e.toString()}');
|
||||||
if(_notificationAppLaunchDetails?.didNotificationLaunchApp ?? false) {
|
|
||||||
log('LocalNotificationManager::handleNotificationAppLaunch(): ${_notificationAppLaunchDetails!.notificationResponse}');
|
|
||||||
final selectedNotificationPayload = _notificationAppLaunchDetails!.notificationResponse?.payload;
|
|
||||||
return selectedNotificationPayload;
|
|
||||||
}
|
}
|
||||||
return null;
|
return Future.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationResponse? get currentNotificationResponse => _notificationAppLaunchDetails?.notificationResponse;
|
||||||
|
|
||||||
Future<bool?> _initLocalNotification() async {
|
Future<bool?> _initLocalNotification() async {
|
||||||
return await _localNotificationsPlugin.initialize(
|
return await _localNotificationsPlugin.initialize(
|
||||||
const InitializationSettings(
|
const InitializationSettings(
|
||||||
@@ -65,8 +62,8 @@ class LocalNotificationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleReceiveNotificationResponse(NotificationResponse response) {
|
void _handleReceiveNotificationResponse(NotificationResponse response) {
|
||||||
log('LocalNotificationManager::handleReceiveNotificationResponse(): ${response.payload}');
|
log('LocalNotificationManager::handleReceiveNotificationResponse():payload: ${response.payload}');
|
||||||
if(response.notificationResponseType == NotificationResponseType.selectedNotification) {
|
if (response.notificationResponseType == NotificationResponseType.selectedNotification) {
|
||||||
localNotificationsController.add(response);
|
localNotificationsController.add(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user