Merge branch 'development_aamir' into 'master'

Chat Fixes

See merge request Cloud_Solution/mohemm-flutter-app!56
merge-requests/57/merge
haroon amjad 3 years ago
commit 0508f6c393

@ -499,7 +499,6 @@
"resend": "إعادة إرسال", "resend": "إعادة إرسال",
"codeExpire": "انتهت صلاحية رمز التحقق", "codeExpire": "انتهت صلاحية رمز التحقق",
"typeheretoreply": "اكتب هنا للرد", "typeheretoreply": "اكتب هنا للرد",
"favorite" : "أُفضله", "favorite": "مفضلتي",
"searchfromchat": "البحث من الدردشة" "searchfromchat": "البحث من الدردشة"
} }

@ -499,7 +499,7 @@
"codeExpire": "The verification code has been expired", "codeExpire": "The verification code has been expired",
"allQuestionsCorrect": "You have answered all questions correct", "allQuestionsCorrect": "You have answered all questions correct",
"typeheretoreply": "Type here to reply", "typeheretoreply": "Type here to reply",
"favorite" : "My Favorite", "favorite" : "My Favorites",
"searchfromchat": "Search from chat" "searchfromchat": "Search from chat"
} }

@ -44,6 +44,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<void> getUserAutoLoginToken() async { Future<void> getUserAutoLoginToken() async {
String userName = AppState().memberInformationList!.eMPLOYEEEMAILADDRESS!.split("@").first.toString(); String userName = AppState().memberInformationList!.eMPLOYEEEMAILADDRESS!.split("@").first.toString();
//userName
Response response = Response response =
await ApiClient().postJsonForResponse("${ApiConsts.chatServerBaseApiUrl}user/desktopuserlogin", {"userName": userName, "password": "FxIu26rWIKoF8n6mpbOmAjDLphzFGmpG", "loginType": 2}); await ApiClient().postJsonForResponse("${ApiConsts.chatServerBaseApiUrl}user/desktopuserlogin", {"userName": userName, "password": "FxIu26rWIKoF8n6mpbOmAjDLphzFGmpG", "loginType": 2});
login.UserAutoLoginModel userLoginResponse = login.userAutoLoginModelFromJson(response.body); login.UserAutoLoginModel userLoginResponse = login.userAutoLoginModelFromJson(response.body);
@ -84,8 +85,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
} }
} }
pChatHistory = recentChat.response; pChatHistory = recentChat.response == null ? [] : recentChat.response;
pChatHistory!.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase())); if (pChatHistory != null) pChatHistory!.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase()));
searchedChats = pChatHistory; searchedChats = pChatHistory;
isLoading = false; isLoading = false;
notifyListeners(); notifyListeners();
@ -164,7 +166,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
await hubConnection.start(); await hubConnection.start();
hubConnection.on("OnUpdateUserStatusAsync", changeStatus); hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
// hubConnection.on("OnSeenChatUserAsync", onChatSeen); // hubConnection.on("OnSeenChatUserAsync", onChatSeen);
//hubConnection.on("OnUserTypingAsync", onUserTyping); //hubConnection.on("OnUserTypingAsync", onUserTyping);
// hubConnection.on("OnUserCountAsync", userCountAsync); // hubConnection.on("OnUserCountAsync", userCountAsync);
@ -288,7 +290,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
// } // }
// }); // });
notifyListeners(); notifyListeners();
// if (isChatScreenActive) scrollToBottom(); // if (isChatScreenActive) scrollToBottom();
} }
void onUserTyping(List<Object?>? parameters) { void onUserTyping(List<Object?>? parameters) {
@ -378,10 +380,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<void> sendChatToServer( Future<void> sendChatToServer(
{required int chatEventId, required fileTypeId, required int targetUserId, required String targetUserName, required chatReplyId, required bool isAttachment, required bool isReply}) async { {required int chatEventId, required fileTypeId, required int targetUserId, required String targetUserName, required chatReplyId, required bool isAttachment, required bool isReply}) async {
Uuid uuid = const Uuid(); Uuid uuid = const Uuid();
String msg = message.text;
SingleUserChatModel data = SingleUserChatModel( SingleUserChatModel data = SingleUserChatModel(
chatEventId: chatEventId, chatEventId: chatEventId,
chatSource: 1, chatSource: 1,
contant: message.text, contant: msg,
contantNo: uuid.v4(), contantNo: uuid.v4(),
conversationId: uuid.v4(), conversationId: uuid.v4(),
createdDate: DateTime.now(), createdDate: DateTime.now(),
@ -402,20 +405,19 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
) )
: null, : null,
); );
String chatData =
'{"contant":"${message.text}","contantNo":"${uuid.v4()}","chatEventId":$chatEventId,"fileTypeId": $fileTypeId,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"chatReplyId":$chatReplyId,"conversationId":"${uuid.v4()}"}';
await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
userChatHistory.insert(0, data); userChatHistory.insert(0, data);
isFileSelected = false; isFileSelected = false;
isMsgReply = false; isMsgReply = false;
sFileType = ""; sFileType = "";
message.clear(); message.clear();
notifyListeners(); notifyListeners();
String chatData =
'{"contant":"$msg","contantNo":"${uuid.v4()}","chatEventId":$chatEventId,"fileTypeId": $fileTypeId,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"chatReplyId":$chatReplyId,"conversationId":"${uuid.v4()}"}';
await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
} }
void sendChatMessage(int targetUserId, String targetUserName) async { void sendChatMessage(int targetUserId, String targetUserName, BuildContext context) async {
dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId); dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
if (contain.isEmpty) { if (contain.isEmpty) {
searchedChats!.add( searchedChats!.add(
@ -434,9 +436,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
sendChatToServer(chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: false, chatReplyId: null, isReply: false); sendChatToServer(chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: false, chatReplyId: null, isReply: false);
} }
if (isFileSelected && !isMsgReply) { if (isFileSelected && !isMsgReply) {
Utils.showLoading(context);
logger.d("Normal Attachment Message"); logger.d("Normal Attachment Message");
dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile);
String? ext = getFileExtension(selectedFile.path); String? ext = getFileExtension(selectedFile.path);
Utils.hideLoading(context);
sendChatToServer(chatEventId: 2, fileTypeId: getFileType(ext.toString()), targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: true, chatReplyId: null, isReply: false); sendChatToServer(chatEventId: 2, fileTypeId: getFileType(ext.toString()), targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: true, chatReplyId: null, isReply: false);
} }
if (!isFileSelected && isMsgReply) { if (!isFileSelected && isMsgReply) {
@ -449,9 +453,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
if (isFileSelected && isMsgReply) { if (isFileSelected && isMsgReply) {
logger.d("Attachment Message With Reply"); logger.d("Attachment Message With Reply");
logger.d(repliedMsg.first.userChatHistoryId); Utils.showLoading(context);
dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile);
String? ext = getFileExtension(selectedFile.path); String? ext = getFileExtension(selectedFile.path);
Utils.hideLoading(context);
sendChatToServer( sendChatToServer(
chatEventId: 2, chatEventId: 2,
fileTypeId: getFileType(ext.toString()), fileTypeId: getFileType(ext.toString()),

@ -1,7 +1,7 @@
class ApiConsts { class ApiConsts {
//static String baseUrl = "http://10.200.204.20:2801/"; // Local server //static String baseUrl = "http://10.200.204.20:2801/"; // Local server
static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server
// static String baseUrl = "https://hmgwebservices.com"; // Live server //static String baseUrl = "https://hmgwebservices.com"; // Live server
static String baseUrlServices = baseUrl + "/Services/"; // server static String baseUrlServices = baseUrl + "/Services/"; // server
// static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server
static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/";

@ -515,7 +515,7 @@ class CodegenLoader extends AssetLoader{
"resend": "إعادة إرسال", "resend": "إعادة إرسال",
"codeExpire": "انتهت صلاحية رمز التحقق", "codeExpire": "انتهت صلاحية رمز التحقق",
"typeheretoreply": "اكتب هنا للرد", "typeheretoreply": "اكتب هنا للرد",
"favorite": "أُفضله", "favorite": "مفضلتي",
"searchfromchat": "البحث من الدردشة" "searchfromchat": "البحث من الدردشة"
}; };
static const Map<String,dynamic> en_US = { static const Map<String,dynamic> en_US = {
@ -1019,7 +1019,7 @@ static const Map<String,dynamic> en_US = {
"codeExpire": "The verification code has been expired", "codeExpire": "The verification code has been expired",
"allQuestionsCorrect": "You have answered all questions correct", "allQuestionsCorrect": "You have answered all questions correct",
"typeheretoreply": "Type here to reply", "typeheretoreply": "Type here to reply",
"favorite": "My Favorite", "favorite": "My Favorites",
"searchfromchat": "Search from chat" "searchfromchat": "Search from chat"
}; };
static const Map<String, Map<String,dynamic>> mapLocales = {"ar_SA": ar_SA, "en_US": en_US}; static const Map<String, Map<String,dynamic>> mapLocales = {"ar_SA": ar_SA, "en_US": en_US};

@ -252,7 +252,7 @@ class ChatDetailScreen extends StatelessWidget {
width: 26, width: 26,
), ),
onPressed: () { onPressed: () {
m.sendChatMessage(userDetails["targetUser"].id, userDetails["targetUser"].userName); m.sendChatMessage(userDetails["targetUser"].id, userDetails["targetUser"].userName, context);
}, },
) )
], ],

@ -26,7 +26,6 @@ class _ChatHomeState extends State<ChatHome> {
PageController controller = PageController(); PageController controller = PageController();
late ChatProviderModel data; late ChatProviderModel data;
@override @override
void initState() { void initState() {
// TODO: implement initState // TODO: implement initState
@ -46,7 +45,6 @@ class _ChatHomeState extends State<ChatHome> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: MyColors.white, backgroundColor: MyColors.white,
appBar: AppBarWidget( appBar: AppBarWidget(

@ -7,7 +7,6 @@ import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/config/routes.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_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/widgets/bottom_sheet.dart'; import 'package:mohem_flutter_app/widgets/bottom_sheet.dart';
import 'package:mohem_flutter_app/widgets/bottom_sheets/search_employee_bottom_sheet.dart'; import 'package:mohem_flutter_app/widgets/bottom_sheets/search_employee_bottom_sheet.dart';
@ -113,35 +112,40 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
if (m.searchedChats![index].unreadMessageCount! > 0) // if (m.searchedChats![index].unreadMessageCount != null)
Flexible( // Flexible(
child: Container( // child: Container(
padding: EdgeInsets.zero, // padding: EdgeInsets.zero,
alignment: Alignment.centerRight, // alignment: Alignment.centerRight,
width: 18, // width: 18,
height: 18, // height: 18,
decoration: const BoxDecoration( // decoration: const BoxDecoration(
color: MyColors.redColor, // color: MyColors.redColor,
borderRadius: BorderRadius.all( // borderRadius: BorderRadius.all(
Radius.circular(20), // Radius.circular(20),
), // ),
), // ),
child: (m.searchedChats![index].unreadMessageCount!.toString()) // child: (m.searchedChats![index].unreadMessageCount!.toString())
.toText10( // .toText10(
color: MyColors.white, // color: MyColors.white,
) // )
.center, // .center,
), // ),
), // ),
Flexible( Flexible(
child: IconButton( child: IconButton(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
icon: Icon(m.searchedChats![index].isFav! ? Icons.star_sharp : Icons.star_border), icon: Icon(m.searchedChats![index].isFav != null && m.searchedChats![index].isFav == false ? Icons.star_sharp : Icons.star_sharp),
color: m.searchedChats![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color, color: m.searchedChats![index].isFav != null && m.searchedChats![index].isFav == true ? MyColors.yellowColor : MyColors.grey35Color,
onPressed: () { onPressed: () {
if (m.searchedChats![index].isFav!) m.unFavoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!); if (m.searchedChats![index].isFav == null || m.searchedChats![index].isFav == false) {
if (!m.searchedChats![index].isFav!) m.favoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!); m.favoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!);
} else if (m.searchedChats![index].isFav == true) {
m.unFavoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!);
} else {
m.favoriteUser(userID: AppState().chatDetails!.response!.id!, targetUserID: m.searchedChats![index].id!);
}
}, },
), ),
) )

Loading…
Cancel
Save