Merge branch 'development_aamir' into 'master'

Multiple Chat Issue

See merge request Cloud_Solution/mohemm-flutter-app!108
merge-requests/110/merge
haroon amjad 3 years ago
commit dafa075e4c

@ -48,7 +48,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
bool currentUserTyping = false; bool currentUserTyping = false;
int? cTypingUserId = 0; int? cTypingUserId = 0;
//Chat //Chat Home Page Counter
int chatUConvCounter = 0; int chatUConvCounter = 0;
Future<void> getUserAutoLoginToken() async { Future<void> getUserAutoLoginToken() async {
@ -291,14 +291,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void chatNotDelivered(List<Object?>? args) { void chatNotDelivered(List<Object?>? args) {
dynamic items = args!.toList(); dynamic items = args!.toList();
for (dynamic item in items[0]) { for (dynamic item in items[0]) {
searchedChats!.forEach( for (ChatUser element in searchedChats!) {
(ChatUser element) { if (element.id == item["currentUserId"]) {
if (element.id == item["currentUserId"]) { int? val = element.unreadMessageCount ?? 0;
int? val = element.unreadMessageCount ?? 0; element.unreadMessageCount = val! + 1;
element.unreadMessageCount = val! + 1; }
} }
},
);
} }
notifyListeners(); notifyListeners();
} }
@ -378,20 +376,25 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
setMsgTune(); setMsgTune();
if (isChatScreenActive && data.first.currentUserId == receiverID) { if (isChatScreenActive && data.first.currentUserId == receiverID) {
userChatHistory.insert(0, data.first); userChatHistory.insert(0, data.first);
} } else {
if (searchedChats != null) {
if (searchedChats != null) { for (ChatUser user in searchedChats!) {
for (ChatUser user in searchedChats!) { if (user.id == data.first.currentUserId) {
if (user.id == data.first.currentUserId) { int tempCount = user.unreadMessageCount ?? 0;
int tempCount = user.unreadMessageCount ?? 0; user.unreadMessageCount = tempCount + 1;
user.unreadMessageCount = tempCount + 1; }
} }
sort();
} }
sort();
} }
List list = [ List<Object> list = [
{"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive && data.first.currentUserId == receiverID ? true : false} {
"userChatHistoryId": data.first.userChatHistoryId,
"TargetUserId": temp.first.targetUserId,
"isDelivered": true,
"isSeen": isChatScreenActive && data.first.currentUserId == receiverID ? true : false
}
]; ];
updateUserChatHistoryOnMsg(list); updateUserChatHistoryOnMsg(list);
invokeChatCounter(userId: AppState().chatDetails!.response!.id!); invokeChatCounter(userId: AppState().chatDetails!.response!.id!);
@ -400,9 +403,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void sort() { void sort() {
searchedChats!.sort( searchedChats!.sort(
(ChatUser a, ChatUser b) => b.unreadMessageCount!.compareTo( (ChatUser a, ChatUser b) => b.unreadMessageCount!.compareTo(a.unreadMessageCount!),
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 { 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) { if (!isFileSelected && !isMsgReply) {
print("Normal Text Msg"); print("Normal Text Msg");
if (message.text == null || message.text.isEmpty) { if (message.text == null || message.text.isEmpty) {
@ -621,6 +600,51 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isImageLoaded: true, isImageLoaded: true,
image: selectedFile.readAsBytesSync()); 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) { void selectImageToUpload(BuildContext context) {
@ -725,7 +749,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
if (user.id == favoriteChatUser.response!.targetUserId!) { if (user.id == favoriteChatUser.response!.targetUserId!) {
user.isFav = favoriteChatUser.response!.isFav; 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() { void clearAll() {
print("----------------- Disposed ---------------------------");
searchedChats = pChatHistory; searchedChats = pChatHistory;
search.clear(); search.clear();
isChatScreenActive = false; isChatScreenActive = false;
@ -775,6 +803,37 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
sFileType = ""; 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 { void getUserImages() async {
List<String> emails = []; List<String> emails = [];
List<ChatUser> exists = [], unique = []; List<ChatUser> exists = [], unique = [];
@ -885,4 +944,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
await chatHubConnection.invoke("GetChatCounversationCount", args: [userId]); await chatHubConnection.invoke("GetChatCounversationCount", args: [userId]);
return ""; return "";
} }
void userTypingInvoke({required int currentUser, required int reciptUser}) async {
logger.d([reciptUser, currentUser]);
await chatHubConnection.invoke("UserTypingAsync", args: [reciptUser, currentUser]);
}
} }

@ -123,6 +123,7 @@ class ChatBubble extends StatelessWidget {
if (fileTypeID == 1 || fileTypeID == 5 || fileTypeID == 7 || fileTypeID == 6 || fileTypeID == 8 || fileTypeID == 2) if (fileTypeID == 1 || fileTypeID == 5 || fileTypeID == 7 || fileTypeID == 6 || fileTypeID == 8 || fileTypeID == 2)
SvgPicture.asset(data.getType(fileTypeName ?? ""), height: 30, width: 22, alignment: Alignment.center, fit: BoxFit.cover).paddingOnly(left: 0, right: 10), SvgPicture.asset(data.getType(fileTypeName ?? ""), height: 30, width: 22, alignment: Alignment.center, fit: BoxFit.cover).paddingOnly(left: 0, right: 10),
(cItem.contant ?? "").toText12().expanded, (cItem.contant ?? "").toText12().expanded,
if (fileTypeID == 1 || fileTypeID == 5 || fileTypeID == 7 || fileTypeID == 6 || fileTypeID == 8 || fileTypeID == 2) const Icon(Icons.remove_red_eye, size: 20)
], ],
), ),
Align( Align(
@ -217,11 +218,9 @@ class ChatBubble extends StatelessWidget {
Row( Row(
children: [ children: [
if (fileTypeID == 1 || fileTypeID == 5 || fileTypeID == 7 || fileTypeID == 6 || fileTypeID == 8 || fileTypeID == 2) if (fileTypeID == 1 || fileTypeID == 5 || fileTypeID == 7 || fileTypeID == 6 || fileTypeID == 8 || fileTypeID == 2)
SvgPicture.asset(data.getType(fileTypeName ?? ""), height: 30, width: 22, alignment: Alignment.center, fit: BoxFit.cover).paddingOnly( SvgPicture.asset(data.getType(fileTypeName ?? ""), height: 30, width: 22, alignment: Alignment.center, fit: BoxFit.cover).paddingOnly(left: 0, right: 10),
left: 0,
right: 10,
),
(cItem.contant ?? "").toText12(color: Colors.white).expanded, (cItem.contant ?? "").toText12(color: Colors.white).expanded,
if (fileTypeID == 1 || fileTypeID == 5 || fileTypeID == 7 || fileTypeID == 6 || fileTypeID == 8 || fileTypeID == 2) const Icon(Icons.remove_red_eye, color: Colors.white, size: 20)
], ],
), ),
Align( Align(

@ -233,6 +233,9 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
), ),
).paddingOnly(right: 21), ).paddingOnly(right: 21),
), ),
onChanged: (val) {
m.userTypingInvoke(currentUser: AppState().chatDetails!.response!.id!, reciptUser: params!.chatUser!.id!);
},
), ),
], ],
)); ));

@ -47,6 +47,7 @@ class _ChatHomeState extends State<ChatHome> {
return; return;
} }
if (data.searchedChats == null || data.searchedChats!.isEmpty) { if (data.searchedChats == null || data.searchedChats!.isEmpty) {
data.isLoading = true;
data.getUserRecentChats(); data.getUserRecentChats();
} }
} }

