diff --git a/lib/api/chat/chat_provider_model.dart b/lib/api/chat/chat_provider_model.dart index 7a27c1f..a019294 100644 --- a/lib/api/chat/chat_provider_model.dart +++ b/lib/api/chat/chat_provider_model.dart @@ -115,6 +115,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { searchedChats = pChatHistory; isLoading = false; + getUserChatHistoryNotDeliveredAsync( + userId: int.parse( + AppState().chatDetails!.response!.id.toString(), + ), + ); notifyListeners(); } @@ -122,6 +127,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { await hubConnection.invoke( "GetUserChatHistoryNotDeliveredAsync", args: [userId], + ).onError( + (Error error, StackTrace stackTrace) => { + logger.d(error), + }, ); return ""; } @@ -220,8 +229,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { '${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatMediaImageUploadUrl}', ), ); - request.fields.addAll({'userId': userId, 'fileSource': '1'}); - request.files.add(await MultipartFile.fromPath('files', file.path)); + request.fields.addAll( + {'userId': userId, 'fileSource': '1'}, + ); + request.files.add( + await MultipartFile.fromPath( + 'files', + file.path, + ), + ); request.headers.addAll( { 'Authorization': 'Bearer ${AppState().chatDetails!.response!.token}', @@ -256,7 +272,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { options: httpOp, ) .withAutomaticReconnect( - retryDelays: [2000, 5000, 10000, 20000], + retryDelays: [ + 2000, + 5000, + 10000, + 20000, + ], ) .configureLogging( Logger("Loggin"), @@ -273,11 +294,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { ); if (hubConnection.state != HubConnectionState.Connected) { await hubConnection.start(); - getUserChatHistoryNotDeliveredAsync( - userId: int.parse( - AppState().chatDetails!.response!.id.toString(), - ), - ); + print("Connnnnn Stablished"); hubConnection.on("OnUpdateUserStatusAsync", changeStatus); hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); // hubConnection.on("OnSeenChatUserAsync", onChatSeen); @@ -343,21 +360,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void chatNotDelivered(List? args) { dynamic items = args!.toList(); for (dynamic item in items[0]) { - searchedChats!.forEach((element) { - if (element.id == item["currentUserId"]) { - var val = element.unreadMessageCount == null ? 0 : element.unreadMessageCount; - element.unreadMessageCount = val! + 1; - } - }); - // dynamic data = [ - // { - // "userChatHistoryId": item["userChatHistoryId"], - // "TargetUserId": item["targetUserId"], - // "isDelivered": true, - // "isSeen": true, - // } - // ]; - // updateUserChatHistoryStatusAsync(data); + searchedChats!.forEach( + (ChatUser element) { + if (element.id == item["currentUserId"]) { + int? val = element.unreadMessageCount ?? 0; + element.unreadMessageCount = val! + 1; + } + element.isLoadingCounter = false; + }, + ); } notifyListeners(); } diff --git a/lib/models/chat/call.dart b/lib/models/chat/call.dart index 20f6a79..7f8f6eb 100644 --- a/lib/models/chat/call.dart +++ b/lib/models/chat/call.dart @@ -7,7 +7,7 @@ import 'dart:convert'; class CallDataModel { CallDataModel({ this.callerId, - this.callReciverId, + this.callReceiverID, this.notificationForeground, this.message, this.title, @@ -27,7 +27,7 @@ class CallDataModel { }); String? callerId; - String? callReciverId; + String? callReceiverID; String? notificationForeground; String? message; String? title; @@ -51,7 +51,7 @@ class CallDataModel { factory CallDataModel.fromJson(Map json) => CallDataModel( callerId: json["callerID"] == null ? null : json["callerID"], - callReciverId: json["callReciverID"] == null ? null : json["callReciverID"], + callReceiverID: json["callReceiverID"] == null ? null : json["callReceiverID"], notificationForeground: json["notification_foreground"] == null ? null : json["notification_foreground"], message: json["message"] == null ? null : json["message"], title: json["title"] == null ? null : json["title"], @@ -78,7 +78,7 @@ class CallDataModel { Map toJson() => { "callerID": callerId == null ? null : callerId, - "callReciverID": callReciverId == null ? null : callReciverId, + "callReceiverID": callReceiverID == null ? null : callReceiverID, "notification_foreground": notificationForeground == null ? null : notificationForeground, "message": message == null ? null : message, "title": title == null ? null : title, diff --git a/lib/models/chat/get_search_user_chat_model.dart b/lib/models/chat/get_search_user_chat_model.dart index ceee0de..31d1085 100644 --- a/lib/models/chat/get_search_user_chat_model.dart +++ b/lib/models/chat/get_search_user_chat_model.dart @@ -19,21 +19,21 @@ class ChatUserModel { } class ChatUser { - ChatUser({ - this.id, - this.userName, - this.email, - this.phone, - this.title, - this.userStatus, - this.image, - this.unreadMessageCount, - this.userAction, - this.isPin, - this.isFav, - this.isAdmin, - this.isTyping, - }); + ChatUser( + {this.id, + this.userName, + this.email, + this.phone, + this.title, + this.userStatus, + this.image, + this.unreadMessageCount, + this.userAction, + this.isPin, + this.isFav, + this.isAdmin, + this.isTyping, + this.isLoadingCounter}); int? id; String? userName; @@ -48,6 +48,7 @@ class ChatUser { bool? isFav; bool? isAdmin; bool? isTyping; + bool? isLoadingCounter; factory ChatUser.fromJson(Map json) => ChatUser( id: json["id"] == null ? null : json["id"], @@ -63,6 +64,7 @@ class ChatUser { isFav: json["isFav"] == null ? null : json["isFav"], isAdmin: json["isAdmin"] == null ? null : json["isAdmin"], isTyping: false, + isLoadingCounter: true, ); Map toJson() => { diff --git a/lib/ui/chat/chat_detailed_screen.dart b/lib/ui/chat/chat_detailed_screen.dart index 4a8e70c..1374608 100644 --- a/lib/ui/chat/chat_detailed_screen.dart +++ b/lib/ui/chat/chat_detailed_screen.dart @@ -38,13 +38,14 @@ class _ChatDetailScreenState extends State { void getMoreChat() async { if (userDetails != null) { data.paginationVal = data.paginationVal + 10; - if (userDetails != null) + if (userDetails != null) { data.getSingleUserChatHistory( senderUID: AppState().chatDetails!.response!.id!.toInt(), receiverUID: userDetails["targetUser"].id, loadMore: true, isNewChat: false, ); + } } await Future.delayed( const Duration( @@ -76,10 +77,10 @@ class _ChatDetailScreenState extends State { actions: [ IconButton( onPressed: () { - // makeCall( - // callType: "AUDIO", - // con: data.hubConnection, - // ); + makeCall( + callType: "AUDIO", + con: data.hubConnection, + ); }, icon: SvgPicture.asset( "assets/icons/chat/call.svg", @@ -89,10 +90,10 @@ class _ChatDetailScreenState extends State { ), IconButton( onPressed: () { - // makeCall( - // callType: "VIDEO", - // con: data.hubConnection, - // ); + makeCall( + callType: "VIDEO", + con: data.hubConnection, + ); }, icon: SvgPicture.asset( "assets/icons/chat/video_call.svg", @@ -357,38 +358,41 @@ class _ChatDetailScreenState extends State { void makeCall({required String callType, required HubConnection con}) async { print("================== Make call Triggered ============================"); - logger.d(jsonEncode(AppState().chatDetails!.response)); Map json = { "callerID": AppState().chatDetails!.response!.id!.toString(), - "callReciverID": userDetails["targetUser"].id.toString(), + "callReceiverID": userDetails["targetUser"].id.toString(), "notification_foreground": "true", - "message": "Aamir is calling ", + "message": "Aamir is calling", "title": "Video Call", "type": callType == "VIDEO" ? "Video" : "Audio", - "identity": "Aamir.Muhammad", - "name": "Aamir Saleem Ahmad", + "identity": AppState().chatDetails!.response!.userName, + "name": AppState().chatDetails!.response!.title, "is_call": "true", "is_webrtc": "true", - "contant": "Start video Call Aamir.Muhammad", + "contant": "Start video Call ${AppState().chatDetails!.response!.userName}", "contantNo": "775d1f11-62d9-6fcc-91f6-21f8c14559fb", "chatEventId": "3", "fileTypeId": null, - "currentUserId": "266642", + "currentUserId": AppState().chatDetails!.response!.id!.toString(), "chatSource": "1", "userChatHistoryLineRequestList": [ - {"isSeen": false, "isDelivered": false, "targetUserId": 341682, "targetUserStatus": 4} + { + "isSeen": false, + "isDelivered": false, + "targetUserId": userDetails["targetUser"].id, + "targetUserStatus": 4, + } ], // "server": "https://192.168.8.163:8086", "server": "https://livecareturn.hmg.com:8086", }; - - CallDataModel incomingCallData = CallDataModel.fromJson(json); + CallDataModel callData = CallDataModel.fromJson(json); await Navigator.push( context, MaterialPageRoute( builder: (BuildContext context) => OutGoingCall( isVideoCall: callType == "VIDEO" ? true : false, - OutGoingCallData: incomingCallData, + OutGoingCallData: callData, ), ), ); diff --git a/lib/ui/chat/chat_home_screen.dart b/lib/ui/chat/chat_home_screen.dart index 816aaec..63523f5 100644 --- a/lib/ui/chat/chat_home_screen.dart +++ b/lib/ui/chat/chat_home_screen.dart @@ -135,6 +135,22 @@ class _ChatHomeScreenState extends State { mainAxisAlignment: MainAxisAlignment.end, mainAxisSize: MainAxisSize.max, children: [ + if (m.searchedChats![index].isLoadingCounter!) + Flexible( + child: Container( + padding: EdgeInsets.zero, + alignment: Alignment.centerRight, + width: 18, + height: 18, + decoration: const BoxDecoration( + // color: MyColors.redColor, + borderRadius: BorderRadius.all( + Radius.circular(20), + ), + ), + child: CircularProgressIndicator(), + ), + ), if (m.searchedChats![index].unreadMessageCount! > 0) Flexible( child: Container( @@ -193,7 +209,7 @@ class _ChatHomeScreenState extends State { AppRoutes.chatDetailed, arguments: {"targetUser": m.searchedChats![index], "isNewChat": false}, ).then((Object? value) { - // m.GetUserChatHistoryNotDeliveredAsync(userId: int.parse(AppState().chatDetails!.response!.id.toString())); + // m.GetUserChatHistoryNotDeliveredAsync(userId: int.parse(AppState().chatDetails!.response!.id.toString())); m.clearSelections(); m.notifyListeners(); });