diff --git a/lib/api/chat/chat_provider_model.dart b/lib/api/chat/chat_provider_model.dart index cedc158..b336ace 100644 --- a/lib/api/chat/chat_provider_model.dart +++ b/lib/api/chat/chat_provider_model.dart @@ -109,7 +109,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { notifyListeners(); } - void getSingleUserChatHistory({required String senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false}) async { + Future GetUserChatHistoryNotDeliveredAsync(int userId) async { + await hubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]); + return ""; + } + + void getSingleUserChatHistory({required int senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false}) async { isLoading = true; if (isNewChat) userChatHistory = []; if (!loadMore) paginationVal = 0; @@ -134,9 +139,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } } isLoading = false; + await GetUserChatHistoryNotDeliveredAsync(senderUID); notifyListeners(); } + void updateUserChatHistoryStatusAsync(List data) { + hubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]); + } + List getSingleUserChatModel(String str) => List.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x))); ChatUserModel userToList(String str) => ChatUserModel.fromJson(json.decode(str)); @@ -170,7 +180,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { .withAutomaticReconnect( retryDelays: [2000, 5000, 10000, 20000], ) - .configureLogging(Logger("Loggin")) + .configureLogging( + Logger("Loggin"), + ) .build(); hubConnection.onclose( ({Exception? error}) {}, @@ -188,11 +200,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { // hubConnection.on("OnSeenChatUserAsync", onChatSeen); //hubConnection.on("OnUserTypingAsync", onUserTyping); - // hubConnection.on("OnUserCountAsync", userCountAsync); + hubConnection.on("OnUserCountAsync", userCountAsync); hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus); - } } @@ -223,6 +234,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void userCountAsync(List? args) { dynamic items = args!.toList(); + // logger.d(items); //logger.d("---------------------------------User Count Async -------------------------------------"); //logger.d(items); // for (var user in searchedChats!) { @@ -247,10 +259,17 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void chatNotDelivered(List? args) { dynamic items = args!.toList(); - if (kDebugMode) { - print("--------------------------------- Chat Not Delivered Windows Async -------------------------------------"); + for (dynamic item in items[0]) { + dynamic data = [ + { + "userChatHistoryId": item["userChatHistoryId"], + "TargetUserId": item["targetUserId"], + "isDelivered": true, + "isSeen": true, + } + ]; + updateUserChatHistoryStatusAsync(data); } - logger.d(items); // for (var user in searchedChats!) { // if (user.id == items.first["id"]) { // user.userStatus = items.first["userStatus"]; @@ -289,7 +308,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } Future onMsgReceived(List? parameters) async { - print("msg Received"); List data = []; List temp = []; for (dynamic msg in parameters!) { @@ -307,6 +325,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { // element.unreadMessageCount = val! + 1; // } // }); + logger.d(jsonEncode(data)); + + var list = [ + { + "userChatHistoryId": data.first.userChatHistoryId, + "TargetUserId": data.first.targetUserId, + "isDelivered": true, + "isSeen": isChatScreenActive ? true : false, + } + ]; + updateUserChatHistoryStatusAsync(list); + notifyListeners(); // if (isChatScreenActive) scrollToBottom(); } diff --git a/lib/ui/chat/chat_detailed_screen.dart b/lib/ui/chat/chat_detailed_screen.dart index 2ef61f0..71a95b5 100644 --- a/lib/ui/chat/chat_detailed_screen.dart +++ b/lib/ui/chat/chat_detailed_screen.dart @@ -36,7 +36,7 @@ class _ChatDetailScreenState extends State { data.paginationVal = data.paginationVal + 10; if (userDetails != null) data.getSingleUserChatHistory( - senderUID: AppState().chatDetails!.response!.id.toString(), + senderUID: AppState().chatDetails!.response!.id!.toInt(), receiverUID: userDetails["targetUser"].id, loadMore: true, isNewChat: false, @@ -56,11 +56,12 @@ class _ChatDetailScreenState extends State { data = Provider.of(context, listen: false); if (userDetails != null) data.getSingleUserChatHistory( - senderUID: AppState().chatDetails!.response!.id.toString(), + senderUID: AppState().chatDetails!.response!.id!.toInt(), receiverUID: userDetails["targetUser"].id, loadMore: false, isNewChat: userDetails["isNewChat"], ); + return Scaffold( backgroundColor: const Color(0xFFF8F8F8), appBar: AppBarWidget(context,