|
|
|
@ -51,10 +51,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> buildHubConnection() async {
|
|
|
|
|
hubConnection = await getHubConnection();
|
|
|
|
|
await hubConnection.start()!.then((value) {
|
|
|
|
|
print('-----------------------Hub Started For Chat------------------');
|
|
|
|
|
});
|
|
|
|
|
chatHubConnection = await getHubConnection();
|
|
|
|
|
await chatHubConnection.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<HubConnection> getHubConnection() async {
|
|
|
|
@ -75,18 +73,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void registerEvents() {
|
|
|
|
|
hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
|
|
|
|
|
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
|
|
|
|
|
chatHubConnection.on("OnUpdateUserStatusAsync", changeStatus);
|
|
|
|
|
chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
|
|
|
|
|
// hubConnection.on("OnSeenChatUserAsync", onChatSeen);
|
|
|
|
|
//hubConnection.on("OnUserTypingAsync", onUserTyping);
|
|
|
|
|
hubConnection.on("OnUserCountAsync", userCountAsync);
|
|
|
|
|
chatHubConnection.on("OnUserCountAsync", userCountAsync);
|
|
|
|
|
// hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
|
|
|
|
|
hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
|
|
|
|
|
hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
|
|
|
|
|
chatHubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
|
|
|
|
|
chatHubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getUserRecentChats() async {
|
|
|
|
|
if (hubConnection.state != HubConnectionState.Connected) {
|
|
|
|
|
if (chatHubConnection.state != HubConnectionState.Connected) {
|
|
|
|
|
getUserAutoLoginToken().whenComplete(() async {
|
|
|
|
|
await buildHubConnection();
|
|
|
|
|
getUserRecentChats();
|
|
|
|
@ -127,7 +125,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future invokeUserChatHistoryNotDeliveredAsync({required int userId}) async {
|
|
|
|
|
await hubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]);
|
|
|
|
|
await chatHubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -194,7 +192,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void updateUserChatHistoryStatusAsync(List data) {
|
|
|
|
|
try {
|
|
|
|
|
hubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
|
|
|
|
|
chatHubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
@ -202,7 +200,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void updateUserChatHistoryOnMsg(List data) {
|
|
|
|
|
try {
|
|
|
|
|
hubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
|
|
|
|
|
chatHubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
@ -486,7 +484,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
String chatData =
|
|
|
|
|
'{"contant":"$msg","contantNo":"$contentNo","chatEventId":$chatEventId,"fileTypeId": $fileTypeId,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"chatReplyId":$chatReplyId,"conversationId":"$chatCID"}';
|
|
|
|
|
await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
|
|
|
|
|
await chatHubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sendChatMessage(int targetUserId, String targetUserName, BuildContext context) async {
|
|
|
|
|