|
|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
@ -390,8 +388,13 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
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) {
|
|
|
|
|
|