@ -11,6 +11,7 @@ import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/models/dashboard/drawer_menu_item_model.dart'; import 'package:mohem_flutter_app/models/dashboard/drawer_menu_item_model.dart';
import 'package:mohem_flutter_app/provider/chat_provider_model.dart';
import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart'; import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
import 'package:mohem_flutter_app/ui/dialogs/id/business_card_dialog.dart'; import 'package:mohem_flutter_app/ui/dialogs/id/business_card_dialog.dart';
import 'package:mohem_flutter_app/ui/dialogs/id/employee_digital_id_dialog.dart'; import 'package:mohem_flutter_app/ui/dialogs/id/employee_digital_id_dialog.dart';
@ -28,6 +29,13 @@ class AppDrawer extends StatefulWidget {
class _AppDrawerState extends State<AppDrawer> { class _AppDrawerState extends State<AppDrawer> {
List<DrawerMenuItem> drawerMenuItemList = []; List<DrawerMenuItem> drawerMenuItemList = [];
late ChatProviderModel chatData;
@override
void initState() {
super.initState();
chatData = Provider.of<ChatProviderModel>(context, listen: false);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -171,6 +179,7 @@ class _AppDrawerState extends State<AppDrawer> {
AppState().isAuthenticated = false; AppState().isAuthenticated = false;
AppState().isLogged = false; AppState().isLogged = false;
AppState().setPostParamsInitConfig(); AppState().setPostParamsInitConfig();
chatData.disposeData();
// SharedPreferences prefs = await SharedPreferences.getInstance(); // SharedPreferences prefs = await SharedPreferences.getInstance();
// await prefs.clear(); // await prefs.clear();
Navigator.pushNamedAndRemoveUntil(context, AppRoutes.login, (Route<dynamic> route) => false, arguments: null); Navigator.pushNamedAndRemoveUntil(context, AppRoutes.login, (Route<dynamic> route) => false, arguments: null);

Loading…
Cancel
Save