diff --git a/lib/api/chat/chat_provider_model.dart b/lib/api/chat/chat_provider_model.dart index d5abd79..bcb748c 100644 --- a/lib/api/chat/chat_provider_model.dart +++ b/lib/api/chat/chat_provider_model.dart @@ -91,18 +91,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { .build(); hubConnection.onclose( ({Exception? error}) { - logger.d(error); + // logger.d(error); }, ); hubConnection.onreconnecting( ({Exception? error}) { - logger.d(error); - logger.d("Reconnecting"); + // logger.d(error); + // logger.d("Reconnecting"); }, ); hubConnection.onreconnected( ({String? connectionId}) { - logger.d("Reconnected"); + // logger.d("Reconnected"); }, ); if (hubConnection.state != HubConnectionState.Connected) { @@ -110,23 +110,39 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { hubConnection.on("OnUpdateUserStatusAsync", changeStatus); hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); - // hubConnection.on("OnUserTypingAsync", onUserTyping); + hubConnection.on("OnUserTypingAsync", onUserTyping); // hubConnection.on("OnUserCountAsync", userCountAsync); // hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); // hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); + hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus); } else { hubConnection.on("OnUpdateUserStatusAsync", changeStatus); hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); - // hubConnection.on("OnUserTypingAsync", onUserTyping); + hubConnection.on("OnUserTypingAsync", onUserTyping); // hubConnection.on("OnUserCountAsync", userCountAsync); // hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); // hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); + hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus); } isLoading = false; notifyListeners(); } + void updateUserChatStatus(List? args) { + dynamic items = args!.toList(); + for (dynamic cItem in items[0]) { + for (SingleUserChatModel chat in userChatHistory) { + if (chat.userChatHistoryId.toString() == cItem["userChatHistoryId"].toString()) { + logger.d(jsonEncode(chat)); + chat.isSeen = cItem["isSeen"]; + chat.isDelivered = cItem["isDelivered"]; + notifyListeners(); + } + } + } + } + void userCountAsync(List? args) { List items = args!.toList(); print("---------------------------------User Count Async -------------------------------------"); @@ -166,7 +182,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void changeStatus(List? args) { // print("================= Status Online // Offline ===================="); List items = args!.toList(); - logger.d(items); + // logger.d(items); for (ChatUser user in searchedChats!) { if (user.id == items.first["id"]) { user.userStatus = items.first["userStatus"]; @@ -192,9 +208,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { Future onMsgReceived(List? parameters) async { List data = []; + List temp = []; for (dynamic msg in parameters!) { data = getSingleUserChatModel(jsonEncode(msg)); - logger.d(msg); + temp = getSingleUserChatModel(jsonEncode(msg)); + data.first.targetUserId = temp.first.currentUserId; + data.first.targetUserName = temp.first.currentUserName; + data.first.currentUserId = temp.first.targetUserId; + data.first.currentUserName = temp.first.targetUserName; } userChatHistory.add(data.first); notifyListeners(); @@ -207,11 +228,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { for (ChatUser user in searchedChats!) { if (user.id == parameters![1] && parameters[0] == true) { user.isTyping = parameters[0] as bool?; - } else { + Future.delayed( - const Duration(milliseconds: 500), + const Duration(seconds: 2), () { user.isTyping = false; + notifyListeners(); }, ); } diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index e82c30a..3fd992f 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -1,7 +1,7 @@ class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server - static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server - // static String baseUrl = "https://hmgwebservices.com"; // Live server + //static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server + static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrlServices = baseUrl + "/Services/"; // server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; diff --git a/lib/ui/chat/chat_detailed_screen.dart b/lib/ui/chat/chat_detailed_screen.dart index 1a9cf7d..5f2fa97 100644 --- a/lib/ui/chat/chat_detailed_screen.dart +++ b/lib/ui/chat/chat_detailed_screen.dart @@ -43,6 +43,7 @@ class ChatDetailScreen extends StatelessWidget { itemCount: m.userChatHistory.length, padding: const EdgeInsets.symmetric(vertical: 10), itemBuilder: (BuildContext context, int i) { + i == 0 ? m.logger.d(m.userChatHistory.length) : ""; return ChatBubble( text: m.userChatHistory[i].contant.toString(), isSeen: m.userChatHistory[i].isSeen == true ? true : false, diff --git a/lib/ui/chat/chat_home.dart b/lib/ui/chat/chat_home.dart index 5d6d065..b8696ae 100644 --- a/lib/ui/chat/chat_home.dart +++ b/lib/ui/chat/chat_home.dart @@ -110,7 +110,7 @@ class _ChatHomeScreenState extends State { ], ), title: (m.searchedChats![index].userName ?? "").toText14(color: MyColors.darkTextColor), - subtitle: (m.searchedChats![index].isTyping == true ? "Something is Typing" : "Last message text").toText11(color: MyColors.normalTextColor), + subtitle: (m.searchedChats![index].isTyping == true ? "Typing ..." : "").toText11(color: MyColors.normalTextColor), trailing: ("Today").toText10(color: MyColors.lightTextColor), minVerticalPadding: 0, onTap: () {