Merge branch 'master' into fatima

merge-requests/47/head
Fatimah Alshammari 3 years ago
commit 0a0c173331

@ -493,6 +493,6 @@
"winnerSelectedRandomly": "سيتم اختيار الفائز عشوائياً من بين التصفيات.", "winnerSelectedRandomly": "سيتم اختيار الفائز عشوائياً من بين التصفيات.",
"fingersCrossed": "تشابك الاصابع!!!", "fingersCrossed": "تشابك الاصابع!!!",
"congrats": "مبروك !!!", "congrats": "مبروك !!!",
"allQuestionsCorrect": "لقد أجبت على جميع الأسئلة بشكل صحيح." "allQuestionsCorrect": "لقد أجبت على جميع الأسئلة بشكل صحيح.",
"typeheretoreply": "اكتب هنا للرد"
} }

@ -493,5 +493,6 @@
"winnerSelectedRandomly": "The winner will be selected randomly among the qualifiers.", "winnerSelectedRandomly": "The winner will be selected randomly among the qualifiers.",
"fingersCrossed": "Fingers Crossed!!!", "fingersCrossed": "Fingers Crossed!!!",
"congrats": "Congratulations!!!", "congrats": "Congratulations!!!",
"allQuestionsCorrect": "You have answered all questions correct" "allQuestionsCorrect": "You have answered all questions correct",
"typeheretoreply": "Type here to reply"
} }

