|
|
|
|
@ -26,7 +26,8 @@ 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');
|
|
|
|
|
@ -34,11 +35,19 @@ Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
@ -50,13 +59,14 @@ 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,
|
|
|
|
|
@ -131,7 +141,8 @@ 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -177,7 +188,8 @@ 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');
|
|
|
|
|
@ -202,18 +214,27 @@ 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;
|
|
|
|
|
|
|
|
|
|
@ -225,7 +246,8 @@ 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?;
|
|
|
|
|
|
|
|
|
|
@ -410,6 +432,7 @@ 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');
|
|
|
|
|
@ -492,7 +515,8 @@ 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');
|
|
|
|
|
@ -521,7 +545,8 @@ 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') {
|
|
|
|
|
@ -538,11 +563,19 @@ 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;
|
|
|
|
|
|
|
|
|
|
@ -554,7 +587,8 @@ 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?;
|
|
|
|
|
|
|
|
|
|
@ -632,7 +666,11 @@ 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;
|
|
|
|
|
|