diff --git a/lib/api/chat/chat_api_client.dart b/lib/api/chat/chat_api_client.dart index 46dcce7..43e9f6c 100644 --- a/lib/api/chat/chat_api_client.dart +++ b/lib/api/chat/chat_api_client.dart @@ -57,6 +57,7 @@ class ChatApiClient { return List.from(json.decode(response.body).map((x) => ChatUser.fromJson(x))); } + //Get User Recent Chats Future getRecentChats() async { try { Response response = await ApiClient().getJsonForResponse( @@ -74,6 +75,7 @@ class ChatApiClient { } } + // Get Favorite Users Future getFavUsers() async { Response favRes = await ApiClient().getJsonForResponse( "${ApiConsts.chatFavUser}getFavUserById/${AppState().chatDetails!.response!.id}", @@ -85,6 +87,7 @@ class ChatApiClient { return ChatUserModel.fromJson(json.decode(favRes.body)); } + //Get User Chat History Future getSingleUserChatHistory({required int senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false, required int paginationVal}) async { try { Response response = await ApiClient().getJsonForResponse( @@ -101,6 +104,7 @@ class ChatApiClient { } } +//Favorite Users Future favUser({required int userID, required int targetUserID}) async { Response response = await ApiClient().postJsonForResponse("${ApiConsts.chatFavUser}addFavUser", {"targetUserId": targetUserID, "userId": userID}, token: AppState().chatDetails!.response!.token); if (!kReleaseMode) { @@ -110,6 +114,7 @@ class ChatApiClient { return favoriteChatUser; } + //UnFavorite Users Future unFavUser({required int userID, required int targetUserID}) async { try { Response response = await ApiClient().postJsonForResponse( @@ -128,9 +133,13 @@ class ChatApiClient { } } +// Upload Chat Media Future uploadMedia(String userId, File file) async { - print("${ApiConsts.chatMediaImageUploadUrl}upload"); - print(AppState().chatDetails!.response!.token); + if (kDebugMode) { + print("${ApiConsts.chatMediaImageUploadUrl}upload"); + print(AppState().chatDetails!.response!.token); + } + dynamic request = MultipartRequest('POST', Uri.parse('${ApiConsts.chatMediaImageUploadUrl}upload')); request.fields.addAll({'userId': userId, 'fileSource': '1'}); request.files.add(await MultipartFile.fromPath('files', file.path)); @@ -154,6 +163,7 @@ class ChatApiClient { return data; } + //Get Chat Users & Favorite Images Future> getUsersImages({required List encryptedEmails}) async { List imagesData = []; Response response = await ApiClient().postJsonForResponse( diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index 974bc30..16bf327 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -68,7 +68,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { Future buildHubConnection() async { chatHubConnection = await getHubConnection(); await chatHubConnection.start(); - print("Startedddddddd"); + if (kDebugMode) { + logger.i("Hub Conn: Startedddddddd"); + } chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); chatHubConnection.on("OnGetChatConversationCount", onNewChatConversion); } @@ -91,7 +93,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { // chatHubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); chatHubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); chatHubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus); - print("Alll Registered"); + if (kDebugMode) { + logger.i("All listeners registered"); + } } void getUserRecentChats() async { @@ -279,7 +283,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void updateChatHistoryWindow(List? args) { dynamic items = args!.toList(); - print("---------------------------------Update Chat History Windows Async -------------------------------------"); + if (kDebugMode) { + logger.i("---------------------------------Update Chat History Windows Async -------------------------------------"); + } logger.d(items); // for (var user in searchedChats!) { // if (user.id == items.first["id"]) { @@ -404,7 +410,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } void OnSubmitChatAsync(List? parameters) { - logger.d(parameters); + logger.i(parameters); List data = [], temp = []; for (dynamic msg in parameters!) { data = getSingleUserChatModel(jsonEncode(msg)); @@ -563,8 +569,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { isImageLoaded: isImageLoaded, voice: voice, ); - print("Model data---------------------------"); - logger.d(data.toJson()); + if (kDebugMode) { + logger.i("model data: " + jsonEncode(data)); + } userChatHistory.insert(0, data); isFileSelected = false; isMsgReply = false; @@ -579,16 +586,19 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void sendChatMessage(BuildContext context, {required int targetUserId, required int userStatus, required String userEmail, required String targetUserName}) async { if (!isFileSelected && !isMsgReply) { - print("Normal Text Msg"); + if (kDebugMode) { + print("Normal Text Msg"); + } if (message.text == null || message.text.isEmpty) { return; } sendChatToServer( chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: false, chatReplyId: null, isReply: false, isImageLoaded: false, image: null); - } // normal Text msg + } if (isFileSelected && !isMsgReply) { - bool isImage = false; - print("Normal Attachment Msg"); + if (kDebugMode) { + logger.i("Normal Attachment Msg"); + } Utils.showLoading(context); dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); String? ext = getFileExtension(selectedFile.path); @@ -623,7 +633,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { image: repliedMsg.first.image); } // reply msg over image && normal if (isFileSelected && isMsgReply) { - print("Reply With File"); + if (kDebugMode) { + print("Reply With File"); + } Utils.showLoading(context); dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); String? ext = getFileExtension(selectedFile.path); @@ -711,7 +723,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { String? getFileExtension(String fileName) { try { if (kDebugMode) { - print("ext: " + "." + fileName.split('.').last); + logger.i("ext: " + "." + fileName.split('.').last); } return "." + fileName.split('.').last; } catch (e) { @@ -836,7 +848,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } void clearAll() { - print("----------------- Disposed ---------------------------"); searchedChats = pChatHistory; search.clear(); isChatScreenActive = false; @@ -1050,9 +1061,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { startRecoding(); } else { recorderController.reset(); - logger.d(recorderController.isRecording); await recorderController.record(path); - logger.d(recorderController.isRecording); _recodeDuration = 0; _startTimer(); isRecoding = !isRecoding; @@ -1142,7 +1151,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { path = await recorderController.stop(false); } if (kDebugMode) { - print(path); + logger.i("path:" + path!); } File voiceFile = File(path!); voiceFile.readAsBytesSync(); @@ -1152,9 +1161,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { isRecoding = false; Utils.showLoading(context); dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), voiceFile); - logger.d(value); String? ext = getFileExtension(voiceFile.path); - logger.d(voiceFile.path!.split("/").last); Utils.hideLoading(context); sendVoiceMessageToServer( msgText: voiceFile.path!.split("/").last, @@ -1168,7 +1175,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { userStatus: userStatus, chatReplyId: null, isAttachment: true, - isReply: false, + isReply: isMsgReply, voicFile: voiceFile, ); notifyListeners(); @@ -1278,7 +1285,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { Uint8List encodedString = await ChatApiClient().downloadURL(fileName: data.contant!, fileTypeDescription: getFileTypeDescription(data.fileTypeResponse!.fileTypeName ?? "")); try { String path = await downChatVoice(encodedString, data.fileTypeResponse!.fileTypeName ?? "", data); - logger.d(path); File file = File(path!); file.readAsBytesSync(); Utils.hideLoading(context); diff --git a/lib/ui/chat/chat_bubble.dart b/lib/ui/chat/chat_bubble.dart index ea87450..bb67365 100644 --- a/lib/ui/chat/chat_bubble.dart +++ b/lib/ui/chat/chat_bubble.dart @@ -100,8 +100,7 @@ class ChatBubble extends StatelessWidget { ], ), ), - ).paddingOnly(bottom: 7).onPress(() { - }), + ).paddingOnly(bottom: 7).onPress(() {}), if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) ClipRRect( borderRadius: BorderRadius.circular(5.0), @@ -204,8 +203,7 @@ class ChatBubble extends StatelessWidget { ], ), ), - ).paddingOnly(bottom: 7).onPress(() { - }), + ).paddingOnly(bottom: 7).onPress(() {}), if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) ClipRRect( borderRadius: BorderRadius.circular(5.0), diff --git a/lib/ui/chat/chat_detailed_screen.dart b/lib/ui/chat/chat_detailed_screen.dart index 1ec1bcf..7b3a72b 100644 --- a/lib/ui/chat/chat_detailed_screen.dart +++ b/lib/ui/chat/chat_detailed_screen.dart @@ -130,7 +130,7 @@ class _ChatDetailScreenState extends State { reverse: true, itemCount: m.userChatHistory.length, padding: const EdgeInsets.all(21), - separatorBuilder: (cxt, index) => 8.height, + separatorBuilder: (BuildContext cxt, int index) => 8.height, itemBuilder: (BuildContext context, int i) { return SwipeTo( iconColor: MyColors.lightGreenColor, @@ -145,14 +145,17 @@ class _ChatDetailScreenState extends State { }, ).onPress(() async { logger.d(m.userChatHistory[i].toJson()); - if (m.userChatHistory[i].fileTypeResponse != null && m.userChatHistory[i].fileTypeId! == 1 || - m.userChatHistory[i].fileTypeId! == 5 || - m.userChatHistory[i].fileTypeId! == 7 || - m.userChatHistory[i].fileTypeId! == 6 || - m.userChatHistory[i].fileTypeId! == 8 || - m.userChatHistory[i].fileTypeId! == 2) { - m.getChatMedia(context, - fileTypeName: m.userChatHistory[i].fileTypeResponse!.fileTypeName ?? "", fileTypeID: m.userChatHistory[i].fileTypeId!, fileName: m.userChatHistory[i].contant!); + if (m.userChatHistory[i].fileTypeResponse != null && m.userChatHistory[i].fileTypeId != null) { + if (m.userChatHistory[i].fileTypeId! == 1 || + m.userChatHistory[i].fileTypeId! == 5 || + m.userChatHistory[i].fileTypeId! == 7 || + m.userChatHistory[i].fileTypeId! == 6 || + m.userChatHistory[i].fileTypeId! == 8 + // || m.userChatHistory[i].fileTypeId! == 2 + ) { + m.getChatMedia(context, + fileTypeName: m.userChatHistory[i].fileTypeResponse!.fileTypeName ?? "", fileTypeID: m.userChatHistory[i].fileTypeId!, fileName: m.userChatHistory[i].contant!); + } } }); }, @@ -312,7 +315,7 @@ class _ChatDetailScreenState extends State { () => m.selectImageToUpload(context), ), ).paddingOnly(right: 15), - Icon( + const Icon( Icons.mic, color: MyColors.lightGreenColor, ).paddingOnly(right: 15).onPress(() {