|  |  | @ -5,6 +5,7 @@ import 'package:easy_localization/easy_localization.dart'; | 
			
		
	
		
		
			
				
					
					|  |  |  | import 'package:flutter/cupertino.dart'; |  |  |  | import 'package:flutter/cupertino.dart'; | 
			
		
	
		
		
			
				
					
					|  |  |  | import 'package:flutter/foundation.dart'; |  |  |  | import 'package:flutter/foundation.dart'; | 
			
		
	
		
		
			
				
					
					|  |  |  | import 'package:http/http.dart'; |  |  |  | import 'package:http/http.dart'; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import 'package:just_audio/just_audio.dart'; | 
			
		
	
		
		
			
				
					
					|  |  |  | import 'package:mohem_flutter_app/api/chat/chat_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/app_state/app_state.dart'; | 
			
		
	
		
		
			
				
					
					|  |  |  | import 'package:mohem_flutter_app/classes/consts.dart'; |  |  |  | import 'package:mohem_flutter_app/classes/consts.dart'; | 
			
		
	
	
		
		
			
				
					|  |  | @ -53,6 +54,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
			
		
	
		
		
			
				
					
					|  |  |  |   Future<void> buildHubConnection() async { |  |  |  |   Future<void> buildHubConnection() async { | 
			
		
	
		
		
			
				
					
					|  |  |  |     chatHubConnection = await getHubConnection(); |  |  |  |     chatHubConnection = await getHubConnection(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     await chatHubConnection.start(); |  |  |  |     await chatHubConnection.start(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     print("Startedddddddd"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   Future<HubConnection> getHubConnection() async { |  |  |  |   Future<HubConnection> getHubConnection() async { | 
			
		
	
	
		
		
			
				
					|  |  | @ -74,7 +77,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   void registerEvents() { |  |  |  |   void registerEvents() { | 
			
		
	
		
		
			
				
					
					|  |  |  |     chatHubConnection.on("OnUpdateUserStatusAsync", changeStatus); |  |  |  |     chatHubConnection.on("OnUpdateUserStatusAsync", changeStatus); | 
			
		
	
		
		
			
				
					
					|  |  |  |     chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); |  |  |  |     //   chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     // hubConnection.on("OnSeenChatUserAsync", onChatSeen); |  |  |  |     // hubConnection.on("OnSeenChatUserAsync", onChatSeen); | 
			
		
	
		
		
			
				
					
					|  |  |  |     //hubConnection.on("OnUserTypingAsync", onUserTyping); |  |  |  |     //hubConnection.on("OnUserTypingAsync", onUserTyping); | 
			
		
	
		
		
			
				
					
					|  |  |  |     chatHubConnection.on("OnUserCountAsync", userCountAsync); |  |  |  |     chatHubConnection.on("OnUserCountAsync", userCountAsync); | 
			
		
	
	
		
		
			
				
					|  |  | @ -134,6 +137,13 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (isNewChat) userChatHistory = []; |  |  |  |     if (isNewChat) userChatHistory = []; | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (!loadMore) paginationVal = 0; |  |  |  |     if (!loadMore) paginationVal = 0; | 
			
		
	
		
		
			
				
					
					|  |  |  |     isChatScreenActive = true; |  |  |  |     isChatScreenActive = true; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // if (chatHubConnection.state != HubConnectionState.Connected) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //   getUserAutoLoginToken().whenComplete(() async { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //     await buildHubConnection(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //     getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //   }); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //   return; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // } | 
			
		
	
		
		
			
				
					
					|  |  |  |     Response response = await ChatApiClient().getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal); |  |  |  |     Response response = await ChatApiClient().getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal); | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (response.statusCode == 204) { |  |  |  |     if (response.statusCode == 204) { | 
			
		
	
		
		
			
				
					
					|  |  |  |       if (isNewChat) { |  |  |  |       if (isNewChat) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -335,13 +345,13 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |       } |  |  |  |       } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     setMsgTune(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     userChatHistory.insert(0, data.first); |  |  |  |     userChatHistory.insert(0, data.first); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (searchedChats != null && !isChatScreenActive) { |  |  |  |     if (searchedChats != null && !isChatScreenActive) { | 
			
		
	
		
		
			
				
					
					|  |  |  |       for (ChatUser user in searchedChats!) { |  |  |  |       for (ChatUser user in searchedChats!) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (user.id == data.first.currentUserId) { |  |  |  |         if (user.id == data.first.currentUserId) { | 
			
		
	
		
		
			
				
					
					|  |  |  |           var tempCount = user.unreadMessageCount ?? 0; |  |  |  |           int tempCount = user.unreadMessageCount ?? 0; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |           user.unreadMessageCount = tempCount + 1; |  |  |  |           user.unreadMessageCount = tempCount + 1; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |       } |  |  |  |       } | 
			
		
	
	
		
		
			
				
					|  |  | @ -351,6 +361,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
			
		
	
		
		
			
				
					
					|  |  |  |       {"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive ? true : false} |  |  |  |       {"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive ? true : false} | 
			
		
	
		
		
			
				
					
					|  |  |  |     ]; |  |  |  |     ]; | 
			
		
	
		
		
			
				
					
					|  |  |  |     updateUserChatHistoryOnMsg(list); |  |  |  |     updateUserChatHistoryOnMsg(list); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     notifyListeners(); |  |  |  |     notifyListeners(); | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -731,6 +742,26 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { | 
			
		
	
		
		
			
				
					
					|  |  |  |     notifyListeners(); |  |  |  |     notifyListeners(); | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   void setMsgTune() async { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     AudioPlayer player = AudioPlayer(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     await player.setVolume(1.0); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     String audioAsset = ""; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (Platform.isAndroid) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       audioAsset = "assets/audio/pulse_tone_android.mp3"; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       audioAsset = "assets/audio/pulse_tune_ios.caf"; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     try { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       await player.setAsset(audioAsset); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       await player.load(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       player.play(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } catch (e) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       print("Error: $e"); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   Future<void> playSuccessSound() async {} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   ///getUserAutoLoginToken().whenComplete(() { |  |  |  |   ///getUserAutoLoginToken().whenComplete(() { | 
			
		
	
		
		
			
				
					
					|  |  |  | //         buildHubConnection(); |  |  |  | //         buildHubConnection(); | 
			
		
	
		
		
			
				
					
					|  |  |  | //         print("After Reconnect State: " + hubConnection.state.toString()); |  |  |  | //         print("After Reconnect State: " + hubConnection.state.toString()); | 
			
		
	
	
		
		
			
				
					|  |  | 
 |