Chat Fixes & Favorite Api Implementation

merge-requests/52/head
Aamir Muhammad 3 years ago
parent 8ba3dcf43b
commit 67f4fdef28

@ -141,20 +141,13 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
) )
.build(); .build();
hubConnection.onclose( hubConnection.onclose(
({Exception? error}) { ({Exception? error}) {},
// logger.d(error);
},
); );
hubConnection.onreconnecting( hubConnection.onreconnecting(
({Exception? error}) { ({Exception? error}) {},
// logger.d(error);
// logger.d("Reconnecting");
},
); );
hubConnection.onreconnected( hubConnection.onreconnected(
({String? connectionId}) { ({String? connectionId}) {},
// logger.d("Reconnected");
},
); );
if (hubConnection.state != HubConnectionState.Connected) { if (hubConnection.state != HubConnectionState.Connected) {
await hubConnection.start(); await hubConnection.start();
@ -403,7 +396,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
sFileType = ""; sFileType = "";
message.clear(); message.clear();
notifyListeners(); notifyListeners();
// scrollDown();
} }
void sendChatMessage(int targetUserId, String targetUserName) async { void sendChatMessage(int targetUserId, String targetUserName) async {
@ -437,7 +429,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
sendChatToServer( sendChatToServer(
chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, chatReplyId: repliedMsg.first.userChatHistoryId, isAttachment: false, isReply: true); chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, chatReplyId: repliedMsg.first.userChatHistoryId, isAttachment: false, isReply: true);
//chatReplyId
} }
if (isFileSelected && isMsgReply) { if (isFileSelected && isMsgReply) {
logger.d("Attachment Message With Reply"); logger.d("Attachment Message With Reply");
@ -445,60 +436,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
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);
sendChatToServer( sendChatToServer(
chatEventId: 2, chatEventId: 2,
fileTypeId: getFileType(ext.toString()), fileTypeId: getFileType(ext.toString()),
targetUserId: targetUserId, targetUserId: targetUserId,
targetUserName: targetUserName, targetUserName: targetUserName,
isAttachment: true, isAttachment: true,
chatReplyId: repliedMsg.first.userChatHistoryId, chatReplyId: repliedMsg.first.userChatHistoryId,
isReply: true); isReply: true,
} );
// dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
// if (contain.isEmpty) {
// searchedChats!.add(
// ChatUser(
// id: targetUserId,
// userName: targetUserName,
// ),
// );
// notifyListeners();
// }
// Uuid uuid = const Uuid();
// dynamic fileID = fileUploadResponse.isEmpty ? null : getFileType(chatMessage);
// SingleUserChatModel data = SingleUserChatModel(
// chatEventId: fileUploadResponse.isEmpty ? 1 : 2,
// chatSource: 1,
// contant: chatMessage,
// contantNo: uuid.v4(),
// conversationId: uuid.v4(),
// createdDate: DateTime.now(),
// currentUserId: AppState().chatDetails!.response!.id,
// currentUserName: AppState().chatDetails!.response!.userName,
// targetUserId: targetUserId,
// targetUserName: targetUserName,
// fileTypeId: fileID,
// isReplied: false,
// // fileTypeResponse: FileTypeResponse(
// // fileTypeId: 0,
// // fileTypeDescription: fileUploadResponse.isEmpty ? null : fileUploadResponse.first["filePath"],
// // fileName: fileUploadResponse.isEmpty ? null : fileUploadResponse.first["filePath"],
// // fileKind: "image",
// // fileTypeName: fileUploadResponse.isEmpty ? null : fileUploadResponse.first["filePath"].toString().split(".").last),
// );
//
// String chatData =
// '{"contant":"$chatMessage","contantNo":"${uuid.v4()}","chatEventId":${fileUploadResponse.isEmpty ? 1 : 2},"fileTypeId": $fileID,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"conversationId":"${uuid.v4()}"}';
// await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
// userChatHistory.add(data);
// message.clear();
// notifyListeners();
// scrollDown();
}
void scrollListener() {
if (userChatHistory.length < paginationVal) {
print("Get New Data");
} }
} }
@ -513,18 +458,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} else { } else {
Utils.showToast("Max 1 mb size is allowed to upload"); Utils.showToast("Max 1 mb size is allowed to upload");
} }
//Utils.showLoading(context);
notifyListeners(); notifyListeners();
//Utils.hideLoading(context);
// Utils.showLoading(context);
// await m.uploadAttachments(AppState().chatDetails!.response!.id.toString(), file).then((value) {
// if (value == null) {
// m.logger.d("Returned EMPTY");
// } else {
// m.sendChatMessage(value.isEmpty ? m.message.text : value.first["filePath"], userDetails["targetUser"].id, userDetails["targetUser"].userName, value);
// }
// });
// Utils.hideLoading(context);
}); });
} }

