mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-06 16:04:20 +00:00
TF-4268 Add a log to monitor push notifications on Android.
This commit is contained in:
1 parent
a7349c3693
commit
fb796e47a5
13 files changed
+184
-25
No files matched your search
@@ -374,8 +374,12 @@ abstract class BaseController extends GetxController
|
||||
} else {
|
||||
throw NotSupportFCMException();
|
||||
}
|
||||
} catch(e) {
|
||||
logWarning('$runtimeType::injectFCMBindings(): exception: $e');
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'$runtimeType::injectFCMBindings():',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
@@ -19,7 +20,12 @@ class GetStoredEmailStateInteractor {
|
||||
} else {
|
||||
yield Left<Failure, Success>(NotFoundEmailState());
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'Get stored email state is failed',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
yield Left<Failure, Success>(GetStoredEmailStateFailure(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@ extension ListMailboxIdExtension on List<MailboxId> {
|
||||
};
|
||||
return maps;
|
||||
}
|
||||
|
||||
List<String> toListString() {
|
||||
return map((mailboxId) => mailboxId.id.value).toList();
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -862,8 +862,12 @@ class MailboxDashBoardController extends ReloadableController
|
||||
await super.injectFCMBindings(session, accountId);
|
||||
await LocalNotificationManager.instance.recreateStreamController();
|
||||
_registerLocalNotificationStreamListener();
|
||||
} catch (e) {
|
||||
logWarning('MailboxDashBoardController::injectFCMBindings(): $e');
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'MailboxDashBoardController::injectFCMBindings():',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -1,5 +1,6 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/delete_firebase_registration_cache_state.dart';
|
||||
@@ -14,7 +15,12 @@ class DeleteFirebaseRegistrationCacheInteractor {
|
||||
yield Right<Failure, Success>(DeleteFirebaseRegistrationCacheLoading());
|
||||
await _fcmRepository.deleteFirebaseRegistrationCache();
|
||||
yield Right<Failure, Success>(DeleteFirebaseRegistrationCacheSuccess());
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'Delete firebase registration cache is failed',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
yield Left<Failure, Success>(DeleteFirebaseRegistrationCacheFailure(e));
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -1,6 +1,7 @@
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
@@ -17,7 +18,12 @@ class RegisterNewFirebaseRegistrationTokenInteractor {
|
||||
yield Right<Failure, Success>(RegisterNewFirebaseRegistrationTokenLoading());
|
||||
final firebaseRegistration = await _fcmRepository.registerNewFirebaseRegistrationToken(newTokenRequest);
|
||||
yield Right<Failure, Success>(RegisterNewFirebaseRegistrationTokenSuccess(firebaseRegistration));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'Register new firebase registration token failed',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
yield Left<Failure, Success>(RegisterNewFirebaseRegistrationTokenFailure(e));
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -1,6 +1,7 @@
|
||||
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/model/update_token_expired_time_request.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
|
||||
@@ -17,7 +18,12 @@ class UpdateFirebaseRegistrationTokenInteractor {
|
||||
yield Right<Failure, Success>(UpdateFirebaseRegistrationTokenLoading());
|
||||
await _fcmRepository.updateFirebaseRegistrationToken(updateTokenExpiredTimeRequest);
|
||||
yield Right<Failure, Success>(UpdateFirebaseRegistrationTokenSuccess());
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'Update expired time for firebase registration token is failed',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
yield Left<Failure, Success>(UpdateFirebaseRegistrationTokenFailure(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,12 @@ class FcmConfiguration {
|
||||
static Future<void> initialize() async {
|
||||
try {
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
} catch (e) {
|
||||
logWarning('FcmConfiguration::initialize: Exception = $e');
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'FcmConfiguration::initialize',
|
||||
exception: e,
|
||||
stackTrace: st
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,14 +58,32 @@ class FcmMessageController extends PushBaseController {
|
||||
.debounceTime(const Duration(
|
||||
milliseconds: FcmUtils.durationBackgroundMessageComing,
|
||||
))
|
||||
.listen(_handleBackgroundMessageAction);
|
||||
.listen(
|
||||
_handleBackgroundMessageAction,
|
||||
onError: (e, st) {
|
||||
logError(
|
||||
'FcmMessageController::_listenBackgroundMessageStream',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _listenTokenStream() {
|
||||
FcmService.instance.fcmTokenStreamController
|
||||
?.stream
|
||||
.debounceTime(const Duration(milliseconds: FcmUtils.durationRefreshToken))
|
||||
.listen(FcmTokenController.instance.onFcmTokenChanged);
|
||||
.listen(
|
||||
FcmTokenController.instance.onFcmTokenChanged,
|
||||
onError: (e, st) {
|
||||
logError(
|
||||
'FcmMessageController::_listenTokenStream',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _handleBackgroundMessageAction(Map<String, dynamic> payloadData) async {
|
||||
@@ -102,6 +120,10 @@ class FcmMessageController extends PushBaseController {
|
||||
void _getAuthenticatedAccount({StateChange? stateChange}) {
|
||||
if (_getAuthenticatedAccountInteractor != null) {
|
||||
consumeState(_getAuthenticatedAccountInteractor!.execute(stateChange: stateChange));
|
||||
} else {
|
||||
logError(
|
||||
'GetAuthenticatedAccountInteractor is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,9 +197,17 @@ class FcmMessageController extends PushBaseController {
|
||||
userName: success.session.username,
|
||||
stateChange: stateChange,
|
||||
session: success.session);
|
||||
} else {
|
||||
logError(
|
||||
'FcmMessageController::_handleGetSessionSuccess: Api url or state change is null',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
logWarning('FcmMessageController::_handleGetSessionSuccess: Exception $e');
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'FcmMessageController::_handleGetSessionSuccess:',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +232,17 @@ class FcmMessageController extends PushBaseController {
|
||||
@override
|
||||
void handleFailureViewState(Failure failure) {
|
||||
log('FcmMessageController::_handleFailureViewState(): $failure');
|
||||
if (failure is GetStoredTokenOidcFailure) {
|
||||
logError(
|
||||
'Get stored token oidc is failed',
|
||||
exception: failure.exception,
|
||||
);
|
||||
} else if (failure is GetSessionFailure) {
|
||||
logError(
|
||||
'Get session is failed',
|
||||
exception: failure.exception,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -83,12 +83,20 @@ class FcmTokenController extends PushBaseController {
|
||||
void _getStoredFirebaseRegistrationFromCache() {
|
||||
if (_getStoredFirebaseRegistrationInteractor != null) {
|
||||
consumeState(_getStoredFirebaseRegistrationInteractor!.execute());
|
||||
} else {
|
||||
logError(
|
||||
'GetStoredFirebaseRegistrationInteractor is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _storeFirebaseRegistrationToCache(FirebaseRegistration firebaseRegistration){
|
||||
if (_storeFirebaseRegistrationInteractor != null) {
|
||||
consumeState(_storeFirebaseRegistrationInteractor!.execute(firebaseRegistration));
|
||||
} else {
|
||||
logError(
|
||||
'StoreFirebaseRegistrationInteractor is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +131,10 @@ class FcmTokenController extends PushBaseController {
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
logError(
|
||||
'UpdateFirebaseRegistrationTokenInteractor is null or firebaseRegistration.id is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,12 +155,20 @@ class FcmTokenController extends PushBaseController {
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
logError(
|
||||
'RegisterNewFirebaseRegistrationTokenInteractor is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _deleteFirebaseRegistrationInCache() {
|
||||
if (_deleteFirebaseRegistrationCacheInteractor != null) {
|
||||
consumeState(_deleteFirebaseRegistrationCacheInteractor!.execute());
|
||||
} else {
|
||||
logError(
|
||||
'DeleteFirebaseRegistrationCacheInteractor is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import 'package:tmail_ui_user/features/email/domain/usecases/get_stored_email_st
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/store_list_new_email_interator.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/action/email_ui_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/extensions/list_mailbox_id_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/exceptions/fcm_exception.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_changes_to_push_notification_state.dart';
|
||||
@@ -138,12 +139,20 @@ class EmailChangeListener extends ChangeListener {
|
||||
void _getStoredEmailDeliveryState(AccountId accountId, UserName userName) {
|
||||
if (_getStoredEmailDeliveryStateInteractor != null) {
|
||||
consumeState(_getStoredEmailDeliveryStateInteractor!.execute(accountId, userName));
|
||||
} else {
|
||||
logError(
|
||||
'GetStoredEmailDeliveryStateInteractor is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _getStoredEmailState() {
|
||||
if (_getStoredEmailStateInteractor != null && _session != null && _accountId != null) {
|
||||
consumeState(_getStoredEmailStateInteractor!.execute(_session!, _accountId!));
|
||||
} else {
|
||||
logError(
|
||||
'GetStoredEmailStateInteractor is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,12 +171,20 @@ class EmailChangeListener extends ChangeListener {
|
||||
_accountId!,
|
||||
),
|
||||
));
|
||||
} else {
|
||||
logError(
|
||||
'GetEmailChangesToPushNotificationInteractor is null, or accountId is null, or session is null, or userName is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _storeEmailDeliveryStateAction(AccountId accountId, UserName userName, jmap.State state) {
|
||||
if (_storeEmailDeliveryStateInteractor != null) {
|
||||
consumeState(_storeEmailDeliveryStateInteractor!.execute(accountId, userName, state));
|
||||
} else {
|
||||
logError(
|
||||
'StoreEmailDeliveryStateInteractor is null',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,6 +212,11 @@ class EmailChangeListener extends ChangeListener {
|
||||
_getStoredEmailState();
|
||||
} else if (failure is GetMailboxesNotPutNotificationsFailure) {
|
||||
final listEmails = _emailsAvailablePushNotification.toEmailsAvailablePushNotification();
|
||||
if (listEmails.isEmpty) {
|
||||
logError(
|
||||
'List email available to push notification is empty'
|
||||
);
|
||||
}
|
||||
_handleLocalPushNotification(
|
||||
userName: failure.userName,
|
||||
emailList: listEmails
|
||||
@@ -217,10 +239,20 @@ class EmailChangeListener extends ChangeListener {
|
||||
userName: success.userName,
|
||||
emailList: success.emailList
|
||||
);
|
||||
if (success.emailList.isEmpty) {
|
||||
logError(
|
||||
'Get new emails with new state ${_newStateEmailDelivery?.value} to push notification is empty'
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (success is GetMailboxesNotPutNotificationsSuccess) {
|
||||
final listEmails = _emailsAvailablePushNotification.toEmailsAvailablePushNotification(
|
||||
mailboxIdsNotPutNotifications: success.mailboxes.mailboxIds);
|
||||
if (listEmails.isEmpty) {
|
||||
logError(
|
||||
'List email available to push notification is empty, with mailbox id not put notifications: ${success.mailboxes.mailboxIds.toListString()}'
|
||||
);
|
||||
}
|
||||
_handleLocalPushNotification(
|
||||
userName: success.userName,
|
||||
emailList: listEmails
|
||||
@@ -249,6 +281,11 @@ class EmailChangeListener extends ChangeListener {
|
||||
consumeState(_getMailboxesNotPutNotificationsInteractor!.execute(_session!, _accountId!));
|
||||
} else {
|
||||
final listEmails = _emailsAvailablePushNotification.toEmailsAvailablePushNotification();
|
||||
if (listEmails.isEmpty) {
|
||||
logError(
|
||||
'List email available to push notification is empty'
|
||||
);
|
||||
}
|
||||
_handleLocalPushNotification(
|
||||
userName: userName,
|
||||
emailList: listEmails
|
||||
|
||||
+12
-4
@@ -39,8 +39,12 @@ class LocalNotificationManager {
|
||||
await _createAndroidNotificationChannelGroup(groupId);
|
||||
await _createAndroidNotificationChannel(groupId);
|
||||
}
|
||||
} catch (e) {
|
||||
logWarning('LocalNotificationManager::setUp(): ERROR: ${e.toString()}');
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'LocalNotificationManager::setUp:ERROR',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +52,12 @@ class LocalNotificationManager {
|
||||
try {
|
||||
_notificationAppLaunchDetails = await _localNotificationsPlugin.getNotificationAppLaunchDetails();
|
||||
return _notificationAppLaunchDetails?.notificationResponse;
|
||||
} catch (e) {
|
||||
logWarning('LocalNotificationManager::getCurrentNotificationResponse(): ERROR: ${e.toString()}');
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'Get notification app launch details failed from local notification plugin',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,12 @@ class FcmReceiver {
|
||||
final token = await FirebaseMessaging.instance.getToken();
|
||||
log('FcmReceiver::_getInitialToken:token: $token');
|
||||
return token;
|
||||
} catch (e) {
|
||||
logWarning('FcmReceiver::_getInitialToken: TYPE = ${e.runtimeType} | Exception = $e');
|
||||
} catch (e, st) {
|
||||
logError(
|
||||
'FcmReceiver::_getInitialToken:',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -44,11 +48,20 @@ class FcmReceiver {
|
||||
final token = await _getInitialToken();
|
||||
FcmService.instance.handleToken(token);
|
||||
|
||||
FirebaseMessaging.instance.onTokenRefresh.listen((newToken) {
|
||||
log('FcmReceiver::_onHandleFcmToken:onTokenRefresh: $newToken');
|
||||
if (newToken != token) {
|
||||
FcmService.instance.handleToken(newToken);
|
||||
FirebaseMessaging.instance.onTokenRefresh.listen(
|
||||
(newToken) {
|
||||
log('FcmReceiver::_onHandleFcmToken:onTokenRefresh: $newToken');
|
||||
if (newToken != token) {
|
||||
FcmService.instance.handleToken(newToken);
|
||||
}
|
||||
},
|
||||
onError: (e, st) {
|
||||
logError(
|
||||
'FcmReceiver::_onHandleFcmToken:onTokenRefresh:',
|
||||
exception: e,
|
||||
stackTrace: st,
|
||||
);
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user