diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index d3639c9..3a4e70b 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -125,8 +125,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { AppState().chatDetails!.response!.id.toString(), ), ); + sort(); notifyListeners(); - if (searchedChats!.isNotEmpty) { + if (searchedChats!.isNotEmpty || favUsersList.isNotEmpty) { getUserImages(); } } @@ -141,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 { @@ -533,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( @@ -546,6 +539,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { isImageLoaded: true, isTyping: false, isFav: false, + userStatus: userStatus, userLocalDownlaodedImage: null, ), ); @@ -764,9 +758,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) { @@ -847,7 +850,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/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, 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), diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index 15fc795..2d7de09 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!); + }); }); }