|
|
|
|
@ -26,28 +26,19 @@ import 'package:flutter_callkit_incoming/entities/entities.dart';
|
|
|
|
|
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
|
|
|
try {
|
|
|
|
|
log('📱 [BACKGROUND] Data payload: ${message.data}', name: 'FirebaseNotificationManger');
|
|
|
|
|
final notificationType = message.data['notificationType'] as String? ??
|
|
|
|
|
message.data['type'] as String?;
|
|
|
|
|
final notificationType = message.data['notificationType'] as String? ?? message.data['type'] as String?;
|
|
|
|
|
final transactionType = message.data['transactionType'] as String?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log('📱 [BACKGROUND] Notification Type: $notificationType', name: 'FirebaseNotificationManger');
|
|
|
|
|
|
|
|
|
|
// Handle incoming call notifications
|
|
|
|
|
if (notificationType == 'incoming_call' || transactionType == 'call') {
|
|
|
|
|
// Extract call data
|
|
|
|
|
final callId = message.data['callId'] as String? ??
|
|
|
|
|
message.data['sessionId'] as String? ??
|
|
|
|
|
DateTime.now().millisecondsSinceEpoch.toString();
|
|
|
|
|
final callId = message.data['callId'] as String? ?? message.data['sessionId'] as String? ?? DateTime.now().millisecondsSinceEpoch.toString();
|
|
|
|
|
|
|
|
|
|
final callerId = message.data['callerId'] as String? ??
|
|
|
|
|
message.data['callerEmployeeNumber'] as String? ??
|
|
|
|
|
message.data['sourceUserId'] as String? ??
|
|
|
|
|
'unknown';
|
|
|
|
|
final callerId = message.data['callerId'] as String? ?? message.data['callerEmployeeNumber'] as String? ?? message.data['sourceUserId'] as String? ?? 'unknown';
|
|
|
|
|
|
|
|
|
|
final callerName = message.data['callerName'] as String? ??
|
|
|
|
|
message.data['callerUserName'] as String? ??
|
|
|
|
|
message.data['userName'] as String? ??
|
|
|
|
|
'Unknown Caller';
|
|
|
|
|
final callerName = message.data['callerName'] as String? ?? message.data['callerUserName'] as String? ?? message.data['userName'] as String? ?? 'Unknown Caller';
|
|
|
|
|
|
|
|
|
|
final callerEmployeeNumber = message.data['callerEmployeeNumber'] as String? ?? callerId;
|
|
|
|
|
|
|
|
|
|
@ -59,14 +50,13 @@ Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
|
|
|
return false;
|
|
|
|
|
}();
|
|
|
|
|
|
|
|
|
|
final moduleId = message.data['moduleId'] as String? ??
|
|
|
|
|
message.data['applicationId']?.toString();
|
|
|
|
|
final moduleId = message.data['moduleId'] as String? ?? message.data['applicationId']?.toString();
|
|
|
|
|
final referenceId = message.data['referenceId'] as String?;
|
|
|
|
|
final conversationId = message.data['conversationId'] as String?;
|
|
|
|
|
|
|
|
|
|
// CRITICAL FIX: DO NOT initialize any communication services in background isolate
|
|
|
|
|
// Only persist call data and show CallKit
|
|
|
|
|
///TODO need to find other solution to this after testing
|
|
|
|
|
///TODO need to find other solution to this after testing
|
|
|
|
|
await PendingCallStorage.savePendingCall(
|
|
|
|
|
callId: callId,
|
|
|
|
|
callerId: callerId,
|
|
|
|
|
@ -141,8 +131,7 @@ Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
|
|
|
|
|
|
|
|
log('═══════════════════════════════════════════', name: 'FirebaseNotificationManger');
|
|
|
|
|
} catch (e, stackTrace) {
|
|
|
|
|
log('❌ [BACKGROUND] Error handling background message: $e',
|
|
|
|
|
name: 'FirebaseNotificationManger', error: e, stackTrace: stackTrace);
|
|
|
|
|
log('❌ [BACKGROUND] Error handling background message: $e', name: 'FirebaseNotificationManger', error: e, stackTrace: stackTrace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -188,8 +177,7 @@ class FirebaseNotificationManger {
|
|
|
|
|
//print("pushToken:$token");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void _onMessageReceived(h_push.RemoteMessage remoteMessage) {
|
|
|
|
|
}
|
|
|
|
|
static void _onMessageReceived(h_push.RemoteMessage remoteMessage) {}
|
|
|
|
|
|
|
|
|
|
static void _onMessageReceiveError(Object error) {
|
|
|
|
|
log('❌ [HUAWEI] Message receive error: ${error.toString()}', name: 'FirebaseNotificationManger');
|
|
|
|
|
@ -214,27 +202,18 @@ class FirebaseNotificationManger {
|
|
|
|
|
log('📱 [HANDLE_MESSAGE] Full message data: $messageData', name: 'FirebaseNotificationManger');
|
|
|
|
|
|
|
|
|
|
// FIXED: Check if this is a call notification first - CHECK BOTH 'notificationType' AND 'type'
|
|
|
|
|
final notificationType = messageData['notificationType'] as String? ??
|
|
|
|
|
messageData['type'] as String?; // Backend uses 'type'
|
|
|
|
|
final notificationType = messageData['notificationType'] as String? ?? messageData['type'] as String?; // Backend uses 'type'
|
|
|
|
|
final transactionType = messageData['transactionType'] as String?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log('📱 [HANDLE_MESSAGE] Notification Type: $notificationType', name: 'FirebaseNotificationManger');
|
|
|
|
|
|
|
|
|
|
if (notificationType == 'incoming_call' || transactionType == 'call') {
|
|
|
|
|
// CRITICAL FIX: Show CallKit UI in foreground just like background
|
|
|
|
|
final callId = messageData['callId'] as String? ??
|
|
|
|
|
messageData['sessionId'] as String? ??
|
|
|
|
|
DateTime.now().millisecondsSinceEpoch.toString();
|
|
|
|
|
final callId = messageData['callId'] as String? ?? messageData['sessionId'] as String? ?? DateTime.now().millisecondsSinceEpoch.toString();
|
|
|
|
|
|
|
|
|
|
final callerId = messageData['callerId'] as String? ??
|
|
|
|
|
messageData['callerEmployeeNumber'] as String? ??
|
|
|
|
|
messageData['sourceUserId'] as String? ??
|
|
|
|
|
'unknown';
|
|
|
|
|
final callerId = messageData['callerId'] as String? ?? messageData['callerEmployeeNumber'] as String? ?? messageData['sourceUserId'] as String? ?? 'unknown';
|
|
|
|
|
|
|
|
|
|
final callerName = messageData['callerName'] as String? ??
|
|
|
|
|
messageData['callerUserName'] as String? ??
|
|
|
|
|
messageData['userName'] as String? ??
|
|
|
|
|
'Unknown Caller';
|
|
|
|
|
final callerName = messageData['callerName'] as String? ?? messageData['callerUserName'] as String? ?? messageData['userName'] as String? ?? 'Unknown Caller';
|
|
|
|
|
|
|
|
|
|
final callerEmployeeNumber = messageData['callerEmployeeNumber'] as String? ?? callerId;
|
|
|
|
|
|
|
|
|
|
@ -246,8 +225,7 @@ class FirebaseNotificationManger {
|
|
|
|
|
return false;
|
|
|
|
|
}();
|
|
|
|
|
|
|
|
|
|
final moduleId = messageData['moduleId'] as String? ??
|
|
|
|
|
messageData['applicationId']?.toString();
|
|
|
|
|
final moduleId = messageData['moduleId'] as String? ?? messageData['applicationId']?.toString();
|
|
|
|
|
final referenceId = messageData['referenceId'] as String?;
|
|
|
|
|
final conversationId = messageData['conversationId'] as String?;
|
|
|
|
|
|
|
|
|
|
@ -432,7 +410,6 @@ class FirebaseNotificationManger {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static initialized(BuildContext context) async {
|
|
|
|
|
|
|
|
|
|
//TOD0 add platform check here also
|
|
|
|
|
if (!(await isGoogleServicesAvailable()) && Platform.isAndroid) {
|
|
|
|
|
log('📱 [INIT] Using Huawei Push Services', name: 'FirebaseNotificationManger');
|
|
|
|
|
@ -515,8 +492,7 @@ class FirebaseNotificationManger {
|
|
|
|
|
FirebaseMessaging.instance.getInitialMessage().then((initialMessage) {
|
|
|
|
|
if (initialMessage != null) {
|
|
|
|
|
// Check if it's a call notification
|
|
|
|
|
final notificationType = initialMessage.data['notificationType'] as String? ??
|
|
|
|
|
initialMessage.data['type'] as String?;
|
|
|
|
|
final notificationType = initialMessage.data['notificationType'] as String? ?? initialMessage.data['type'] as String?;
|
|
|
|
|
final transactionType = initialMessage.data['transactionType'] as String?;
|
|
|
|
|
log('📱 [FCM_INITIAL] Notification Type: $notificationType', name: 'FirebaseNotificationManger');
|
|
|
|
|
log('📱 [FCM_INITIAL] Transaction Type: $transactionType', name: 'FirebaseNotificationManger');
|
|
|
|
|
@ -545,8 +521,7 @@ class FirebaseNotificationManger {
|
|
|
|
|
log('📱 [FCM_FOREGROUND] Body: ${message.notification?.body}', name: 'FirebaseNotificationManger');
|
|
|
|
|
|
|
|
|
|
// FIXED: Check if it's a call notification - CHECK BOTH 'notificationType' AND 'type'
|
|
|
|
|
final notificationType = message.data['notificationType'] as String? ??
|
|
|
|
|
message.data['type'] as String?; // Backend uses 'type'
|
|
|
|
|
final notificationType = message.data['notificationType'] as String? ?? message.data['type'] as String?; // Backend uses 'type'
|
|
|
|
|
log('📱 [FCM_FOREGROUND] Notification Type: $notificationType', name: 'FirebaseNotificationManger');
|
|
|
|
|
|
|
|
|
|
if (notificationType == 'incoming_call') {
|
|
|
|
|
@ -563,19 +538,11 @@ class FirebaseNotificationManger {
|
|
|
|
|
log(' - applicationId: ${message.data['applicationId']}', name: 'FirebaseNotificationManger');
|
|
|
|
|
|
|
|
|
|
// CRITICAL FIX: Show CallKit UI in foreground
|
|
|
|
|
final callId = message.data['callId'] as String? ??
|
|
|
|
|
message.data['sessionId'] as String? ??
|
|
|
|
|
DateTime.now().millisecondsSinceEpoch.toString();
|
|
|
|
|
final callId = message.data['callId'] as String? ?? message.data['sessionId'] as String? ?? DateTime.now().millisecondsSinceEpoch.toString();
|
|
|
|
|
|
|
|
|
|
final callerId = message.data['callerId'] as String? ??
|
|
|
|
|
message.data['callerEmployeeNumber'] as String? ??
|
|
|
|
|
message.data['sourceUserId'] as String? ??
|
|
|
|
|
'unknown';
|
|
|
|
|
final callerId = message.data['callerId'] as String? ?? message.data['callerEmployeeNumber'] as String? ?? message.data['sourceUserId'] as String? ?? 'unknown';
|
|
|
|
|
|
|
|
|
|
final callerName = message.data['callerName'] as String? ??
|
|
|
|
|
message.data['callerUserName'] as String? ??
|
|
|
|
|
message.data['userName'] as String? ??
|
|
|
|
|
'Unknown Caller';
|
|
|
|
|
final callerName = message.data['callerName'] as String? ?? message.data['callerUserName'] as String? ?? message.data['userName'] as String? ?? 'Unknown Caller';
|
|
|
|
|
|
|
|
|
|
final callerEmployeeNumber = message.data['callerEmployeeNumber'] as String? ?? callerId;
|
|
|
|
|
|
|
|
|
|
@ -587,8 +554,7 @@ class FirebaseNotificationManger {
|
|
|
|
|
return false;
|
|
|
|
|
}();
|
|
|
|
|
|
|
|
|
|
final moduleId = message.data['moduleId'] as String? ??
|
|
|
|
|
message.data['applicationId']?.toString();
|
|
|
|
|
final moduleId = message.data['moduleId'] as String? ?? message.data['applicationId']?.toString();
|
|
|
|
|
final referenceId = message.data['referenceId'] as String?;
|
|
|
|
|
final conversationId = message.data['conversationId'] as String?;
|
|
|
|
|
|
|
|
|
|
@ -666,16 +632,12 @@ class FirebaseNotificationManger {
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
if (message.data["notificationType"] != 'NurseConfirmArrive') {
|
|
|
|
|
NotificationManger.showNotification(
|
|
|
|
|
title: message.notification?.title ?? "",
|
|
|
|
|
subtext: message.notification?.body ?? "",
|
|
|
|
|
hashcode: int.tryParse("1234") ?? 1,
|
|
|
|
|
payload: json.encode(message.data),
|
|
|
|
|
context: context);
|
|
|
|
|
title: message.notification?.title ?? "", subtext: message.notification?.body ?? "", hashcode: int.tryParse("1234") ?? 1, payload: json.encode(message.data), context: context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
|
|
|
|
log('═══════════════════════════════════════════', name: 'FirebaseNotificationManger');
|
|
|
|
|
log('📱 [FCM_TAP] Notification tapped', name: 'FirebaseNotificationManger');
|
|
|
|
|
@ -697,7 +659,7 @@ class FirebaseNotificationManger {
|
|
|
|
|
}
|
|
|
|
|
log('═══════════════════════════════════════════', name: 'FirebaseNotificationManger');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
|
|
|
|
|
|
|
|
|
|
log('✅ [INIT] FirebaseNotificationManger initialized successfully', name: 'FirebaseNotificationManger');
|
|
|
|
|
|