@ -91,18 +91,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
.build(); .build();
hubConnection.onclose( hubConnection.onclose(
({Exception? error}) { ({Exception? error}) {
logger.d(error); // logger.d(error);
}, },
); );
hubConnection.onreconnecting( hubConnection.onreconnecting(
({Exception? error}) { ({Exception? error}) {
logger.d(error); // logger.d(error);
logger.d("Reconnecting"); // logger.d("Reconnecting");
}, },
); );
hubConnection.onreconnected( hubConnection.onreconnected(
({String? connectionId}) { ({String? connectionId}) {
logger.d("Reconnected"); // logger.d("Reconnected");
}, },
); );
if (hubConnection.state != HubConnectionState.Connected) { if (hubConnection.state != HubConnectionState.Connected) {
@ -110,23 +110,39 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
hubConnection.on("OnUpdateUserStatusAsync", changeStatus); hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
// hubConnection.on("OnUserTypingAsync", onUserTyping); hubConnection.on("OnUserTypingAsync", onUserTyping);
// hubConnection.on("OnUserCountAsync", userCountAsync); // hubConnection.on("OnUserCountAsync", userCountAsync);
// hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); // hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
// hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); // hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
} else { } else {
hubConnection.on("OnUpdateUserStatusAsync", changeStatus); hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
// hubConnection.on("OnUserTypingAsync", onUserTyping); hubConnection.on("OnUserTypingAsync", onUserTyping);
// hubConnection.on("OnUserCountAsync", userCountAsync); // hubConnection.on("OnUserCountAsync", userCountAsync);
// hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); // hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
// hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); // hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
} }
isLoading = false; isLoading = false;
notifyListeners(); notifyListeners();
} }
void updateUserChatStatus(List<Object?>? args) {
dynamic items = args!.toList();
for (dynamic cItem in items[0]) {
for (SingleUserChatModel chat in userChatHistory) {
if (chat.userChatHistoryId.toString() == cItem["userChatHistoryId"].toString()) {
logger.d(jsonEncode(chat));
chat.isSeen = cItem["isSeen"];
chat.isDelivered = cItem["isDelivered"];
notifyListeners();
}
}
}
}
void userCountAsync(List<Object?>? args) { void userCountAsync(List<Object?>? args) {
List items = args!.toList(); List items = args!.toList();
print("---------------------------------User Count Async -------------------------------------"); print("---------------------------------User Count Async -------------------------------------");
@ -166,7 +182,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void changeStatus(List<Object?>? args) { void changeStatus(List<Object?>? args) {
// print("================= Status Online // Offline ===================="); // print("================= Status Online // Offline ====================");
List items = args!.toList(); List items = args!.toList();
logger.d(items); // logger.d(items);
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
if (user.id == items.first["id"]) { if (user.id == items.first["id"]) {
user.userStatus = items.first["userStatus"]; user.userStatus = items.first["userStatus"];
@ -192,9 +208,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<void> onMsgReceived(List<Object?>? parameters) async { Future<void> onMsgReceived(List<Object?>? parameters) async {
List<SingleUserChatModel> data = []; List<SingleUserChatModel> data = [];
List<SingleUserChatModel> temp = [];
for (dynamic msg in parameters!) { for (dynamic msg in parameters!) {
data = getSingleUserChatModel(jsonEncode(msg)); data = getSingleUserChatModel(jsonEncode(msg));
logger.d(msg); temp = getSingleUserChatModel(jsonEncode(msg));
data.first.targetUserId = temp.first.currentUserId;
data.first.targetUserName = temp.first.currentUserName;
data.first.currentUserId = temp.first.targetUserId;
data.first.currentUserName = temp.first.targetUserName;
} }
userChatHistory.add(data.first); userChatHistory.add(data.first);
notifyListeners(); notifyListeners();
@ -207,11 +228,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
if (user.id == parameters![1] && parameters[0] == true) { if (user.id == parameters![1] && parameters[0] == true) {
user.isTyping = parameters[0] as bool?; user.isTyping = parameters[0] as bool?;
} else {
Future.delayed( Future.delayed(
const Duration(milliseconds: 500), const Duration(seconds: 2),
() { () {
user.isTyping = false; user.isTyping = false;
notifyListeners();
}, },
); );
} }
@ -223,6 +245,17 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
if (chatMessage == null || chatMessage.isEmpty) { if (chatMessage == null || chatMessage.isEmpty) {
return; return;
} }
var contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
if (contain.isEmpty) {
searchedChats!.add(
ChatUser(
id: targetUserId,
userName: targetUserName,
),
);
}
String chatData = String chatData =
'{"contant":"$chatMessage","contantNo":"8a129295-36d7-7185-5d34-cc4eec7bcba4","chatEventId":1,"fileTypeId":null,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"conversationId":"715f8b13-96ee-cd36-cb07-5a982a219982"}'; '{"contant":"$chatMessage","contantNo":"8a129295-36d7-7185-5d34-cc4eec7bcba4","chatEventId":1,"fileTypeId":null,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"conversationId":"715f8b13-96ee-cd36-cb07-5a982a219982"}';
await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]); await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);

@ -480,5 +480,6 @@ abstract class LocaleKeys {
static const fingersCrossed = 'fingersCrossed'; static const fingersCrossed = 'fingersCrossed';
static const congrats = 'congrats'; static const congrats = 'congrats';
static const allQuestionsCorrect = 'allQuestionsCorrect'; static const allQuestionsCorrect = 'allQuestionsCorrect';
static const typeheretoreply = 'typeheretoreply';
} }

@ -1,11 +1,12 @@
import 'dart:async'; import 'dart:async';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/api/chat/chat_provider_model.dart'; import 'package:mohem_flutter_app/api/chat/chat_provider_model.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart'; 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/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/ui/chat/chat_bubble.dart'; import 'package:mohem_flutter_app/ui/chat/chat_bubble.dart';
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart'; import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart'; import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart';
@ -19,7 +20,10 @@ class ChatDetailScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
userDetails = ModalRoute.of(context)!.settings.arguments; userDetails = ModalRoute
.of(context)!
.settings
.arguments;
data = Provider.of<ChatProviderModel>(context, listen: false); data = Provider.of<ChatProviderModel>(context, listen: false);
data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, pagination: "0"); data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, pagination: "0");
Timer(const Duration(seconds: 1), () => data.scrollDown()); Timer(const Duration(seconds: 1), () => data.scrollDown());
@ -31,56 +35,73 @@ class ChatDetailScreen extends StatelessWidget {
return (m.isLoading return (m.isLoading
? ChatHomeShimmer() ? ChatHomeShimmer()
: Column( : Column(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: ListView.builder( child: ListView.builder(
controller: m.scrollController, controller: m.scrollController,
shrinkWrap: true, shrinkWrap: true,
itemCount: m.userChatHistory.length, itemCount: m.userChatHistory.length,
padding: const EdgeInsets.symmetric(vertical: 10), padding: const EdgeInsets.symmetric(vertical: 10),
itemBuilder: (BuildContext context, int i) { itemBuilder: (BuildContext context, int i) {
return ChatBubble( i == 0 ? m.logger.d(m.userChatHistory.length) : "";
text: m.userChatHistory[i].contant.toString(), return ChatBubble(
isSeen: m.userChatHistory[i].isSeen == true ? true : false, text: m.userChatHistory[i].contant.toString(),
isCurrentUser: m.userChatHistory[i].currentUserId == 42062 ? true : false, isSeen: m.userChatHistory[i].isSeen == true ? true : false,
isDelivered: m.userChatHistory[i].currentUserId == 42062 && m.userChatHistory[i].isDelivered == true ? true : false, isCurrentUser: m.userChatHistory[i].currentUserId == AppState().chatDetails!.response!.id ? true : false,
dateTime: m.userChatHistory[i].createdDate.toString(), isDelivered: m.userChatHistory[i].currentUserId == AppState().chatDetails!.response!.id && m.userChatHistory[i].isDelivered == true ? true : false,
); dateTime: m.userChatHistory[i].createdDate.toString(),
}, );
), },
), ),
Card( ),
margin: EdgeInsets.zero, Card(
child: Padding( margin: EdgeInsets.zero,
padding: const EdgeInsets.symmetric(vertical: 10), child: Padding(
child: TextField( padding: const EdgeInsets.symmetric(vertical: 10),
controller: m.message, child: TextField(
decoration: InputDecoration( controller: m.message,
hintText: 'Type here to reply', decoration: InputDecoration(
hintStyle: const TextStyle(color: MyColors.grey98Color), hintText: LocaleKeys.typeheretoreply.tr(),
border: InputBorder.none, hintStyle: const TextStyle(color: MyColors.grey98Color),
focusedBorder: InputBorder.none, border: InputBorder.none,
enabledBorder: InputBorder.none, focusedBorder: InputBorder.none,
errorBorder: InputBorder.none, enabledBorder: InputBorder.none,
disabledBorder: InputBorder.none, errorBorder: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15), disabledBorder: InputBorder.none,
suffixIcon: IconButton( contentPadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
suffixIcon: SizedBox(
width: 100,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
icon: const Icon(
Icons.attach_file_rounded,
size: 27,
color: MyColors.lightGreenColor,
),
onPressed: () {},
),
IconButton(
icon: SvgPicture.asset( icon: SvgPicture.asset(
"assets/icons/chat/chat_send_icon.svg", "assets/icons/chat/chat_send_icon.svg",
height: 26, height: 26,
width: 35, width: 35,
), ),
onPressed: () { onPressed: () {
// m.logger.d(userDetails); m.sendChatMessage(m.message.text, userDetails["targetUser"].id, userDetails["targetUser"].userName);
m.sendChatMessage(m.message.text, userDetails["targetUser"].id, userDetails["targetUser"].userName);
}, },
), ),
), ],
), ),
), ),
), ),
], ),
)); ),
),
],
));
}, },
), ),
); );

