TF-2384 Handle open email detailed when click notification on terminated mode
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit d59ed90fa89755f476150eaee7527282ef0bae7a)
This commit is contained in:
@@ -8,6 +8,7 @@ import flutter_local_notifications
|
||||
@objc class AppDelegate: FlutterAppDelegate {
|
||||
|
||||
var notificationInteractionChannel: FlutterMethodChannel?
|
||||
var initialNotificationInfo: Any?
|
||||
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
@@ -16,6 +17,7 @@ import flutter_local_notifications
|
||||
GeneratedPluginRegistrant.register(with: self)
|
||||
|
||||
createNotificationInteractionChannel()
|
||||
initialNotificationInfo = launchOptions?[.remoteNotification]
|
||||
|
||||
if #available(iOS 10.0, *) {
|
||||
UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
|
||||
@@ -142,5 +144,15 @@ extension AppDelegate {
|
||||
name: "notification_interaction_channel",
|
||||
binaryMessenger: controller.binaryMessenger
|
||||
)
|
||||
|
||||
self.notificationInteractionChannel?.setMethodCallHandler { (call, result) in
|
||||
switch call.method {
|
||||
case "getInitialNotificationInfo":
|
||||
result(self.initialNotificationInfo)
|
||||
self.initialNotificationInfo = nil
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:core/utils/platform_info.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
@@ -21,6 +22,7 @@ import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_recent_lo
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_recent_login_username_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/cleanup/domain/usecases/cleanup_recent_search_cache_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/preview_email_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/push_notification/presentation/services/fcm_receiver.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_utils.dart';
|
||||
@@ -50,8 +52,8 @@ class HomeController extends ReloadableController {
|
||||
_initFlutterDownloader();
|
||||
_registerReceivingSharingIntent();
|
||||
}
|
||||
if (PlatformInfo.isIOS && Get.arguments is EmailId) {
|
||||
_emailIdPreview = Get.arguments;
|
||||
if (PlatformInfo.isIOS) {
|
||||
_handleIOSDataMessage();
|
||||
}
|
||||
super.onInit();
|
||||
}
|
||||
@@ -114,4 +116,18 @@ class HomeController extends ReloadableController {
|
||||
|
||||
_emailReceiveManager.receivingFileSharingStream.listen(_emailReceiveManager.setPendingFileInfo);
|
||||
}
|
||||
|
||||
Future _handleIOSDataMessage() async {
|
||||
if (Get.arguments is EmailId) {
|
||||
_emailIdPreview = Get.arguments;
|
||||
} else {
|
||||
final notificationInfo = await FcmReceiver.instance.getIOSInitialNotificationInfo();
|
||||
if (notificationInfo != null && notificationInfo.containsKey('email_id')) {
|
||||
final emailId = notificationInfo['email_id'] as String?;
|
||||
if (emailId?.isNotEmpty == true) {
|
||||
_emailIdPreview = EmailId(Id(emailId!));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class FcmReceiver {
|
||||
if (PlatformInfo.isIOS) {
|
||||
notificationInteractionChannel.setMethodCallHandler((call) async {
|
||||
log('FcmReceiver::onInitialFcmListener:notificationInteractionChannel: $call');
|
||||
if (call.method == 'openEmail') {
|
||||
if (call.method == 'openEmail' && call.arguments is String) {
|
||||
log('FcmReceiver::onInitialFcmListener:openEmail with id = ${call.arguments}');
|
||||
FcmService.instance.handleOpenEmailFromNotification(call.arguments);
|
||||
}
|
||||
@@ -72,4 +72,18 @@ class FcmReceiver {
|
||||
Future deleteFcmToken() async {
|
||||
await FirebaseMessaging.instance.deleteToken();
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> getIOSInitialNotificationInfo() async {
|
||||
try {
|
||||
final notificationInfo = await notificationInteractionChannel.invokeMethod('getInitialNotificationInfo');
|
||||
log('FcmReceiver::getIOSInitialNotificationInfo:notificationInfo: $notificationInfo');
|
||||
if (notificationInfo != null && notificationInfo is Map<String, dynamic>) {
|
||||
return notificationInfo;
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
logError('FcmReceiver::getIOSInitialNotificationInfo: Exception: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user