@ -10,6 +10,7 @@ class ApiConsts {
static String user = baseUrlServices + "api/User/"; static String user = baseUrlServices + "api/User/";
static String cocRest = baseUrlServices + "COCWS.svc/REST/"; static String cocRest = baseUrlServices + "COCWS.svc/REST/";
//Chat
static String chatServerBaseUrl = "https://apiderichat.hmg.com"; static String chatServerBaseUrl = "https://apiderichat.hmg.com";
static String chatServerBaseApiUrl = "https://apiderichat.hmg.com/api/"; static String chatServerBaseApiUrl = "https://apiderichat.hmg.com/api/";
static String chatHubConnectionUrl = chatServerBaseUrl + "/ConnectionChatHub"; static String chatHubConnectionUrl = chatServerBaseUrl + "/ConnectionChatHub";
@ -18,12 +19,6 @@ class ApiConsts {
static String chatSingleUserHistoryUrl = "UserChatHistory/GetUserChatHistory"; static String chatSingleUserHistoryUrl = "UserChatHistory/GetUserChatHistory";
static String chatMediaImageUploadUrl = "shared/upload"; static String chatMediaImageUploadUrl = "shared/upload";
static String chatFavoriteUsers = "FavUser/getFavUserById/"; static String chatFavoriteUsers = "FavUser/getFavUserById/";
//https://apiderichat.hmg.com/api/FavUser/getFavUserById/42062
//https://apiderichat.hmg.com/api/shared/upload
// 42062 is CurrentUserID and 36745 is targetUserID and 0 is For Pagination
// static String chatSearchMember = "https://apiderichat.hmg.com/api/user/getUserWithStatusAndFavAsync/aamir.muhammad/36239";
} }
class SharedPrefsConsts { class SharedPrefsConsts {

@ -29,7 +29,7 @@ class ChatBubble extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
// padding: EdgeInsets.zero, // padding: EdgeInsets.zero,
padding: EdgeInsets.only(left: isCurrentUser ? 110 : 20, right: isCurrentUser ? 20 : 110, bottom: 9), padding: EdgeInsets.only(left: isCurrentUser ? 110 : 20, right: isCurrentUser ? 20 : 110, bottom: 9),
child: Align( child: Align(
@ -51,7 +51,7 @@ class ChatBubble extends StatelessWidget {
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
), ),
child: Padding( child: Padding(
padding: EdgeInsets.only(top: isReplied ? 8 : 5, right:8, left: 8, bottom: 5), padding: EdgeInsets.only(top: isReplied ? 8 : 5, right: 8, left: 8, bottom: 5),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
@ -85,7 +85,6 @@ class ChatBubble extends StatelessWidget {
), ),
if (isReplied) 8.height, if (isReplied) 8.height,
text.toText12(color: isCurrentUser ? MyColors.grey57Color : MyColors.white), text.toText12(color: isCurrentUser ? MyColors.grey57Color : MyColors.white),
Row( Row(
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
@ -100,7 +99,6 @@ class ChatBubble extends StatelessWidget {
), ),
], ],
), ),
], ],
), ),
), ),

