|
|
|
|
@ -54,7 +54,7 @@ import 'model/get_single_user_chat_list_model.dart';
|
|
|
|
|
import 'model/user_chat_history_model.dart';
|
|
|
|
|
// import 'get_single_user_chat_list_model.dart';
|
|
|
|
|
|
|
|
|
|
late HubConnection chatHubConnection;
|
|
|
|
|
HubConnection? chatHubConnection;
|
|
|
|
|
|
|
|
|
|
class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
bool isTyping = false;
|
|
|
|
|
@ -83,6 +83,9 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
int? referenceID;
|
|
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
|
chatHubConnection?.stop().then((value) {
|
|
|
|
|
chatHubConnection = null;
|
|
|
|
|
});
|
|
|
|
|
chatLoginTokenLoading = false;
|
|
|
|
|
chatParticipantLoading = false;
|
|
|
|
|
userChatHistoryLoading = false;
|
|
|
|
|
@ -108,11 +111,13 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Future<void> getUserAutoLoginTokenSilent(int moduleId, int requestId, String title, String myId, String assigneeEmployeeNumber) async {
|
|
|
|
|
Future<void> getUserAutoLoginTokenSilent(int moduleId, int requestId, String title, String myId, String assigneeEmployeeNumber, {bool isMounted = true}) async {
|
|
|
|
|
reset();
|
|
|
|
|
receiverID = assigneeEmployeeNumber;
|
|
|
|
|
chatLoginTokenLoading = true;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (isMounted) {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
chatLoginResponse = await ChatApiClient().getChatLoginToken(moduleId, requestId, title, myId, assigneeEmployeeNumber);
|
|
|
|
|
chatParticipantModel = await ChatApiClient().loadParticipants(moduleId, requestId, assigneeEmployeeNumber);
|
|
|
|
|
@ -122,7 +127,9 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
print(ex);
|
|
|
|
|
}
|
|
|
|
|
chatLoginTokenLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (isMounted) {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Future<void> getUserLoadChatHistory(int moduleId, int requestId, String myId, String assigneeEmployeeNumber) async {
|
|
|
|
|
@ -146,17 +153,24 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
// } catch (e) {}
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Future<void> connectToHub(int moduleId, int requestId, String myId, String assigneeEmployeeNumber) async {
|
|
|
|
|
Future<void> connectToHub(int moduleId, int requestId, String myId, String assigneeEmployeeNumber, bool readOnly, {bool isMounted = true}) async {
|
|
|
|
|
userChatHistoryLoading = true;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (isMounted) {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
moduleID = moduleId;
|
|
|
|
|
referenceID = requestId;
|
|
|
|
|
await buildHubConnection(chatParticipantModel!.id!.toString());
|
|
|
|
|
if (!readOnly) {
|
|
|
|
|
await buildHubConnection(chatParticipantModel!.id!.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userChatHistory = await ChatApiClient().loadChatHistory(moduleId, requestId, myId, assigneeEmployeeNumber);
|
|
|
|
|
chatResponseList = userChatHistory ?? [];
|
|
|
|
|
chatResponseList.sort((a, b) => b.createdDate!.compareTo(a.createdDate!));
|
|
|
|
|
userChatHistoryLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
if (isMounted) {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Future<void> loadChatHistory(int moduleId, int requestId, String myId, String assigneeEmployeeNumber) async {
|
|
|
|
|
@ -174,7 +188,7 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
notifyListeners();
|
|
|
|
|
bool returnStatus = false;
|
|
|
|
|
try {
|
|
|
|
|
await chatHubConnection.invoke("AddChatUserAsync", args: <Object>[object]);
|
|
|
|
|
await chatHubConnection!.invoke("AddChatUserAsync", args: <Object>[object]);
|
|
|
|
|
returnStatus = true;
|
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
|
|
@ -223,17 +237,17 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
Future<void> buildHubConnection(String conversationID) async {
|
|
|
|
|
chatHubConnection = await getHubConnection();
|
|
|
|
|
await chatHubConnection.start();
|
|
|
|
|
await chatHubConnection!.start();
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
print("Hub Conn: Startedddddddd");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await chatHubConnection.invoke("JoinConversation", args: [conversationID]);
|
|
|
|
|
chatHubConnection.on("ReceiveMessage", onMsgReceived1);
|
|
|
|
|
chatHubConnection.on("OnMessageReceivedAsync", onMsgReceived);
|
|
|
|
|
chatHubConnection.on("OnSubmitChatAsync", OnSubmitChatAsync);
|
|
|
|
|
chatHubConnection.on("OnTypingAsync", OnTypingAsync);
|
|
|
|
|
chatHubConnection.on("OnStopTypingAsync", OnStopTypingAsync);
|
|
|
|
|
await chatHubConnection!.invoke("JoinConversation", args: [conversationID]);
|
|
|
|
|
chatHubConnection!.on("ReceiveMessage", onMsgReceived1);
|
|
|
|
|
chatHubConnection!.on("OnMessageReceivedAsync", onMsgReceived);
|
|
|
|
|
chatHubConnection!.on("OnSubmitChatAsync", OnSubmitChatAsync);
|
|
|
|
|
chatHubConnection!.on("OnTypingAsync", OnTypingAsync);
|
|
|
|
|
chatHubConnection!.on("OnStopTypingAsync", OnStopTypingAsync);
|
|
|
|
|
|
|
|
|
|
//group On message
|
|
|
|
|
|
|
|
|
|
@ -255,7 +269,7 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
// chatHubConnection.on("OnSubmitChatAsync", OnSubmitChatAsync);
|
|
|
|
|
// chatHubConnection.on("OnUserTypingAsync", onUserTyping);
|
|
|
|
|
chatHubConnection.on("OnUserCountAsync", userCountAsync);
|
|
|
|
|
chatHubConnection?.on("OnUserCountAsync", userCountAsync);
|
|
|
|
|
// chatHubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
|
|
|
|
|
// chatHubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
|
|
|
|
|
// chatHubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
|
|
|
|
|
@ -298,7 +312,7 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Future invokeUserChatHistoryNotDeliveredAsync({required int userId}) async {
|
|
|
|
|
await chatHubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]);
|
|
|
|
|
await chatHubConnection!.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -361,7 +375,7 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void updateUserChatHistoryStatusAsync(List data) {
|
|
|
|
|
try {
|
|
|
|
|
chatHubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
|
|
|
|
|
chatHubConnection!.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
@ -369,7 +383,7 @@ class ChatProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void updateUserChatHistoryOnMsg(List data) {
|
|
|
|
|
try {
|
|
|
|
|
chatHubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
|
|
|
|
|
chatHubConnection!.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
@ -1766,12 +1780,12 @@ void setMsgTune() async {
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Future invokeChatCounter({required int userId}) async {
|
|
|
|
|
await chatHubConnection.invoke("GetChatCounversationCount", args: [userId]);
|
|
|
|
|
await chatHubConnection!.invoke("GetChatCounversationCount", args: [userId]);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void userTypingInvoke({required int currentUser, required int reciptUser}) async {
|
|
|
|
|
await chatHubConnection.invoke("UserTypingAsync", args: [reciptUser, currentUser]);
|
|
|
|
|
await chatHubConnection!.invoke("UserTypingAsync", args: [reciptUser, currentUser]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// void groupTypingInvoke({required GroupResponse groupDetails, required int groupId}) async {
|
|
|
|
|
|