@ -45,7 +45,7 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
appBar: AppBarWidget(context, title: "My Chats", showHomeButton: false), appBar: AppBarWidget(context, title: LocaleKeys.mychats.tr(), showHomeButton: false),
body: Consumer<ChatProviderModel>(builder: (BuildContext context, ChatProviderModel m, Widget? child) { body: Consumer<ChatProviderModel>(builder: (BuildContext context, ChatProviderModel m, Widget? child) {
return m.isLoading return m.isLoading
? ChatHomeShimmer() ? ChatHomeShimmer()
@ -110,7 +110,7 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
], ],
), ),
title: (m.searchedChats![index].userName ?? "").toText14(color: MyColors.darkTextColor), title: (m.searchedChats![index].userName ?? "").toText14(color: MyColors.darkTextColor),
subtitle: (m.searchedChats![index].isTyping == true ? "Something is Typing" : "Last message text").toText11(color: MyColors.normalTextColor), subtitle: (m.searchedChats![index].isTyping == true ? "Typing ..." : "").toText11(color: MyColors.normalTextColor),
trailing: ("Today").toText10(color: MyColors.lightTextColor), trailing: ("Today").toText10(color: MyColors.lightTextColor),
minVerticalPadding: 0, minVerticalPadding: 0,
onTap: () { onTap: () {

@ -217,8 +217,8 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
], ],
), ),
title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor), title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor),
subtitle: (chatUsersList![index].isTyping == true ? "Something is Typing" : "Last message text").toText11(color: MyColors.normalTextColor), // subtitle: (chatUsersList![index].isTyping == true ? "Something is Typing" : "Last message text").toText11(color: MyColors.normalTextColor),
trailing: ("Today").toText10(color: MyColors.lightTextColor), // trailing: ("Today").toText10(color: MyColors.lightTextColor),
minVerticalPadding: 0, minVerticalPadding: 0,
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(context);
@ -230,7 +230,7 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
}, },
); );
}, },
separatorBuilder: (cxt, index) => Container( separatorBuilder: (BuildContext cxt, int index) => Container(
height: 1, height: 1,
color: MyColors.borderE3Color, color: MyColors.borderE3Color,
), ),

Loading…
Cancel
Save