|  |  |  | @ -1,21 +1,21 @@ | 
		
	
		
			
				|  |  |  |  | import 'dart:async'; | 
		
	
		
			
				|  |  |  |  | import 'dart:convert'; | 
		
	
		
			
				|  |  |  |  | import 'dart:io'; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | import 'package:easy_localization/easy_localization.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/cupertino.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:flutter/foundation.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:http/http.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:logger/logger.dart' as L; | 
		
	
		
			
				|  |  |  |  | import 'package:logging/logging.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/api/api_client.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/api/chat/chat_api_client.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/app_state/app_state.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/classes/consts.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/classes/utils.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/main.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' as login; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/models/chat/make_user_favotire_unfavorite_chat_model.dart' as fav; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:mohem_flutter_app/widgets/image_picker.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:signalr_netcore/signalr_client.dart'; | 
		
	
		
			
				|  |  |  |  | import 'package:uuid/uuid.dart'; | 
		
	
	
		
			
				
					|  |  |  | @ -26,9 +26,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |   TextEditingController search = TextEditingController(); | 
		
	
		
			
				|  |  |  |  |   List<SingleUserChatModel> userChatHistory = []; | 
		
	
		
			
				|  |  |  |  |   List<ChatUser>? pChatHistory, searchedChats; | 
		
	
		
			
				|  |  |  |  |   late HubConnection hubConnection; | 
		
	
		
			
				|  |  |  |  |   L.Logger logger = L.Logger(); | 
		
	
		
			
				|  |  |  |  |   bool hubConInitialized = false; | 
		
	
		
			
				|  |  |  |  |   String chatCID = ''; | 
		
	
		
			
				|  |  |  |  |   bool isLoading = true; | 
		
	
		
			
				|  |  |  |  |   bool isChatScreenActive = false; | 
		
	
	
		
			
				
					|  |  |  | @ -40,56 +37,20 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |   List<ChatUser> favUsersList = []; | 
		
	
		
			
				|  |  |  |  |   int paginationVal = 0; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> getUserAutoLoginToken(BuildContext cxt) async { | 
		
	
		
			
				|  |  |  |  |     Response response = await ApiClient().postJsonForResponse( | 
		
	
		
			
				|  |  |  |  |       "${ApiConsts.chatServerBaseApiUrl}user/externaluserlogin", | 
		
	
		
			
				|  |  |  |  |       { | 
		
	
		
			
				|  |  |  |  |         "employeeNumber": AppState().memberInformationList!.eMPLOYEENUMBER.toString(), | 
		
	
		
			
				|  |  |  |  |         "password": "FxIu26rWIKoF8n6mpbOmAjDLphzFGmpG", | 
		
	
		
			
				|  |  |  |  |       }, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     login.UserAutoLoginModel userLoginResponse = login.userAutoLoginModelFromJson( | 
		
	
		
			
				|  |  |  |  |       response.body, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (userLoginResponse.response != null) { | 
		
	
		
			
				|  |  |  |  |       hubConInitialized = true; | 
		
	
		
			
				|  |  |  |  |       AppState().setchatUserDetails = userLoginResponse; | 
		
	
		
			
				|  |  |  |  |       await buildHubConnection(); | 
		
	
		
			
				|  |  |  |  |     } else { | 
		
	
		
			
				|  |  |  |  |       Utils.showToast( | 
		
	
		
			
				|  |  |  |  |         userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr", | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  |       return; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<List<ChatUser>?> getChatMemberFromSearch(String sName, int cUserId) async { | 
		
	
		
			
				|  |  |  |  |     Response response = await ApiClient().getJsonForResponse( | 
		
	
		
			
				|  |  |  |  |       "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatSearchMember}$sName/$cUserId", | 
		
	
		
			
				|  |  |  |  |       token: AppState().chatDetails!.response!.token, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     return searchUserJsonModel(response.body); | 
		
	
		
			
				|  |  |  |  |   void registerEvents() { | 
		
	
		
			
				|  |  |  |  |     hubConnection.on("OnUpdateUserStatusAsync", changeStatus); | 
		
	
		
			
				|  |  |  |  |     hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); | 
		
	
		
			
				|  |  |  |  |     //   hubConnection.on("OnSeenChatUserAsync", onChatSeen); | 
		
	
		
			
				|  |  |  |  |     //hubConnection.on("OnUserTypingAsync", onUserTyping); | 
		
	
		
			
				|  |  |  |  |     hubConnection.on("OnUserCountAsync", userCountAsync); | 
		
	
		
			
				|  |  |  |  |     hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); | 
		
	
		
			
				|  |  |  |  |     hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); | 
		
	
		
			
				|  |  |  |  |     hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   List<ChatUser> searchUserJsonModel(String str) => List<ChatUser>.from( | 
		
	
		
			
				|  |  |  |  |         json.decode(str).map( | 
		
	
		
			
				|  |  |  |  |               (x) => ChatUser.fromJson(x), | 
		
	
		
			
				|  |  |  |  |             ), | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void getUserRecentChats() async { | 
		
	
		
			
				|  |  |  |  |     Response response = await ApiClient().getJsonForResponse( | 
		
	
		
			
				|  |  |  |  |       "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatRecentUrl}", | 
		
	
		
			
				|  |  |  |  |       token: AppState().chatDetails!.response!.token, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     ChatUserModel recentChat = userToList(response.body); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     Response favRes = await ApiClient().getJsonForResponse( | 
		
	
		
			
				|  |  |  |  |       "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatFavoriteUsers}${AppState().chatDetails!.response!.id}", | 
		
	
		
			
				|  |  |  |  |       token: AppState().chatDetails!.response!.token, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     ChatUserModel favUList = userToList(favRes.body); | 
		
	
		
			
				|  |  |  |  |     ChatUserModel recentChat = await ChatApiClient().getRecentChats(); | 
		
	
		
			
				|  |  |  |  |     ChatUserModel favUList = await ChatApiClient().getFavUsers(); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (favUList.response != null && recentChat.response != null) { | 
		
	
		
			
				|  |  |  |  |       favUsersList = favUList.response!; | 
		
	
	
		
			
				
					|  |  |  | @ -108,14 +69,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     pChatHistory = recentChat.response ?? []; | 
		
	
		
			
				|  |  |  |  |     pChatHistory!.sort( | 
		
	
		
			
				|  |  |  |  |       (ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo( | 
		
	
		
			
				|  |  |  |  |             b.userName!.toLowerCase(), | 
		
	
		
			
				|  |  |  |  |           ), | 
		
	
		
			
				|  |  |  |  |       (ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase()), | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     searchedChats = pChatHistory; | 
		
	
		
			
				|  |  |  |  |     isLoading = false; | 
		
	
		
			
				|  |  |  |  |     getUserChatHistoryNotDeliveredAsync( | 
		
	
		
			
				|  |  |  |  |     await getUserChatHistoryNotDeliveredAsync( | 
		
	
		
			
				|  |  |  |  |       userId: int.parse( | 
		
	
		
			
				|  |  |  |  |         AppState().chatDetails!.response!.id.toString(), | 
		
	
		
			
				|  |  |  |  |       ), | 
		
	
	
		
			
				
					|  |  |  | @ -124,14 +82,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future getUserChatHistoryNotDeliveredAsync({required int userId}) async { | 
		
	
		
			
				|  |  |  |  |     await hubConnection.invoke( | 
		
	
		
			
				|  |  |  |  |       "GetUserChatHistoryNotDeliveredAsync", | 
		
	
		
			
				|  |  |  |  |       args: [userId], | 
		
	
		
			
				|  |  |  |  |     ).onError( | 
		
	
		
			
				|  |  |  |  |       (Error error, StackTrace stackTrace) => { | 
		
	
		
			
				|  |  |  |  |         logger.d(error), | 
		
	
		
			
				|  |  |  |  |       }, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     // try { | 
		
	
		
			
				|  |  |  |  |     await hubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]); | 
		
	
		
			
				|  |  |  |  |     // } finally { | 
		
	
		
			
				|  |  |  |  |     //   hubConnection.off("OnGetUserChatHistoryNotDeliveredAsync", method: chatNotDelivered); | 
		
	
		
			
				|  |  |  |  |     // } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     return ""; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -140,9 +96,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |     if (isNewChat) userChatHistory = []; | 
		
	
		
			
				|  |  |  |  |     if (!loadMore) paginationVal = 0; | 
		
	
		
			
				|  |  |  |  |     isChatScreenActive = true; | 
		
	
		
			
				|  |  |  |  |     Response response = await ApiClient().getJsonForResponse( | 
		
	
		
			
				|  |  |  |  |       "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatSingleUserHistoryUrl}/$senderUID/$receiverUID/$paginationVal", | 
		
	
		
			
				|  |  |  |  |       token: AppState().chatDetails!.response!.token, | 
		
	
		
			
				|  |  |  |  |     Response response = await ChatApiClient().getSingleUserChatHistory( | 
		
	
		
			
				|  |  |  |  |       senderUID: senderUID, | 
		
	
		
			
				|  |  |  |  |       receiverUID: receiverUID, | 
		
	
		
			
				|  |  |  |  |       loadMore: loadMore, | 
		
	
		
			
				|  |  |  |  |       paginationVal: paginationVal, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     if (response.statusCode == 204) { | 
		
	
		
			
				|  |  |  |  |       if (isNewChat) { | 
		
	
	
		
			
				
					|  |  |  | @ -165,9 +123,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |         ).reversed.toList(); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     await getUserChatHistoryNotDeliveredAsync( | 
		
	
		
			
				|  |  |  |  |       userId: senderUID, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     isLoading = false; | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |     markRead( | 
		
	
	
		
			
				
					|  |  |  | @ -184,16 +139,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void markRead(List<SingleUserChatModel> data, reciverID) { | 
		
	
		
			
				|  |  |  |  |     for (SingleUserChatModel element in data!) { | 
		
	
		
			
				|  |  |  |  |       if (!element.isSeen!) { | 
		
	
		
			
				|  |  |  |  |         dynamic data = [ | 
		
	
		
			
				|  |  |  |  |           { | 
		
	
		
			
				|  |  |  |  |             "userChatHistoryId": element.userChatHistoryId, | 
		
	
		
			
				|  |  |  |  |             "TargetUserId": element.targetUserId, | 
		
	
		
			
				|  |  |  |  |             "isDelivered": true, | 
		
	
		
			
				|  |  |  |  |             "isSeen": true, | 
		
	
		
			
				|  |  |  |  |           } | 
		
	
		
			
				|  |  |  |  |         ]; | 
		
	
		
			
				|  |  |  |  |         updateUserChatHistoryStatusAsync(data); | 
		
	
		
			
				|  |  |  |  |       if (element.isSeen != null) { | 
		
	
		
			
				|  |  |  |  |         if (!element.isSeen!) { | 
		
	
		
			
				|  |  |  |  |           dynamic data = [ | 
		
	
		
			
				|  |  |  |  |             { | 
		
	
		
			
				|  |  |  |  |               "userChatHistoryId": element.userChatHistoryId, | 
		
	
		
			
				|  |  |  |  |               "TargetUserId": element.targetUserId, | 
		
	
		
			
				|  |  |  |  |               "isDelivered": true, | 
		
	
		
			
				|  |  |  |  |               "isSeen": true, | 
		
	
		
			
				|  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |           ]; | 
		
	
		
			
				|  |  |  |  |           updateUserChatHistoryStatusAsync(data); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     for (ChatUser element in searchedChats!) { | 
		
	
	
		
			
				
					|  |  |  | @ -217,34 +174,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |             ), | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   ChatUserModel userToList(String str) => ChatUserModel.fromJson( | 
		
	
		
			
				|  |  |  |  |         json.decode(str), | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<dynamic> uploadAttachments(String userId, File file) async { | 
		
	
		
			
				|  |  |  |  |     dynamic result; | 
		
	
		
			
				|  |  |  |  |     dynamic request = MultipartRequest( | 
		
	
		
			
				|  |  |  |  |       'POST', | 
		
	
		
			
				|  |  |  |  |       Uri.parse( | 
		
	
		
			
				|  |  |  |  |         '${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatMediaImageUploadUrl}', | 
		
	
		
			
				|  |  |  |  |       ), | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     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}', | 
		
	
		
			
				|  |  |  |  |       }, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     try { | 
		
	
		
			
				|  |  |  |  |       StreamedResponse response = await request.send(); | 
		
	
		
			
				|  |  |  |  |       StreamedResponse response = await ChatApiClient().uploadMedia(userId, file); | 
		
	
		
			
				|  |  |  |  |       if (response.statusCode == 200) { | 
		
	
		
			
				|  |  |  |  |         result = jsonDecode( | 
		
	
		
			
				|  |  |  |  |           await response.stream.bytesToString(), | 
		
	
	
		
			
				
					|  |  |  | @ -253,60 +186,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |         result = []; | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     } catch (e) { | 
		
	
		
			
				|  |  |  |  |       if (kDebugMode) { | 
		
	
		
			
				|  |  |  |  |         print(e); | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |       print(e); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     ; | 
		
	
		
			
				|  |  |  |  |     return result; | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> buildHubConnection() async { | 
		
	
		
			
				|  |  |  |  |     HttpConnectionOptions httpOp = HttpConnectionOptions( | 
		
	
		
			
				|  |  |  |  |       skipNegotiation: false, | 
		
	
		
			
				|  |  |  |  |       logMessageContent: true, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     hubConnection = HubConnectionBuilder() | 
		
	
		
			
				|  |  |  |  |         .withUrl( | 
		
	
		
			
				|  |  |  |  |           ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", | 
		
	
		
			
				|  |  |  |  |           options: httpOp, | 
		
	
		
			
				|  |  |  |  |         ) | 
		
	
		
			
				|  |  |  |  |         .withAutomaticReconnect( | 
		
	
		
			
				|  |  |  |  |           retryDelays: <int>[ | 
		
	
		
			
				|  |  |  |  |             2000, | 
		
	
		
			
				|  |  |  |  |             5000, | 
		
	
		
			
				|  |  |  |  |             10000, | 
		
	
		
			
				|  |  |  |  |             20000, | 
		
	
		
			
				|  |  |  |  |           ], | 
		
	
		
			
				|  |  |  |  |         ) | 
		
	
		
			
				|  |  |  |  |         .configureLogging( | 
		
	
		
			
				|  |  |  |  |           Logger("Loggin"), | 
		
	
		
			
				|  |  |  |  |         ) | 
		
	
		
			
				|  |  |  |  |         .build(); | 
		
	
		
			
				|  |  |  |  |     hubConnection.onclose( | 
		
	
		
			
				|  |  |  |  |       ({Exception? error}) {}, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     hubConnection.onreconnecting( | 
		
	
		
			
				|  |  |  |  |       ({Exception? error}) {}, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     hubConnection.onreconnected( | 
		
	
		
			
				|  |  |  |  |       ({String? connectionId}) {}, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |     if (hubConnection.state != HubConnectionState.Connected) { | 
		
	
		
			
				|  |  |  |  |       await hubConnection.start(); | 
		
	
		
			
				|  |  |  |  |       print("Connnnnn Stablished"); | 
		
	
		
			
				|  |  |  |  |       hubConnection.on("OnUpdateUserStatusAsync", changeStatus); | 
		
	
		
			
				|  |  |  |  |       hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); | 
		
	
		
			
				|  |  |  |  |       //   hubConnection.on("OnSeenChatUserAsync", onChatSeen); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |       //hubConnection.on("OnUserTypingAsync", onUserTyping); | 
		
	
		
			
				|  |  |  |  |       hubConnection.on("OnUserCountAsync", userCountAsync); | 
		
	
		
			
				|  |  |  |  |       hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); | 
		
	
		
			
				|  |  |  |  |       hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); | 
		
	
		
			
				|  |  |  |  |       hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void updateUserChatStatus(List<Object?>? args) { | 
		
	
		
			
				|  |  |  |  |     dynamic items = args!.toList(); | 
		
	
		
			
				|  |  |  |  |     for (dynamic cItem in items[0]) { | 
		
	
	
		
			
				
					|  |  |  | @ -359,6 +244,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void chatNotDelivered(List<Object?>? args) { | 
		
	
		
			
				|  |  |  |  |     dynamic items = args!.toList(); | 
		
	
		
			
				|  |  |  |  |     logger.d(items); | 
		
	
		
			
				|  |  |  |  |     for (dynamic item in items[0]) { | 
		
	
		
			
				|  |  |  |  |       searchedChats!.forEach( | 
		
	
		
			
				|  |  |  |  |         (ChatUser element) { | 
		
	
	
		
			
				
					|  |  |  | @ -374,11 +260,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void changeStatus(List<Object?>? args) { | 
		
	
		
			
				|  |  |  |  |     if (kDebugMode) { | 
		
	
		
			
				|  |  |  |  |       // print("================= Status Online // Offline  ===================="); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     dynamic items = args!.toList(); | 
		
	
		
			
				|  |  |  |  |     // logger.d(items); | 
		
	
		
			
				|  |  |  |  |     for (ChatUser user in searchedChats!) { | 
		
	
		
			
				|  |  |  |  |       if (user.id == items.first["id"]) { | 
		
	
		
			
				|  |  |  |  |         user.userStatus = items.first["userStatus"]; | 
		
	
	
		
			
				
					|  |  |  | @ -413,14 +295,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |       data.first.currentUserId = temp.first.targetUserId; | 
		
	
		
			
				|  |  |  |  |       data.first.currentUserName = temp.first.targetUserName; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     logger.d(jsonEncode(data)); | 
		
	
		
			
				|  |  |  |  |     userChatHistory.insert(0, data.first); | 
		
	
		
			
				|  |  |  |  |     // searchedChats!.forEach((element) { | 
		
	
		
			
				|  |  |  |  |     //   if (element.id == data.first.currentUserId) { | 
		
	
		
			
				|  |  |  |  |     //     var val = element.unreadMessageCount == null ? 0 : element.unreadMessageCount; | 
		
	
		
			
				|  |  |  |  |     //     element.unreadMessageCount = val! + 1; | 
		
	
		
			
				|  |  |  |  |     //   } | 
		
	
		
			
				|  |  |  |  |     // }); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     var list = [ | 
		
	
		
			
				|  |  |  |  |       { | 
		
	
		
			
				|  |  |  |  |         "userChatHistoryId": data.first.userChatHistoryId, | 
		
	
	
		
			
				
					|  |  |  | @ -430,14 +306,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |     ]; | 
		
	
		
			
				|  |  |  |  |     updateUserChatHistoryStatusAsync(list); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |     //  if (isChatScreenActive) scrollToBottom(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   void onUserTyping(List<Object?>? parameters) { | 
		
	
		
			
				|  |  |  |  |     //  print("==================== Typing Active =================="); | 
		
	
		
			
				|  |  |  |  |     //   logger.d(parameters); | 
		
	
		
			
				|  |  |  |  |     for (ChatUser user in searchedChats!) { | 
		
	
		
			
				|  |  |  |  |       if (user.id == parameters![1] && parameters[0] == true) { | 
		
	
		
			
				|  |  |  |  |         user.isTyping = parameters[0] as bool?; | 
		
	
	
		
			
				
					|  |  |  | @ -572,7 +444,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |       notifyListeners(); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     if (!isFileSelected && !isMsgReply) { | 
		
	
		
			
				|  |  |  |  |       logger.d("Normal Text Message"); | 
		
	
		
			
				|  |  |  |  |       if (message.text == null || message.text.isEmpty) { | 
		
	
		
			
				|  |  |  |  |         return; | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
	
		
			
				
					|  |  |  | @ -580,14 +451,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     if (isFileSelected && !isMsgReply) { | 
		
	
		
			
				|  |  |  |  |       Utils.showLoading(context); | 
		
	
		
			
				|  |  |  |  |       //logger.d("Normal Attachment Message"); | 
		
	
		
			
				|  |  |  |  |       dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); | 
		
	
		
			
				|  |  |  |  |       String? ext = getFileExtension(selectedFile.path); | 
		
	
		
			
				|  |  |  |  |       Utils.hideLoading(context); | 
		
	
		
			
				|  |  |  |  |       sendChatToServer(chatEventId: 2, fileTypeId: getFileType(ext.toString()), targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: true, chatReplyId: null, isReply: false); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     if (!isFileSelected && isMsgReply) { | 
		
	
		
			
				|  |  |  |  |       //  logger.d("Normal Text Message With Reply"); | 
		
	
		
			
				|  |  |  |  |       if (message.text == null || message.text.isEmpty) { | 
		
	
		
			
				|  |  |  |  |         return; | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
	
		
			
				
					|  |  |  | @ -595,7 +464,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |           chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, chatReplyId: repliedMsg.first.userChatHistoryId, isAttachment: false, isReply: true); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     if (isFileSelected && isMsgReply) { | 
		
	
		
			
				|  |  |  |  |       //  logger.d("Attachment Message With Reply"); | 
		
	
		
			
				|  |  |  |  |       Utils.showLoading(context); | 
		
	
		
			
				|  |  |  |  |       dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); | 
		
	
		
			
				|  |  |  |  |       String? ext = getFileExtension(selectedFile.path); | 
		
	
	
		
			
				
					|  |  |  | @ -708,9 +576,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> favoriteUser({required int userID, required int targetUserID}) async { | 
		
	
		
			
				|  |  |  |  |     Response response = | 
		
	
		
			
				|  |  |  |  |         await ApiClient().postJsonForResponse("${ApiConsts.chatServerBaseApiUrl}FavUser/addFavUser", {"targetUserId": targetUserID, "userId": userID}, token: AppState().chatDetails!.response!.token); | 
		
	
		
			
				|  |  |  |  |     fav.FavoriteChatUser favoriteChatUser = fav.FavoriteChatUser.fromRawJson(response.body); | 
		
	
		
			
				|  |  |  |  |     fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().favUser(userID: userID, targetUserID: targetUserID); | 
		
	
		
			
				|  |  |  |  |     if (favoriteChatUser.response != null) { | 
		
	
		
			
				|  |  |  |  |       for (ChatUser user in searchedChats!) { | 
		
	
		
			
				|  |  |  |  |         if (user.id == favoriteChatUser.response!.targetUserId!) { | 
		
	
	
		
			
				
					|  |  |  | @ -723,16 +589,16 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |   Future<void> unFavoriteUser({required int userID, required int targetUserID}) async { | 
		
	
		
			
				|  |  |  |  |     Response response = await ApiClient() | 
		
	
		
			
				|  |  |  |  |         .postJsonForResponse("${ApiConsts.chatServerBaseApiUrl}FavUser/deleteFavUser", {"targetUserId": targetUserID, "userId": userID}, token: AppState().chatDetails!.response!.token); | 
		
	
		
			
				|  |  |  |  |     fav.FavoriteChatUser favoriteChatUser = fav.FavoriteChatUser.fromRawJson(response.body); | 
		
	
		
			
				|  |  |  |  |     fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().unFavUser(userID: userID, targetUserID: targetUserID); | 
		
	
		
			
				|  |  |  |  |     if (favoriteChatUser.response != null) { | 
		
	
		
			
				|  |  |  |  |       for (var user in searchedChats!) { | 
		
	
		
			
				|  |  |  |  |       for (ChatUser user in searchedChats!) { | 
		
	
		
			
				|  |  |  |  |         if (user.id == favoriteChatUser.response!.targetUserId!) { | 
		
	
		
			
				|  |  |  |  |           user.isFav = favoriteChatUser.response!.isFav; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |       } | 
		
	
		
			
				|  |  |  |  |       favUsersList.removeWhere((ChatUser element) => element.id == targetUserID); | 
		
	
		
			
				|  |  |  |  |       favUsersList.removeWhere( | 
		
	
		
			
				|  |  |  |  |         (ChatUser element) => element.id == targetUserID, | 
		
	
		
			
				|  |  |  |  |       ); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     notifyListeners(); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
	
		
			
				
					|  |  |  | @ -784,4 +650,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
		
	
		
			
				|  |  |  |  |       curve: Curves.easeIn, | 
		
	
		
			
				|  |  |  |  |     ); | 
		
	
		
			
				|  |  |  |  |   } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | // void getUserChatHistoryNotDeliveredAsync({required int userId}) async { | 
		
	
		
			
				|  |  |  |  | //   try { | 
		
	
		
			
				|  |  |  |  | //     await hubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]); | 
		
	
		
			
				|  |  |  |  | //   } finally { | 
		
	
		
			
				|  |  |  |  | //     hubConnection.off("GetUserChatHistoryNotDeliveredAsync", method: chatNotDelivered); | 
		
	
		
			
				|  |  |  |  | //   } | 
		
	
		
			
				|  |  |  |  | // } | 
		
	
		
			
				|  |  |  |  | } |