From ef347f1078041c406a54a61d60a4d888eebd8259 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Mon, 12 Dec 2022 16:53:21 +0300 Subject: [PATCH 1/4] Sort Fix --- lib/provider/chat_provider_model.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index d3639c9..d5b81fe 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -125,6 +125,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { AppState().chatDetails!.response!.id.toString(), ), ); + sort(); notifyListeners(); if (searchedChats!.isNotEmpty) { getUserImages(); From feb5c5071caa3e636e258e41841c7d8d50a94f0e Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Tue, 13 Dec 2022 09:54:32 +0300 Subject: [PATCH 2/4] Fav Users Images Fix --- lib/provider/chat_provider_model.dart | 22 +++++++++++----------- lib/ui/landing/dashboard_screen.dart | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index d5b81fe..ca07b9b 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -127,7 +127,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { ); sort(); notifyListeners(); - if (searchedChats!.isNotEmpty) { + if (searchedChats!.isNotEmpty || favUsersList.isNotEmpty) { getUserImages(); } } @@ -142,19 +142,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { if (isNewChat) userChatHistory = []; if (!loadMore) paginationVal = 0; 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); if (response.statusCode == 204) { if (isNewChat) { userChatHistory = []; } else if (loadMore) { - // userChatHistory = []; Utils.showToast("No More Data To Load"); } } else { @@ -765,9 +757,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void getUserImages() async { List emails = []; - for (ChatUser element in searchedChats!) { + List exists = [], unique = []; + exists.addAll(searchedChats!); + exists.addAll(favUsersList!); + Map profileMap = {}; + for (ChatUser item in exists) { + profileMap[item.email!] = item; + } + unique = profileMap.values.toList(); + for (ChatUser element in unique!) { emails.add(await EmailImageEncryption().encrypt(val: element.email!)); } + List chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails); for (ChatUser user in searchedChats!) { for (ChatUserImageModel uImage in chatImages) { @@ -848,7 +849,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { String path = await downChatMedia(encodedString, fileTypeName ?? ""); Utils.hideLoading(context); OpenFile.open(path); - } catch (e) { Utils.showToast("Cannot open file."); } diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index 0e9053a..1800aa3 100644 --- a/lib/ui/landing/dashboard_screen.dart +++ b/lib/ui/landing/dashboard_screen.dart @@ -72,6 +72,9 @@ class _DashboardScreenState extends State { void _bHubCon() { cProvider.getUserAutoLoginToken().whenComplete(() { cProvider.buildHubConnection(); + Future.delayed(const Duration(seconds: 2), () { + cProvider.invokeChatCounter(userId: AppState().chatDetails!.response!.id!); + }); }); } From 2a39ee9ddc8f929bc9d4b1caabb7652b7e26cdb9 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Tue, 13 Dec 2022 10:00:27 +0300 Subject: [PATCH 3/4] Fav Users Images Fix --- lib/ui/chat/chat_home.dart | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/ui/chat/chat_home.dart b/lib/ui/chat/chat_home.dart index 7d0631e..807af1a 100644 --- a/lib/ui/chat/chat_home.dart +++ b/lib/ui/chat/chat_home.dart @@ -38,23 +38,23 @@ class _ChatHomeState extends State { data.clearAll(); } - void fetchAgain() { - print("Fetch Triggered"); - if (chatHubConnection.state != HubConnectionState.Connected) { - data.getUserAutoLoginToken().whenComplete(() async { - await data.buildHubConnection(); - data.getUserRecentChats(); - }); - return; - } - if (data.searchedChats == null || data.searchedChats!.isEmpty) { - data.getUserRecentChats(); - } - } + // void fetchAgain() { + // print("Fetch Triggered"); + // if (chatHubConnection.state != HubConnectionState.Connected) { + // data.getUserAutoLoginToken().whenComplete(() async { + // await data.buildHubConnection(); + // data.getUserRecentChats(); + // }); + // return; + // } + // if (data.searchedChats == null || data.searchedChats!.isEmpty) { + // data.getUserRecentChats(); + // } + // } @override Widget build(BuildContext context) { - fetchAgain(); + // fetchAgain(); return Scaffold( backgroundColor: MyColors.white, appBar: AppBarWidget(context, title: LocaleKeys.chat.tr(), showHomeButton: true), From 45b4adc2528986a5b59c7fbdd800f2fc381aa14d Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Tue, 13 Dec 2022 10:09:20 +0300 Subject: [PATCH 4/4] Fav Users Images Fix --- lib/provider/chat_provider_model.dart | 3 ++- lib/ui/chat/chat_bubble.dart | 3 +-- lib/ui/chat/chat_detailed_screen.dart | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index ca07b9b..3a4e70b 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -526,7 +526,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { await chatHubConnection.invoke("AddChatUserAsync", args: [json.decode(chatData)]); } - void sendChatMessage(int targetUserId, String targetUserName, BuildContext context) async { + void sendChatMessage(int targetUserId, int userStatus, String targetUserName, BuildContext context) async { dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId); if (contain.isEmpty) { searchedChats!.add( @@ -539,6 +539,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { isImageLoaded: true, isTyping: false, isFav: false, + userStatus: userStatus, userLocalDownlaodedImage: null, ), ); diff --git a/lib/ui/chat/chat_bubble.dart b/lib/ui/chat/chat_bubble.dart index 288a13f..c79c66b 100644 --- a/lib/ui/chat/chat_bubble.dart +++ b/lib/ui/chat/chat_bubble.dart @@ -54,11 +54,10 @@ class ChatBubble extends StatelessWidget { screenOffset = Offset(windowSize.width / 2, windowSize.height / 2); makeAssign(); data = Provider.of(context, listen: false); - return isCurrentUser ? currentUser(context) : receiptUser(context); } - Widget currentUser(context) { + Widget currentUser(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/ui/chat/chat_detailed_screen.dart b/lib/ui/chat/chat_detailed_screen.dart index 15b2156..05e674a 100644 --- a/lib/ui/chat/chat_detailed_screen.dart +++ b/lib/ui/chat/chat_detailed_screen.dart @@ -223,7 +223,7 @@ class _ChatDetailScreenState extends State { ), ).paddingOnly(right: 25), SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26).onPress( - () => m.sendChatMessage(params!.chatUser!.id!, params!.chatUser!.userName!, context), + () => m.sendChatMessage(params!.chatUser!.id!, params!.chatUser!.userStatus ?? 0, params!.chatUser!.userName!, context), ), ], ), @@ -239,7 +239,6 @@ class _ChatDetailScreenState extends State { } Widget showReplyImage(List data, ChatProviderModel m) { - logger.d(jsonEncode(data)); if (data.first.isImageLoaded! && data.first.image != null) { return Container( width: 43,