|
|
|
@ -91,18 +91,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
hubConnection.onclose(
|
|
|
|
hubConnection.onclose(
|
|
|
|
({Exception? error}) {
|
|
|
|
({Exception? error}) {
|
|
|
|
logger.d(error);
|
|
|
|
// logger.d(error);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
hubConnection.onreconnecting(
|
|
|
|
hubConnection.onreconnecting(
|
|
|
|
({Exception? error}) {
|
|
|
|
({Exception? error}) {
|
|
|
|
logger.d(error);
|
|
|
|
// logger.d(error);
|
|
|
|
logger.d("Reconnecting");
|
|
|
|
// logger.d("Reconnecting");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
hubConnection.onreconnected(
|
|
|
|
hubConnection.onreconnected(
|
|
|
|
({String? connectionId}) {
|
|
|
|
({String? connectionId}) {
|
|
|
|
logger.d("Reconnected");
|
|
|
|
// logger.d("Reconnected");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
if (hubConnection.state != HubConnectionState.Connected) {
|
|
|
|
if (hubConnection.state != HubConnectionState.Connected) {
|
|
|
|
@ -110,23 +110,39 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
|
|
|
|
hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
|
|
|
|
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
|
|
|
|
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
|
|
|
|
|
|
|
|
|
|
|
|
// hubConnection.on("OnUserTypingAsync", onUserTyping);
|
|
|
|
hubConnection.on("OnUserTypingAsync", onUserTyping);
|
|
|
|
// hubConnection.on("OnUserCountAsync", userCountAsync);
|
|
|
|
// hubConnection.on("OnUserCountAsync", userCountAsync);
|
|
|
|
// hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
|
|
|
|
// hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
|
|
|
|
// hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
|
|
|
|
// hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
|
|
|
|
|
|
|
|
hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
|
|
|
|
hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
|
|
|
|
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
|
|
|
|
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
|
|
|
|
|
|
|
|
|
|
|
|
// hubConnection.on("OnUserTypingAsync", onUserTyping);
|
|
|
|
hubConnection.on("OnUserTypingAsync", onUserTyping);
|
|
|
|
// hubConnection.on("OnUserCountAsync", userCountAsync);
|
|
|
|
// hubConnection.on("OnUserCountAsync", userCountAsync);
|
|
|
|
// hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
|
|
|
|
// hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
|
|
|
|
// hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
|
|
|
|
// hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
|
|
|
|
|
|
|
|
hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isLoading = false;
|
|
|
|
isLoading = false;
|
|
|
|
notifyListeners();
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void updateUserChatStatus(List<Object?>? 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<Object?>? args) {
|
|
|
|
void userCountAsync(List<Object?>? args) {
|
|
|
|
List items = args!.toList();
|
|
|
|
List items = args!.toList();
|
|
|
|
print("---------------------------------User Count Async -------------------------------------");
|
|
|
|
print("---------------------------------User Count Async -------------------------------------");
|
|
|
|
@ -166,7 +182,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
void changeStatus(List<Object?>? args) {
|
|
|
|
void changeStatus(List<Object?>? args) {
|
|
|
|
// print("================= Status Online // Offline ====================");
|
|
|
|
// print("================= Status Online // Offline ====================");
|
|
|
|
List items = args!.toList();
|
|
|
|
List items = args!.toList();
|
|
|
|
logger.d(items);
|
|
|
|
// logger.d(items);
|
|
|
|
for (ChatUser user in searchedChats!) {
|
|
|
|
for (ChatUser user in searchedChats!) {
|
|
|
|
if (user.id == items.first["id"]) {
|
|
|
|
if (user.id == items.first["id"]) {
|
|
|
|
user.userStatus = items.first["userStatus"];
|
|
|
|
user.userStatus = items.first["userStatus"];
|
|
|
|
@ -192,9 +208,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> onMsgReceived(List<Object?>? parameters) async {
|
|
|
|
Future<void> onMsgReceived(List<Object?>? parameters) async {
|
|
|
|
List<SingleUserChatModel> data = [];
|
|
|
|
List<SingleUserChatModel> data = [];
|
|
|
|
|
|
|
|
List<SingleUserChatModel> temp = [];
|
|
|
|
for (dynamic msg in parameters!) {
|
|
|
|
for (dynamic msg in parameters!) {
|
|
|
|
data = getSingleUserChatModel(jsonEncode(msg));
|
|
|
|
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);
|
|
|
|
userChatHistory.add(data.first);
|
|
|
|
notifyListeners();
|
|
|
|
notifyListeners();
|
|
|
|
@ -207,11 +228,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
for (ChatUser user in searchedChats!) {
|
|
|
|
for (ChatUser user in searchedChats!) {
|
|
|
|
if (user.id == parameters![1] && parameters[0] == true) {
|
|
|
|
if (user.id == parameters![1] && parameters[0] == true) {
|
|
|
|
user.isTyping = parameters[0] as bool?;
|
|
|
|
user.isTyping = parameters[0] as bool?;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Future.delayed(
|
|
|
|
Future.delayed(
|
|
|
|
const Duration(milliseconds: 500),
|
|
|
|
const Duration(seconds: 2),
|
|
|
|
() {
|
|
|
|
() {
|
|
|
|
user.isTyping = false;
|
|
|
|
user.isTyping = false;
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -223,6 +245,17 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
if (chatMessage == null || chatMessage.isEmpty) {
|
|
|
|
if (chatMessage == null || chatMessage.isEmpty) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
|
|
|
|
|
|
|
|
if (contain.isEmpty) {
|
|
|
|
|
|
|
|
searchedChats!.add(
|
|
|
|
|
|
|
|
ChatUser(
|
|
|
|
|
|
|
|
id: targetUserId,
|
|
|
|
|
|
|
|
userName: targetUserName,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String chatData =
|
|
|
|
String chatData =
|
|
|
|
'{"contant":"$chatMessage","contantNo":"8a129295-36d7-7185-5d34-cc4eec7bcba4","chatEventId":1,"fileTypeId":null,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"conversationId":"715f8b13-96ee-cd36-cb07-5a982a219982"}';
|
|
|
|
'{"contant":"$chatMessage","contantNo":"8a129295-36d7-7185-5d34-cc4eec7bcba4","chatEventId":1,"fileTypeId":null,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"conversationId":"715f8b13-96ee-cd36-cb07-5a982a219982"}';
|
|
|
|
await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
|
|
|
|
await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
|
|
|
|
|