|
|
|
|
@ -48,7 +48,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
bool currentUserTyping = false;
|
|
|
|
|
int? cTypingUserId = 0;
|
|
|
|
|
|
|
|
|
|
//Chat
|
|
|
|
|
//Chat Home Page Counter
|
|
|
|
|
int chatUConvCounter = 0;
|
|
|
|
|
|
|
|
|
|
Future<void> getUserAutoLoginToken() async {
|
|
|
|
|
@ -291,14 +291,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
void chatNotDelivered(List<Object?>? args) {
|
|
|
|
|
dynamic items = args!.toList();
|
|
|
|
|
for (dynamic item in items[0]) {
|
|
|
|
|
searchedChats!.forEach(
|
|
|
|
|
(ChatUser element) {
|
|
|
|
|
if (element.id == item["currentUserId"]) {
|
|
|
|
|
int? val = element.unreadMessageCount ?? 0;
|
|
|
|
|
element.unreadMessageCount = val! + 1;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
for (ChatUser element in searchedChats!) {
|
|
|
|
|
if (element.id == item["currentUserId"]) {
|
|
|
|
|
int? val = element.unreadMessageCount ?? 0;
|
|
|
|
|
element.unreadMessageCount = val! + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
@ -378,20 +376,25 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
setMsgTune();
|
|
|
|
|
if (isChatScreenActive && data.first.currentUserId == receiverID) {
|
|
|
|
|
userChatHistory.insert(0, data.first);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (searchedChats != null) {
|
|
|
|
|
for (ChatUser user in searchedChats!) {
|
|
|
|
|
if (user.id == data.first.currentUserId) {
|
|
|
|
|
int tempCount = user.unreadMessageCount ?? 0;
|
|
|
|
|
user.unreadMessageCount = tempCount + 1;
|
|
|
|
|
} else {
|
|
|
|
|
if (searchedChats != null) {
|
|
|
|
|
for (ChatUser user in searchedChats!) {
|
|
|
|
|
if (user.id == data.first.currentUserId) {
|
|
|
|
|
int tempCount = user.unreadMessageCount ?? 0;
|
|
|
|
|
user.unreadMessageCount = tempCount + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sort();
|
|
|
|
|
}
|
|
|
|
|
sort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List list = [
|
|
|
|
|
{"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive && data.first.currentUserId == receiverID ? true : false}
|
|
|
|
|
List<Object> list = [
|
|
|
|
|
{
|
|
|
|
|
"userChatHistoryId": data.first.userChatHistoryId,
|
|
|
|
|
"TargetUserId": temp.first.targetUserId,
|
|
|
|
|
"isDelivered": true,
|
|
|
|
|
"isSeen": isChatScreenActive && data.first.currentUserId == receiverID ? true : false
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
updateUserChatHistoryOnMsg(list);
|
|
|
|
|
invokeChatCounter(userId: AppState().chatDetails!.response!.id!);
|
|
|
|
|
@ -400,9 +403,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void sort() {
|
|
|
|
|
searchedChats!.sort(
|
|
|
|
|
(ChatUser a, ChatUser b) => b.unreadMessageCount!.compareTo(
|
|
|
|
|
a.unreadMessageCount!,
|
|
|
|
|
),
|
|
|
|
|
(ChatUser a, ChatUser b) => b.unreadMessageCount!.compareTo(a.unreadMessageCount!),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -540,28 +541,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sendChatMessage(BuildContext context, {required int targetUserId, required int userStatus, required String userEmail, required String targetUserName}) async {
|
|
|
|
|
dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
|
|
|
|
|
if (contain.isEmpty) {
|
|
|
|
|
List<String> emails = [];
|
|
|
|
|
emails.add(await EmailImageEncryption().encrypt(val: userEmail));
|
|
|
|
|
List<ChatUserImageModel> chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails);
|
|
|
|
|
searchedChats!.add(
|
|
|
|
|
ChatUser(
|
|
|
|
|
id: targetUserId,
|
|
|
|
|
userName: targetUserName,
|
|
|
|
|
unreadMessageCount: 0,
|
|
|
|
|
email: userEmail,
|
|
|
|
|
isImageLoading: false,
|
|
|
|
|
image: chatImages.first.profilePicture ?? "",
|
|
|
|
|
isImageLoaded: true,
|
|
|
|
|
isTyping: false,
|
|
|
|
|
isFav: false,
|
|
|
|
|
userStatus: userStatus,
|
|
|
|
|
userLocalDownlaodedImage: await downloadImageLocal(chatImages.first.profilePicture, targetUserId.toString()),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
if (!isFileSelected && !isMsgReply) {
|
|
|
|
|
print("Normal Text Msg");
|
|
|
|
|
if (message.text == null || message.text.isEmpty) {
|
|
|
|
|
@ -621,6 +600,51 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
isImageLoaded: true,
|
|
|
|
|
image: selectedFile.readAsBytesSync());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (searchedChats != null) {
|
|
|
|
|
dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
|
|
|
|
|
if (contain.isEmpty) {
|
|
|
|
|
List<String> emails = [];
|
|
|
|
|
emails.add(await EmailImageEncryption().encrypt(val: userEmail));
|
|
|
|
|
List<ChatUserImageModel> chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails);
|
|
|
|
|
searchedChats!.add(
|
|
|
|
|
ChatUser(
|
|
|
|
|
id: targetUserId,
|
|
|
|
|
userName: targetUserName,
|
|
|
|
|
unreadMessageCount: 0,
|
|
|
|
|
email: userEmail,
|
|
|
|
|
isImageLoading: false,
|
|
|
|
|
image: chatImages.first.profilePicture ?? "",
|
|
|
|
|
isImageLoaded: true,
|
|
|
|
|
isTyping: false,
|
|
|
|
|
isFav: false,
|
|
|
|
|
userStatus: userStatus,
|
|
|
|
|
userLocalDownlaodedImage: await downloadImageLocal(chatImages.first.profilePicture, targetUserId.toString()),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
List<String> emails = [];
|
|
|
|
|
emails.add(await EmailImageEncryption().encrypt(val: userEmail));
|
|
|
|
|
List<ChatUserImageModel> chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails);
|
|
|
|
|
searchedChats!.add(
|
|
|
|
|
ChatUser(
|
|
|
|
|
id: targetUserId,
|
|
|
|
|
userName: targetUserName,
|
|
|
|
|
unreadMessageCount: 0,
|
|
|
|
|
email: userEmail,
|
|
|
|
|
isImageLoading: false,
|
|
|
|
|
image: chatImages.first.profilePicture ?? "",
|
|
|
|
|
isImageLoaded: true,
|
|
|
|
|
isTyping: false,
|
|
|
|
|
isFav: false,
|
|
|
|
|
userStatus: userStatus,
|
|
|
|
|
userLocalDownlaodedImage: await downloadImageLocal(chatImages.first.profilePicture, targetUserId.toString()),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void selectImageToUpload(BuildContext context) {
|
|
|
|
|
@ -725,7 +749,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
for (ChatUser user in searchedChats!) {
|
|
|
|
|
if (user.id == favoriteChatUser.response!.targetUserId!) {
|
|
|
|
|
user.isFav = favoriteChatUser.response!.isFav;
|
|
|
|
|
favUsersList.add(user);
|
|
|
|
|
dynamic contain = favUsersList!.where((ChatUser element) => element.id == favoriteChatUser.response!.targetUserId!);
|
|
|
|
|
if (contain.isEmpty) {
|
|
|
|
|
favUsersList.add(user);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -764,6 +791,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clearAll() {
|
|
|
|
|
print("----------------- Disposed ---------------------------");
|
|
|
|
|
searchedChats = pChatHistory;
|
|
|
|
|
search.clear();
|
|
|
|
|
isChatScreenActive = false;
|
|
|
|
|
@ -775,6 +803,37 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
sFileType = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void disposeData() {
|
|
|
|
|
search.clear();
|
|
|
|
|
isChatScreenActive = false;
|
|
|
|
|
receiverID = 0;
|
|
|
|
|
paginationVal = 0;
|
|
|
|
|
message.text = '';
|
|
|
|
|
isFileSelected = false;
|
|
|
|
|
repliedMsg = [];
|
|
|
|
|
sFileType = "";
|
|
|
|
|
deleteData();
|
|
|
|
|
favUsersList.clear();
|
|
|
|
|
searchedChats!.clear();
|
|
|
|
|
pChatHistory!.clear();
|
|
|
|
|
chatHubConnection.stop();
|
|
|
|
|
AppState().chatDetails = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deleteData() {
|
|
|
|
|
List<ChatUser> exists = [], unique = [];
|
|
|
|
|
exists.addAll(searchedChats!);
|
|
|
|
|
exists.addAll(favUsersList!);
|
|
|
|
|
Map<String, ChatUser> profileMap = {};
|
|
|
|
|
for (ChatUser item in exists) {
|
|
|
|
|
profileMap[item.email!] = item;
|
|
|
|
|
}
|
|
|
|
|
unique = profileMap.values.toList();
|
|
|
|
|
for (ChatUser element in unique!) {
|
|
|
|
|
deleteFile(element.id.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getUserImages() async {
|
|
|
|
|
List<String> emails = [];
|
|
|
|
|
List<ChatUser> exists = [], unique = [];
|
|
|
|
|
@ -885,4 +944,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
await chatHubConnection.invoke("GetChatCounversationCount", args: [userId]);
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void userTypingInvoke({required int currentUser, required int reciptUser}) async {
|
|
|
|
|
logger.d([reciptUser, currentUser]);
|
|
|
|
|
await chatHubConnection.invoke("UserTypingAsync", args: [reciptUser, currentUser]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|