|
|
|
@ -68,7 +68,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
Future<void> buildHubConnection() async {
|
|
|
|
|
chatHubConnection = await getHubConnection();
|
|
|
|
|
await chatHubConnection.start();
|
|
|
|
|
print("Startedddddddd");
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
logger.i("Hub Conn: Startedddddddd");
|
|
|
|
|
}
|
|
|
|
|
chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
|
|
|
|
|
chatHubConnection.on("OnGetChatConversationCount", onNewChatConversion);
|
|
|
|
|
}
|
|
|
|
@ -91,7 +93,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
// chatHubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
|
|
|
|
|
chatHubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
|
|
|
|
|
chatHubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
|
|
|
|
|
print("Alll Registered");
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
logger.i("All listeners registered");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getUserRecentChats() async {
|
|
|
|
@ -279,7 +283,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void updateChatHistoryWindow(List<Object?>? args) {
|
|
|
|
|
dynamic items = args!.toList();
|
|
|
|
|
print("---------------------------------Update Chat History Windows Async -------------------------------------");
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
logger.i("---------------------------------Update Chat History Windows Async -------------------------------------");
|
|
|
|
|
}
|
|
|
|
|
logger.d(items);
|
|
|
|
|
// for (var user in searchedChats!) {
|
|
|
|
|
// if (user.id == items.first["id"]) {
|
|
|
|
@ -404,7 +410,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnSubmitChatAsync(List<Object?>? parameters) {
|
|
|
|
|
logger.d(parameters);
|
|
|
|
|
logger.i(parameters);
|
|
|
|
|
List<SingleUserChatModel> data = [], temp = [];
|
|
|
|
|
for (dynamic msg in parameters!) {
|
|
|
|
|
data = getSingleUserChatModel(jsonEncode(msg));
|
|
|
|
@ -563,8 +569,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
isImageLoaded: isImageLoaded,
|
|
|
|
|
voice: voice,
|
|
|
|
|
);
|
|
|
|
|
print("Model data---------------------------");
|
|
|
|
|
logger.d(data.toJson());
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
logger.i("model data: " + jsonEncode(data));
|
|
|
|
|
}
|
|
|
|
|
userChatHistory.insert(0, data);
|
|
|
|
|
isFileSelected = false;
|
|
|
|
|
isMsgReply = false;
|
|
|
|
@ -579,16 +586,19 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void sendChatMessage(BuildContext context, {required int targetUserId, required int userStatus, required String userEmail, required String targetUserName}) async {
|
|
|
|
|
if (!isFileSelected && !isMsgReply) {
|
|
|
|
|
print("Normal Text Msg");
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
print("Normal Text Msg");
|
|
|
|
|
}
|
|
|
|
|
if (message.text == null || message.text.isEmpty) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sendChatToServer(
|
|
|
|
|
chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: false, chatReplyId: null, isReply: false, isImageLoaded: false, image: null);
|
|
|
|
|
} // normal Text msg
|
|
|
|
|
}
|
|
|
|
|
if (isFileSelected && !isMsgReply) {
|
|
|
|
|
bool isImage = false;
|
|
|
|
|
print("Normal Attachment Msg");
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
logger.i("Normal Attachment Msg");
|
|
|
|
|
}
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile);
|
|
|
|
|
String? ext = getFileExtension(selectedFile.path);
|
|
|
|
@ -623,7 +633,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
image: repliedMsg.first.image);
|
|
|
|
|
} // reply msg over image && normal
|
|
|
|
|
if (isFileSelected && isMsgReply) {
|
|
|
|
|
print("Reply With File");
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
print("Reply With File");
|
|
|
|
|
}
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile);
|
|
|
|
|
String? ext = getFileExtension(selectedFile.path);
|
|
|
|
@ -711,7 +723,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
String? getFileExtension(String fileName) {
|
|
|
|
|
try {
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
print("ext: " + "." + fileName.split('.').last);
|
|
|
|
|
logger.i("ext: " + "." + fileName.split('.').last);
|
|
|
|
|
}
|
|
|
|
|
return "." + fileName.split('.').last;
|
|
|
|
|
} catch (e) {
|
|
|
|
@ -836,7 +848,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearAll() {
|
|
|
|
|
print("----------------- Disposed ---------------------------");
|
|
|
|
|
searchedChats = pChatHistory;
|
|
|
|
|
search.clear();
|
|
|
|
|
isChatScreenActive = false;
|
|
|
|
@ -1050,9 +1061,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
startRecoding();
|
|
|
|
|
} else {
|
|
|
|
|
recorderController.reset();
|
|
|
|
|
logger.d(recorderController.isRecording);
|
|
|
|
|
await recorderController.record(path);
|
|
|
|
|
logger.d(recorderController.isRecording);
|
|
|
|
|
_recodeDuration = 0;
|
|
|
|
|
_startTimer();
|
|
|
|
|
isRecoding = !isRecoding;
|
|
|
|
@ -1142,7 +1151,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
path = await recorderController.stop(false);
|
|
|
|
|
}
|
|
|
|
|
if (kDebugMode) {
|
|
|
|
|
print(path);
|
|
|
|
|
logger.i("path:" + path!);
|
|
|
|
|
}
|
|
|
|
|
File voiceFile = File(path!);
|
|
|
|
|
voiceFile.readAsBytesSync();
|
|
|
|
@ -1152,9 +1161,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
isRecoding = false;
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), voiceFile);
|
|
|
|
|
logger.d(value);
|
|
|
|
|
String? ext = getFileExtension(voiceFile.path);
|
|
|
|
|
logger.d(voiceFile.path!.split("/").last);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
sendVoiceMessageToServer(
|
|
|
|
|
msgText: voiceFile.path!.split("/").last,
|
|
|
|
@ -1168,7 +1175,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
userStatus: userStatus,
|
|
|
|
|
chatReplyId: null,
|
|
|
|
|
isAttachment: true,
|
|
|
|
|
isReply: false,
|
|
|
|
|
isReply: isMsgReply,
|
|
|
|
|
voicFile: voiceFile,
|
|
|
|
|
);
|
|
|
|
|
notifyListeners();
|
|
|
|
@ -1278,7 +1285,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
Uint8List encodedString = await ChatApiClient().downloadURL(fileName: data.contant!, fileTypeDescription: getFileTypeDescription(data.fileTypeResponse!.fileTypeName ?? ""));
|
|
|
|
|
try {
|
|
|
|
|
String path = await downChatVoice(encodedString, data.fileTypeResponse!.fileTypeName ?? "", data);
|
|
|
|
|
logger.d(path);
|
|
|
|
|
File file = File(path!);
|
|
|
|
|
file.readAsBytesSync();
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|