From 9f91f1e83c2294fdec5ad566e9cadc3a8bb0c86c Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Wed, 14 Dec 2022 09:59:41 +0300 Subject: [PATCH 1/3] Chat Fixes --- lib/provider/chat_provider_model.dart | 7 +++- lib/ui/chat/chat_bubble.dart | 60 ++++++++++++++++++--------- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index 67899c5..3f76a86 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -371,7 +371,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } } setMsgTune(); - userChatHistory.insert(0, data.first); + if (isChatScreenActive) { + if (data.first.targetUserId == AppState().chatDetails!.response!.id) { + userChatHistory.insert(0, data.first); + } + } if (searchedChats != null && !isChatScreenActive) { for (ChatUser user in searchedChats!) { @@ -868,7 +872,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void onNewChatConversion(List? params) { dynamic items = params!.toList(); - logger.d(items); chatUConvCounter = items[0]["singleChatCount"] ?? 0; notifyListeners(); } diff --git a/lib/ui/chat/chat_bubble.dart b/lib/ui/chat/chat_bubble.dart index c79c66b..03a41e4 100644 --- a/lib/ui/chat/chat_bubble.dart +++ b/lib/ui/chat/chat_bubble.dart @@ -101,15 +101,22 @@ class ChatBubble extends StatelessWidget { ], ), ), - ).paddingOnly(right: 5, bottom: 7), + ).paddingOnly(bottom: 7), if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) - showImage(isReplyPreview: false, fileName: cItem.contant!, fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription).paddingOnly(right: 5).onPress(() { - showDialog( - context: context, - anchorPoint: screenOffset, - builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant!, img: cItem.image!), - ); - }) + ClipRRect( + borderRadius: BorderRadius.circular(5.0), + child: SizedBox( + height: 140, + width: 227, + child: showImage(isReplyPreview: false, fileName: cItem.contant!, fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription).onPress(() { + showDialog( + context: context, + anchorPoint: screenOffset, + builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant!, img: cItem.image!), + ); + }), + ), + ).paddingOnly(bottom: 4) else Row( children: [ @@ -132,12 +139,12 @@ class ChatBubble extends StatelessWidget { ), ), ], - ).paddingOnly(top: 11, left: 13, right: 7, bottom: 5).objectContainerView(disablePadding: true).paddingOnly(left: MediaQuery.of(context).size.width * 0.3); + ).paddingOnly(top: 11, left: 13, right: 13, bottom: 5).objectContainerView(disablePadding: true).paddingOnly(left: MediaQuery.of(context).size.width * 0.3); } Widget receiptUser(BuildContext context) { return Container( - padding: const EdgeInsets.only(top: 11, left: 13, right: 7, bottom: 5), + padding: const EdgeInsets.only(top: 11, left: 13, right: 13, bottom: 5), decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), gradient: const LinearGradient( @@ -190,15 +197,22 @@ class ChatBubble extends StatelessWidget { ], ), ), - ).paddingOnly(right: 5, bottom: 7), + ).paddingOnly(bottom: 7), if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) - showImage(isReplyPreview: false, fileName: cItem.contant ?? "", fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription ?? "image/jpg").paddingOnly(right: 5).onPress(() { - showDialog( - context: context, - anchorPoint: screenOffset, - builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant ?? "", img: cItem.image!), - ); - }) + ClipRRect( + borderRadius: BorderRadius.circular(5.0), + child: SizedBox( + height: 140, + width: 227, + child: showImage(isReplyPreview: false, fileName: cItem.contant ?? "", fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription ?? "image/jpg").onPress(() { + showDialog( + context: context, + anchorPoint: screenOffset, + builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant ?? "", img: cItem.image!), + ); + }), + ), + ).paddingOnly(bottom: 4) else Row( children: [ @@ -212,7 +226,9 @@ class ChatBubble extends StatelessWidget { ), Align( alignment: Alignment.centerRight, - child: dateTime.toText10(color: Colors.white.withOpacity(.71),), + child: dateTime.toText10( + color: Colors.white.withOpacity(.71), + ), ), ], ), @@ -220,12 +236,15 @@ class ChatBubble extends StatelessWidget { } Widget showImage({required bool isReplyPreview, required String fileName, required String fileTypeDescription}) { + if (isReplyPreview) {} + if (cItem.isImageLoaded! && cItem.image != null) { return Image.memory( cItem.image!, height: isReplyPreview ? 32 : 140, width: isReplyPreview ? 32 : 227, fit: BoxFit.cover, + alignment: Alignment.center, ); } else { return FutureBuilder( @@ -233,7 +252,7 @@ class ChatBubble extends StatelessWidget { builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState != ConnectionState.waiting) { if (snapshot.data == null) { - return SizedBox(); + return const SizedBox(); } else { cItem.image = snapshot.data; cItem.isImageLoaded = true; @@ -242,6 +261,7 @@ class ChatBubble extends StatelessWidget { height: isReplyPreview ? 32 : 140, width: isReplyPreview ? 32 : 227, fit: BoxFit.cover, + alignment: Alignment.center, ); } } else { From 2266ace39a6f5331b137253557eca257a9e56847 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Wed, 14 Dec 2022 10:23:21 +0300 Subject: [PATCH 2/3] Chat Fixes & Call Button Disabled --- lib/api/chat/chat_api_client.dart | 30 --------------------------- lib/provider/chat_provider_model.dart | 11 +++++----- lib/ui/chat/chat_detailed_screen.dart | 16 +++++++------- 3 files changed, 14 insertions(+), 43 deletions(-) diff --git a/lib/api/chat/chat_api_client.dart b/lib/api/chat/chat_api_client.dart index 3ef8fba..35e4f79 100644 --- a/lib/api/chat/chat_api_client.dart +++ b/lib/api/chat/chat_api_client.dart @@ -60,17 +60,6 @@ class ChatApiClient { json.decode(response.body), ); } catch (e) { - // if (e.message == "api_common_unauthorized") { - // user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken(); - // if (userLoginResponse.response != null) { - // AppState().setchatUserDetails = userLoginResponse; - // getRecentChats(); - // } else { - // Utils.showToast( - // userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr", - // ); - // } - // } throw e; } } @@ -97,16 +86,6 @@ class ChatApiClient { } return response; } catch (e) { - // e as APIException; - // if (e.message == "api_common_unauthorized") { - // user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken(); - // if (userLoginResponse.response != null) { - // AppState().setchatUserDetails = userLoginResponse; - // getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal); - // } else { - // Utils.showToast(userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr"); - // } - // } throw e; } } @@ -135,15 +114,6 @@ class ChatApiClient { return favoriteChatUser; } catch (e) { e as APIException; - // if (e.message == "api_common_unauthorized") { - // user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken(); - // if (userLoginResponse.response != null) { - // AppState().setchatUserDetails = userLoginResponse; - // unFavUser(userID: userID, targetUserID: targetUserID); - // } else { - // Utils.showToast(userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr"); - // } - // } throw e; } } diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index 3f76a86..fbcb801 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -36,6 +36,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { String chatCID = ''; bool isLoading = true; bool isChatScreenActive = false; + int ReceiverID = 0; + late File selectedFile; bool isFileSelected = false; String sFileType = ""; @@ -142,6 +144,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { if (isNewChat) userChatHistory = []; if (!loadMore) paginationVal = 0; isChatScreenActive = true; + ReceiverID = receiverUID; Response response = await ChatApiClient().getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal); if (response.statusCode == 204) { if (isNewChat) { @@ -371,13 +374,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } } setMsgTune(); - if (isChatScreenActive) { - if (data.first.targetUserId == AppState().chatDetails!.response!.id) { - userChatHistory.insert(0, data.first); - } + if (isChatScreenActive && data.first.currentUserId == ReceiverID) { + userChatHistory.insert(0, data.first); } - if (searchedChats != null && !isChatScreenActive) { + if (searchedChats != null) { for (ChatUser user in searchedChats!) { if (user.id == data.first.currentUserId) { int tempCount = user.unreadMessageCount ?? 0; diff --git a/lib/ui/chat/chat_detailed_screen.dart b/lib/ui/chat/chat_detailed_screen.dart index be685df..5cad3fa 100644 --- a/lib/ui/chat/chat_detailed_screen.dart +++ b/lib/ui/chat/chat_detailed_screen.dart @@ -85,14 +85,14 @@ class _ChatDetailScreenState extends State { showTyping: true, chatUser: params!.chatUser, actions: [ - SvgPicture.asset("assets/icons/chat/call.svg", width: 21, height: 23).onPress(() { - // makeCall(callType: "AUDIO", con: hubConnection); - }), - 24.width, - SvgPicture.asset("assets/icons/chat/video_call.svg", width: 21, height: 18).onPress(() { - // makeCall(callType: "VIDEO", con: hubConnection); - }), - 21.width, + // SvgPicture.asset("assets/icons/chat/call.svg", width: 21, height: 23).onPress(() { + // // makeCall(callType: "AUDIO", con: hubConnection); + // }), + // 24.width, + // SvgPicture.asset("assets/icons/chat/video_call.svg", width: 21, height: 18).onPress(() { + // // makeCall(callType: "VIDEO", con: hubConnection); + // }), + // 21.width, ], ), body: SafeArea( From cb4b95ddb45856083e47df39717902fa9b78ca05 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Wed, 14 Dec 2022 10:47:33 +0300 Subject: [PATCH 3/3] Read Issue On Sub Page --- lib/provider/chat_provider_model.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index fbcb801..876737f 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -36,7 +36,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { String chatCID = ''; bool isLoading = true; bool isChatScreenActive = false; - int ReceiverID = 0; + int receiverID = 0; late File selectedFile; bool isFileSelected = false; @@ -144,7 +144,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { if (isNewChat) userChatHistory = []; if (!loadMore) paginationVal = 0; isChatScreenActive = true; - ReceiverID = receiverUID; + receiverID = receiverUID; Response response = await ChatApiClient().getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal); if (response.statusCode == 204) { if (isNewChat) { @@ -163,7 +163,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { isLoading = false; notifyListeners(); - markRead(userChatHistory, receiverUID); + if (isChatScreenActive && receiverUID == receiverID) { + markRead(userChatHistory, receiverUID); + } generateConvId(); } @@ -374,7 +376,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } } setMsgTune(); - if (isChatScreenActive && data.first.currentUserId == ReceiverID) { + if (isChatScreenActive && data.first.currentUserId == receiverID) { userChatHistory.insert(0, data.first); } @@ -389,7 +391,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } List list = [ - {"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 && data.first.currentUserId == receiverID ? true : false} ]; updateUserChatHistoryOnMsg(list); invokeChatCounter(userId: AppState().chatDetails!.response!.id!); @@ -751,6 +753,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { searchedChats = pChatHistory; search.clear(); isChatScreenActive = false; + receiverID = 0; paginationVal = 0; message.text = ''; isFileSelected = false; @@ -764,6 +767,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { searchedChats = pChatHistory; search.clear(); isChatScreenActive = false; + receiverID = 0; paginationVal = 0; message.text = ''; isFileSelected = false;