From 76169e5cb883f81e708ffcf46c18478723a06fd6 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Mon, 21 Nov 2022 09:53:27 +0300 Subject: [PATCH] Chat Updates & Counter Event Modifications --- lib/api/chat/chat_provider_model.dart | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/api/chat/chat_provider_model.dart b/lib/api/chat/chat_provider_model.dart index 868aa7a..83827c3 100644 --- a/lib/api/chat/chat_provider_model.dart +++ b/lib/api/chat/chat_provider_model.dart @@ -87,11 +87,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { token: AppState().chatDetails!.response!.token, ); ChatUserModel favUList = userToList(favRes.body); - GetUserChatHistoryNotDeliveredAsync( - userId: int.parse( - AppState().chatDetails!.response!.id.toString(), - ), - ); + if (favUList.response != null && recentChat.response != null) { favUsersList = favUList.response!; favUsersList.sort( @@ -119,7 +115,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { notifyListeners(); } - Future GetUserChatHistoryNotDeliveredAsync({required int userId}) async { + Future getUserChatHistoryNotDeliveredAsync({required int userId}) async { await hubConnection.invoke( "GetUserChatHistoryNotDeliveredAsync", args: [userId], @@ -157,7 +153,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { ).reversed.toList(); } } - await GetUserChatHistoryNotDeliveredAsync( + await getUserChatHistoryNotDeliveredAsync( userId: senderUID, ); isLoading = false; @@ -274,6 +270,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { ); if (hubConnection.state != HubConnectionState.Connected) { await hubConnection.start(); + getUserChatHistoryNotDeliveredAsync( + userId: int.parse( + AppState().chatDetails!.response!.id.toString(), + ), + ); hubConnection.on("OnUpdateUserStatusAsync", changeStatus); hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); // hubConnection.on("OnSeenChatUserAsync", onChatSeen); @@ -565,14 +566,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } if (isFileSelected && !isMsgReply) { Utils.showLoading(context); - logger.d("Normal Attachment Message"); + //logger.d("Normal Attachment Message"); dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); String? ext = getFileExtension(selectedFile.path); Utils.hideLoading(context); sendChatToServer(chatEventId: 2, fileTypeId: getFileType(ext.toString()), targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: true, chatReplyId: null, isReply: false); } if (!isFileSelected && isMsgReply) { - logger.d("Normal Text Message With Reply"); + // logger.d("Normal Text Message With Reply"); if (message.text == null || message.text.isEmpty) { return; } @@ -580,7 +581,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, chatReplyId: repliedMsg.first.userChatHistoryId, isAttachment: false, isReply: true); } if (isFileSelected && isMsgReply) { - logger.d("Attachment Message With Reply"); + // logger.d("Attachment Message With Reply"); Utils.showLoading(context); dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); String? ext = getFileExtension(selectedFile.path);