From e022aff0b0587651aa54dc9e3bde835c93412de7 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Sun, 11 Oct 2026 13:45:16 +0300 Subject: [PATCH] update device token/platform for calling --- lib/controllers/api_routes/urls.dart | 1 + .../firebase_notification_manger.dart | 2 +- .../cx_module/chat/chat_api_client.dart | 23 +++++++++++++++---- lib/new_views/pages/land_page/land_page.dart | 8 ++++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/controllers/api_routes/urls.dart b/lib/controllers/api_routes/urls.dart index fc7be716..a9b65eab 100644 --- a/lib/controllers/api_routes/urls.dart +++ b/lib/controllers/api_routes/urls.dart @@ -21,6 +21,7 @@ class URLs { static const String chatHubUrlChat = "$chatHubUrl/hubs/chat"; // new V2 apis static const String resetMessageCount = "$chatHubUrlApi/userChatHistory/AckMessages"; // new V2 apis static const String unreadMessages = "$chatHubUrlApi/userChatHistory/unread-messages"; // new V2 apis + static const String updateDeviceInfo = "$chatHubUrlApi/user/update-device-info"; // new V2 apis static const String chatApiKey = "f53a98286f82798d588f67a7f0db19f7aebc839e"; // new V2 apis static String _host = host1; diff --git a/lib/controllers/notification/firebase_notification_manger.dart b/lib/controllers/notification/firebase_notification_manger.dart index 2d1d5c1d..08f2204f 100644 --- a/lib/controllers/notification/firebase_notification_manger.dart +++ b/lib/controllers/notification/firebase_notification_manger.dart @@ -358,7 +358,7 @@ class FirebaseNotificationManger { } } - initialized(BuildContext context) async { + Future initialized(BuildContext context) async { // iOS incoming calls: VoIP pushes are handled natively in AppDelegate (PushKit -> CallKit // via flutter_callkit_incoming). Accept/decline arrive through FlutterCallkitIncoming.onEvent // (land_page.dart) or, from a cold start, FlutterCallkitIncoming.activeCalls() (splash_page.dart). diff --git a/lib/modules/cx_module/chat/chat_api_client.dart b/lib/modules/cx_module/chat/chat_api_client.dart index 00c55668..ab9cba3a 100644 --- a/lib/modules/cx_module/chat/chat_api_client.dart +++ b/lib/modules/cx_module/chat/chat_api_client.dart @@ -45,7 +45,7 @@ class ChatApiClient { ChatLoginResponse? chatLoginResponse; - Future getChatLoginToken(int moduleId, int requestId, String title, String employeeNumber, String assigneeEmployeeNumber) async { + Future myPlatform() async { String platform; if (Platform.isIOS) { platform = "IOS"; @@ -56,6 +56,22 @@ class ChatApiClient { platform = "HUAWEI"; } } + return platform; + } + + Future updateDeviceInfo(String employeeNumber) async { + final Map payload = { + "employeeNumber": employeeNumber, + "deviceToken": FirebaseNotificationManger.token, + "isHuaweiDevice": (await myPlatform()) == "HUAWEI", + "platform": await myPlatform(), + "voIPToken": FirebaseNotificationManger.voipToken, + }; + final Response response = await ApiClient().postJsonForResponse(URLs.updateDeviceInfo, payload, token: chatLoginResponse!.token); + return response.statusCode == 200; + } + + Future getChatLoginToken(int moduleId, int requestId, String title, String employeeNumber, String assigneeEmployeeNumber) async { Response response = await ApiClient().postJsonForResponse(URLs.chatSdkToken, { "apiKey": URLs.chatApiKey, "employeeNumber": employeeNumber, @@ -67,8 +83,8 @@ class ChatApiClient { // "referenceType": "ticket", "title": title, "deviceToken": FirebaseNotificationManger.token, - "isHuaweiDevice": platform == "HUAWEI", - "platform": platform, + "isHuaweiDevice": (await myPlatform()) == "HUAWEI", + "platform": await myPlatform(), "voIPToken": FirebaseNotificationManger.voipToken, }); @@ -109,7 +125,6 @@ class ChatApiClient { return response.statusCode == 200; } - Future> viewAllDocuments(int moduleId, int referenceId) async { Response response = await ApiClient().getJsonForResponse("${URLs.chatHubUrlApi}/attachments/conversation?referenceId=$referenceId&moduleCode=$moduleId", token: chatLoginResponse!.token); diff --git a/lib/new_views/pages/land_page/land_page.dart b/lib/new_views/pages/land_page/land_page.dart index 764050ad..1680ae09 100644 --- a/lib/new_views/pages/land_page/land_page.dart +++ b/lib/new_views/pages/land_page/land_page.dart @@ -20,6 +20,8 @@ import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/models/enums/user_types.dart'; import 'package:test_sa/modules/cx_module/chat/calling/audio_call_page.dart'; import 'package:test_sa/modules/cx_module/chat/calling/video_call_page.dart'; +import 'package:test_sa/modules/cx_module/chat/chat_api_client.dart'; +import 'package:test_sa/modules/cx_module/chat/chat_provider.dart'; import 'package:test_sa/modules/cx_module/chat/model/chat_participant_model.dart'; import 'package:test_sa/new_views/app_style/app_color.dart'; import 'package:test_sa/new_views/common_widgets/app_filled_button.dart'; @@ -146,7 +148,11 @@ class _LandPageState extends State { const MyAssetsPage(fromBottomBar: true), ]; if (isFCM) { - FirebaseNotificationManger().initialized(context); + FirebaseNotificationManger().initialized(context).then((_) { + if (context.settingProvider.isUserFlowMedical) { + ChatApiClient().updateDeviceInfo(context.userProvider.user!.employeeId ?? context.userProvider.user!.username!); + } + }); callingEvents(context); NotificationManger.initialisation((notificationDetails) { FirebaseNotificationManger.handleMessage(context, json.decode(notificationDetails.payload!));