Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import flutter_local_notifications
GeneratedPluginRegistrant.register(with: self)

createNotificationInteractionChannel()
clearApplicationNotification()

if let payload = launchOptions?[.remoteNotification] as? [AnyHashable : Any],
let emailId = payload[JmapConstants.EMAIL_ID] as? String,
Expand Down Expand Up @@ -68,7 +69,7 @@ import flutter_local_notifications
}

override func applicationDidBecomeActive(_ application: UIApplication) {
removeAppBadger()
clearApplicationNotification()
}

private func handleEmailAndress(open url: URL) -> URL? {
Expand Down Expand Up @@ -126,6 +127,13 @@ import flutter_local_notifications
}
return false
}

private func clearApplicationNotification() {
removeAppBadger()
let userNotificationCenter = UNUserNotificationCenter.current()
userNotificationCenter.removeAllDeliveredNotifications()
userNotificationCenter.removeAllPendingNotificationRequests()
}
}

extension AppDelegate {
Expand Down
2 changes: 1 addition & 1 deletion ios/TwakeMailNSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class NotificationService: UNNotificationServiceExtension {
return self.notify()
}

guard let oldEmailDeliveryState = keychainSharingSession.emailDeliveryState ?? keychainSharingSession.emailState,
guard let oldEmailDeliveryState = keychainSharingSession.emailDeliveryState,
newEmailDeliveryState != oldEmailDeliveryState else {
self.showDefaultNotification(message: NSLocalizedString(self.newEmailDefaultMessageKey, comment: "Localizable"))
return self.notify()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_
import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_mailbox_state_to_refresh_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_email_state_to_refresh_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_mailbox_state_to_refresh_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_message_controller.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/controller/web_socket_controller.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/notification/local_notification_manager.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/services/fcm_service.dart';
Expand Down Expand Up @@ -2971,6 +2972,7 @@ class MailboxDashBoardController extends ReloadableController
mapMailboxById = {};
mapDefaultMailboxIdByRole = {};
WebSocketController.instance.onClose();
FcmMessageController.instance.onClose();
_currentEmailState = null;
super.onClose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/platform_info.dart';
import 'package:flutter/material.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
Expand All @@ -32,6 +33,7 @@ import 'package:tmail_ui_user/features/push_notification/presentation/controller
import 'package:tmail_ui_user/features/push_notification/presentation/extensions/state_change_extension.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/listener/email_change_listener.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/listener/mailbox_change_listener.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/notification/local_notification_manager.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/services/fcm_service.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/utils/fcm_utils.dart';
import 'package:tmail_ui_user/main/bindings/main_bindings.dart';
Expand All @@ -47,6 +49,7 @@ class FcmMessageController extends PushBaseController {
TokenOidcCacheManager? _tokenOidcCacheManager;
StateCacheManager? _stateCacheManager;
AuthenticationInfoCacheManager? _authenticationInfoCacheManager;
AppLifecycleListener? _appLifecycleListener;

FcmMessageController._internal();

Expand All @@ -60,6 +63,24 @@ class FcmMessageController extends PushBaseController {

_listenTokenStream();
_listenBackgroundMessageStream();
LocalNotificationManager.instance.clearAllNotifications();
_listenAppLifecycle();
}

@override
void onClose() {
_appLifecycleListener?.dispose();
super.onClose();
}

void _listenAppLifecycle() {
_appLifecycleListener = AppLifecycleListener(
onStateChange: (appLifecycleState) {
if (appLifecycleState == AppLifecycleState.resumed) {
LocalNotificationManager.instance.clearAllNotifications();
}
},
);
}

void _listenBackgroundMessageStream() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class PushBaseController {
.toList();

final listEmailActions = listTypeName
.where((typeName) => typeName == TypeName.emailType || typeName == TypeName.emailDelivery)
.where((typeName) => typeName == TypeName.emailDelivery || typeName == TypeName.emailDelivery)
.map((typeName) => _toPushNotificationAction(typeName, accountId, userName, mapTypeState, isForeground, session: session))
.whereNotNull()
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,8 @@ class LocalNotificationManager {
void closeStream() {
localNotificationsController.close();
}

Future<void> clearAllNotifications() async {
_localNotificationsPlugin.cancelAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,75 +36,6 @@ void main() {
final emailChangeListener = MockEmailChangeListener();
final mailboxChangeListener = MockMailboxChangeListener();

test(
'should call emailChangeListener.dispatchActions with SynchronizeEmailOnForegroundAction '
'when mapTypeState contains emailType '
'and isForeground is true',
() {
// arrange
final state = State('some-state');
final mapTypeState = {TypeName.emailType.value: state.value};

// act
final pushBaseController = TestPushController();
pushBaseController.mappingTypeStateToAction(
mapTypeState,
accountId,
userName,
isForeground: true,
emailChangeListener: emailChangeListener,
mailboxChangeListener: mailboxChangeListener
);

// assert
verify(
emailChangeListener.dispatchActions([
SynchronizeEmailOnForegroundAction(
TypeName.emailType,
state,
accountId,
null,
),
]),
).called(1);
verifyNever(mailboxChangeListener.dispatchActions(any));
});

test(
'should call emailChangeListener.dispatchActions with StoreEmailStateToRefreshAction '
'when mapTypeState contains emailType '
'and isForeground is false',
() {
// arrange
final state = State('some-state');
final mapTypeState = {TypeName.emailType.value: state.value};

// act
final pushBaseController = TestPushController();
pushBaseController.mappingTypeStateToAction(
mapTypeState,
accountId,
userName,
isForeground: false,
emailChangeListener: emailChangeListener,
mailboxChangeListener: mailboxChangeListener
);

// assert
verify(
emailChangeListener.dispatchActions([
StoreEmailStateToRefreshAction(
TypeName.emailType,
state,
accountId,
userName,
null,
),
]),
).called(1);
verifyNever(mailboxChangeListener.dispatchActions(any));
});

test(
'should call emailChangeListener.dispatchActions with nothing '
'when mapTypeState contains emailDelivery '
Expand Down
Loading