@ -8,19 +8,14 @@ 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/classes/colors.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.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/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/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/image_picker.dart';
import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart'; import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:sizer/sizer.dart';
import 'package:swipe_to/swipe_to.dart'; import 'package:swipe_to/swipe_to.dart';
class ChatDetailScreen extends StatelessWidget { class ChatDetailScreen extends StatelessWidget {
@ -30,13 +25,13 @@ class ChatDetailScreen extends StatelessWidget {
ScrollController scrollController = ScrollController(); ScrollController scrollController = ScrollController();
RefreshController _refreshController = RefreshController(initialRefresh: false); RefreshController _refreshController = RefreshController(initialRefresh: false);
void onRefresh() async { void getMoreChat() async {
print("Refresh Triggered");
await Future.delayed(Duration(milliseconds: 1000));
if (userDetails != null) { if (userDetails != null) {
data.paginationVal = data.paginationVal + 10; data.paginationVal = data.paginationVal + 10;
data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true); data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true);
} }
await Future.delayed(Duration(milliseconds: 1000));
_refreshController.refreshCompleted(); _refreshController.refreshCompleted();
} }
@ -45,16 +40,6 @@ class ChatDetailScreen extends StatelessWidget {
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);
if (userDetails != null) data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: false); if (userDetails != null) data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: false);
//
// if (userDetails != null) {
// scrollController.addListener(() {
// if (scrollController.position.minScrollExtent == scrollController.offset) {
// data.paginationVal++;
// data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true);
// }
// });
// }
return Scaffold( return Scaffold(
backgroundColor: const Color(0xFFF8F8F8), backgroundColor: const Color(0xFFF8F8F8),
appBar: AppBarWidget(context, title: userDetails["targetUser"].userName, showHomeButton: false, image: userDetails["targetUser"].image), appBar: AppBarWidget(context, title: userDetails["targetUser"].userName, showHomeButton: false, image: userDetails["targetUser"].image),
@ -73,34 +58,28 @@ class ChatDetailScreen extends StatelessWidget {
color: MyColors.gradiantEndColor, color: MyColors.gradiantEndColor,
), ),
controller: _refreshController, controller: _refreshController,
onRefresh: onRefresh, onRefresh: getMoreChat,
child: ListView.builder( child: ListView.builder(
controller: scrollController, controller: scrollController,
shrinkWrap: true, shrinkWrap: true,
itemCount: m.userChatHistory.length, itemCount: m.userChatHistory.length,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
itemBuilder: (BuildContext context, int i) { itemBuilder: (BuildContext context, int i) {
return GestureDetector( return SwipeTo(
onTap: () { iconColor: MyColors.lightGreenColor,
m.logger.d(jsonEncode(m.userChatHistory[i])); child: ChatBubble(
m.logger.d(jsonEncode(m.userChatHistory.length)); text: m.userChatHistory[i].contant.toString(),
}, replyText: m.userChatHistory[i].userChatReplyResponse != null ? m.userChatHistory[i].userChatReplyResponse!.contant.toString() : "",
child: SwipeTo( isSeen: m.userChatHistory[i].isSeen == true ? true : false,
iconColor: MyColors.lightGreenColor, isCurrentUser: m.userChatHistory[i].currentUserId == AppState().chatDetails!.response!.id ? true : false,
child: ChatBubble( isDelivered: m.userChatHistory[i].currentUserId == AppState().chatDetails!.response!.id && m.userChatHistory[i].isDelivered == true ? true : false,
text: m.userChatHistory[i].contant.toString(), dateTime: m.dateFormte(m.userChatHistory[i].createdDate!),
replyText: m.userChatHistory[i].userChatReplyResponse != null ? m.userChatHistory[i].userChatReplyResponse!.contant.toString() : "", isReplied: m.userChatHistory[i].userChatReplyResponse != null ? true : false,
isSeen: m.userChatHistory[i].isSeen == true ? true : false, userName: AppState().chatDetails!.response!.userName == m.userChatHistory[i].currentUserName.toString() ? "You" : m.userChatHistory[i].currentUserName.toString(),
isCurrentUser: m.userChatHistory[i].currentUserId == AppState().chatDetails!.response!.id ? true : false,
isDelivered: m.userChatHistory[i].currentUserId == AppState().chatDetails!.response!.id && m.userChatHistory[i].isDelivered == true ? true : false,
dateTime: m.dateFormte(m.userChatHistory[i].createdDate!),
isReplied: m.userChatHistory[i].userChatReplyResponse != null ? true : false,
userName: AppState().chatDetails!.response!.userName == m.userChatHistory[i].currentUserName.toString() ? "You" : m.userChatHistory[i].currentUserName.toString(),
),
onRightSwipe: () {
m.chatReply(m.userChatHistory[i]);
},
), ),
onRightSwipe: () {
m.chatReply(m.userChatHistory[i]);
},
); );
}, },
), ),
@ -203,7 +182,7 @@ class ChatDetailScreen extends StatelessWidget {
], ],
) )
: null, : null,
suffixIcon: Container( suffixIcon: SizedBox(
width: 96, width: 96,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,

@ -27,7 +27,7 @@ class ChatHomeScreen extends StatefulWidget {
} }
class _ChatHomeScreenState extends State<ChatHomeScreen> { class _ChatHomeScreenState extends State<ChatHomeScreen> {
TextEditingController search = new TextEditingController(); TextEditingController search = TextEditingController();
late ChatProviderModel data; late ChatProviderModel data;
@override @override
@ -213,8 +213,6 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
apiMode: LocaleKeys.delegate.tr(), apiMode: LocaleKeys.delegate.tr(),
fromChat: true, fromChat: true,
onSelectEmployee: (_selectedEmployee) { onSelectEmployee: (_selectedEmployee) {
// Navigator.pop(context);
// selectedReplacementEmployee = _selectedEmployee;
setState(() {}); setState(() {});
}, },
), ),

@ -136,12 +136,13 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
}, },
).expanded, ).expanded,
IconButton( IconButton(
constraints: const BoxConstraints(), constraints: const BoxConstraints(),
onPressed: () async { onPressed: () async {
await SystemChannels.textInput.invokeMethod('TextInput.hide'); await SystemChannels.textInput.invokeMethod('TextInput.hide');
widget.fromChat ? fetchChatUser() : fetchUserByInput(); widget.fromChat ? fetchChatUser() : fetchUserByInput();
}, },
icon: Icon(Icons.search)) icon: const Icon(Icons.search),
)
], ],
), ),
if (replacementList != null) if (replacementList != null)
@ -184,62 +185,21 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
if (chatUsersList != null && widget.fromChat) if (chatUsersList != null && widget.fromChat)
chatUsersList!.isEmpty chatUsersList!.isEmpty
? Column( ? Column(
children: [ children: [
20.height, 20.height,
Utils.getNoDataWidget(context), Utils.getNoDataWidget(context),
], ],
) )
: ListView( : ListView(
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.only(top: 15,), padding: const EdgeInsets.only(
top: 15,
),
children: <Widget>[ children: <Widget>[
ListView.separated( ListView.separated(
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
itemBuilder: (BuildContext cxt, int index) { itemBuilder: (BuildContext cxt, int index) {
// return ListTile(
// leading: Stack(
// children: <Widget>[
// SvgPicture.asset(
// "assets/images/user.svg",
// height: 48,
// width: 48,
// ),
// Positioned(
// right: 5,
// bottom: 1,
// child: Container(
// width: 10,
// height: 10,
// decoration: BoxDecoration(
// color: chatUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red,
// borderRadius: const BorderRadius.all(
// Radius.circular(10),
// ),
// ),
// ),
// )
// ],
// ),
// title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor),
// // subtitle: (chatUsersList![index].isTyping == true ? "Something is Typing" : "Last message text").toText11(color: MyColors.normalTextColor),
// // trailing: ("Today").toText10(color: MyColors.lightTextColor),
// minVerticalPadding: 0,
// onTap: () {
// Navigator.pop(context);
// Navigator.pushNamed(
// context,
// AppRoutes.chatDetailed,
// arguments: {"targetUser": chatUsersList![index]},
// );
// },
// );
return SizedBox( return SizedBox(
height: 55, height: 55,
child: ListTile( child: ListTile(
@ -279,12 +239,9 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
onLongPress: () {}, onLongPress: () {},
), ),
); );
}, },
separatorBuilder: (BuildContext context, int index) => const Padding( separatorBuilder: (BuildContext context, int index) => const Padding(
padding: EdgeInsets.only(right: 10, left: 70, bottom: 0,top: 0), padding: EdgeInsets.only(right: 10, left: 70, bottom: 0, top: 0),
child: Divider( child: Divider(
color: Color(0xFFE5E5E5), color: Color(0xFFE5E5E5),
), ),
@ -349,7 +306,9 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.transparent, color: Colors.transparent,
border: Border.all(color: MyColors.borderColor, width: 1), border: Border.all(color: MyColors.borderColor, width: 1),
borderRadius: const BorderRadius.all(Radius.circular(100)), borderRadius: const BorderRadius.all(
Radius.circular(100),
),
), ),
padding: const EdgeInsets.all(4), padding: const EdgeInsets.all(4),
child: Container( child: Container(
@ -357,7 +316,9 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
height: double.infinity, height: double.infinity,
decoration: BoxDecoration( decoration: BoxDecoration(
color: value == groupValue ? MyColors.grey3AColor : Colors.transparent, color: value == groupValue ? MyColors.grey3AColor : Colors.transparent,
borderRadius: BorderRadius.all(const Radius.circular(100)), borderRadius: const BorderRadius.all(
Radius.circular(100),
),
), ),
), ),
), ),

Loading…
Cancel
Save