merge-requests/65/head
Sultan khan 3 years ago
commit 557a4c3737

@ -29,7 +29,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
late HubConnection hubConnection; late HubConnection hubConnection;
L.Logger logger = L.Logger(); L.Logger logger = L.Logger();
bool hubConInitialized = false; bool hubConInitialized = false;
String chatCID = '';
bool isLoading = true; bool isLoading = true;
bool isChatScreenActive = false; bool isChatScreenActive = false;
late File selectedFile; late File selectedFile;
@ -40,18 +40,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
List<ChatUser> favUsersList = []; List<ChatUser> favUsersList = [];
int paginationVal = 0; int paginationVal = 0;
//Scroll Future<void> getUserAutoLoginToken(BuildContext cxt) async {
bool _firstAutoscrollExecuted = false;
bool _shouldAutoscroll = false;
Future<void> getUserAutoLoginToken() async {
Response response = await ApiClient().postJsonForResponse( Response response = await ApiClient().postJsonForResponse(
"${ApiConsts.chatServerBaseApiUrl}user/externaluserlogin", "${ApiConsts.chatServerBaseApiUrl}user/externaluserlogin",
{ {
"employeeNumber": int.parse( "employeeNumber": AppState().memberInformationList!.eMPLOYEENUMBER.toString(),
AppState().memberInformationList!.eMPLOYEENUMBER.toString(), "password": "FxIu26rWIKoF8n6mpbOmAjDLphzFGmpG",
),
"password": "FxIu26rWIKoF8n6mpbOmAjDLphzFGmpG"
}, },
); );
login.UserAutoLoginModel userLoginResponse = login.userAutoLoginModelFromJson( login.UserAutoLoginModel userLoginResponse = login.userAutoLoginModelFromJson(
@ -63,7 +57,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
AppState().setchatUserDetails = userLoginResponse; AppState().setchatUserDetails = userLoginResponse;
await buildHubConnection(); await buildHubConnection();
} else { } else {
Utils.showToast(userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr"); Utils.showToast(
userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr",
);
return; return;
} }
} }
@ -76,7 +72,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
return searchUserJsonModel(response.body); return searchUserJsonModel(response.body);
} }
List<ChatUser> searchUserJsonModel(String str) => List<ChatUser>.from(json.decode(str).map((x) => ChatUser.fromJson(x))); List<ChatUser> searchUserJsonModel(String str) => List<ChatUser>.from(
json.decode(str).map(
(x) => ChatUser.fromJson(x),
),
);
void getUserRecentChats() async { void getUserRecentChats() async {
Response response = await ApiClient().getJsonForResponse( Response response = await ApiClient().getJsonForResponse(
@ -90,9 +90,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
token: AppState().chatDetails!.response!.token, token: AppState().chatDetails!.response!.token,
); );
ChatUserModel favUList = userToList(favRes.body); ChatUserModel favUList = userToList(favRes.body);
if (favUList.response != null) {
if (favUList.response != null && recentChat.response != null) {
favUsersList = favUList.response!; favUsersList = favUList.response!;
favUsersList.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase())); favUsersList.sort(
(ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(
b.userName!.toLowerCase(),
),
);
for (dynamic user in recentChat.response!) { for (dynamic user in recentChat.response!) {
for (dynamic favUser in favUList.response!) { for (dynamic favUser in favUList.response!) {
if (user.id == favUser.id) { if (user.id == favUser.id) {
@ -101,16 +106,23 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
} }
} }
pChatHistory = recentChat.response == null ? [] : recentChat.response; pChatHistory = recentChat.response ?? [];
if (pChatHistory != null) pChatHistory!.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase())); pChatHistory!.sort(
(ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(
b.userName!.toLowerCase(),
),
);
searchedChats = pChatHistory; searchedChats = pChatHistory;
isLoading = false; isLoading = false;
notifyListeners(); notifyListeners();
} }
Future GetUserChatHistoryNotDeliveredAsync(int userId) async { Future getUserChatHistoryNotDeliveredAsync({required int userId}) async {
await hubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]); await hubConnection.invoke(
"GetUserChatHistoryNotDeliveredAsync",
args: [userId],
);
return ""; return "";
} }
@ -132,35 +144,95 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
} else { } else {
if (loadMore) { if (loadMore) {
List<SingleUserChatModel> temp = getSingleUserChatModel(response.body).reversed.toList(); List<SingleUserChatModel> temp = getSingleUserChatModel(
userChatHistory.addAll(temp); response.body,
).reversed.toList();
userChatHistory.addAll(
temp,
);
} else { } else {
userChatHistory = getSingleUserChatModel(response.body).reversed.toList(); userChatHistory = getSingleUserChatModel(
response.body,
).reversed.toList();
} }
} }
await getUserChatHistoryNotDeliveredAsync(
userId: senderUID,
);
isLoading = false; isLoading = false;
await GetUserChatHistoryNotDeliveredAsync(senderUID);
notifyListeners(); notifyListeners();
markRead(
userChatHistory,
receiverUID,
);
generateConvId();
}
void generateConvId() async {
Uuid uuid = const Uuid();
chatCID = uuid.v4();
}
void markRead(List<SingleUserChatModel> data, reciverID) {
for (SingleUserChatModel element in data!) {
if (!element.isSeen!) {
dynamic data = [
{
"userChatHistoryId": element.userChatHistoryId,
"TargetUserId": element.targetUserId,
"isDelivered": true,
"isSeen": true,
}
];
updateUserChatHistoryStatusAsync(data);
}
}
for (ChatUser element in searchedChats!) {
if (element.id == reciverID) {
element.unreadMessageCount = 0;
notifyListeners();
}
}
} }
void updateUserChatHistoryStatusAsync(List data) { void updateUserChatHistoryStatusAsync(List data) {
hubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]); hubConnection.invoke(
"UpdateUserChatHistoryStatusAsync",
args: [data],
);
} }
List<SingleUserChatModel> getSingleUserChatModel(String str) => List<SingleUserChatModel>.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x))); List<SingleUserChatModel> getSingleUserChatModel(String str) => List<SingleUserChatModel>.from(
json.decode(str).map(
(x) => SingleUserChatModel.fromJson(x),
),
);
ChatUserModel userToList(String str) => ChatUserModel.fromJson(json.decode(str)); ChatUserModel userToList(String str) => ChatUserModel.fromJson(
json.decode(str),
);
Future<dynamic> uploadAttachments(String userId, File file) async { Future<dynamic> uploadAttachments(String userId, File file) async {
dynamic result; dynamic result;
dynamic request = MultipartRequest('POST', Uri.parse('${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatMediaImageUploadUrl}')); dynamic request = MultipartRequest(
'POST',
Uri.parse(
'${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatMediaImageUploadUrl}',
),
);
request.fields.addAll({'userId': userId, 'fileSource': '1'}); request.fields.addAll({'userId': userId, 'fileSource': '1'});
request.files.add(await MultipartFile.fromPath('files', file.path)); request.files.add(await MultipartFile.fromPath('files', file.path));
request.headers.addAll({'Authorization': 'Bearer ${AppState().chatDetails!.response!.token}'}); request.headers.addAll(
{
'Authorization': 'Bearer ${AppState().chatDetails!.response!.token}',
},
);
try { try {
StreamedResponse response = await request.send(); StreamedResponse response = await request.send();
if (response.statusCode == 200) { if (response.statusCode == 200) {
result = jsonDecode(await response.stream.bytesToString()); result = jsonDecode(
await response.stream.bytesToString(),
);
} else { } else {
result = []; result = [];
} }
@ -174,9 +246,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
Future<void> buildHubConnection() async { Future<void> buildHubConnection() async {
HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); HttpConnectionOptions httpOp = HttpConnectionOptions(
skipNegotiation: false,
logMessageContent: true,
);
hubConnection = HubConnectionBuilder() hubConnection = HubConnectionBuilder()
.withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp) .withUrl(
ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}",
options: httpOp,
)
.withAutomaticReconnect( .withAutomaticReconnect(
retryDelays: <int>[2000, 5000, 10000, 20000], retryDelays: <int>[2000, 5000, 10000, 20000],
) )
@ -195,6 +273,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
); );
if (hubConnection.state != HubConnectionState.Connected) { if (hubConnection.state != HubConnectionState.Connected) {
await hubConnection.start(); await hubConnection.start();
getUserChatHistoryNotDeliveredAsync(
userId: int.parse(
AppState().chatDetails!.response!.id.toString(),
),
);
hubConnection.on("OnUpdateUserStatusAsync", changeStatus); hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
// hubConnection.on("OnSeenChatUserAsync", onChatSeen); // hubConnection.on("OnSeenChatUserAsync", onChatSeen);
@ -260,23 +343,23 @@ 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]) {
dynamic data = [ searchedChats!.forEach((element) {
{ if (element.id == item["currentUserId"]) {
"userChatHistoryId": item["userChatHistoryId"], var val = element.unreadMessageCount == null ? 0 : element.unreadMessageCount;
"TargetUserId": item["targetUserId"], element.unreadMessageCount = val! + 1;
"isDelivered": true,
"isSeen": true,
} }
]; });
updateUserChatHistoryStatusAsync(data); // dynamic data = [
} // {
logger.d(items); // "userChatHistoryId": item["userChatHistoryId"],
// for (var user in searchedChats!) { // "TargetUserId": item["targetUserId"],
// if (user.id == items.first["id"]) { // "isDelivered": true,
// user.userStatus = items.first["userStatus"]; // "isSeen": true,
// }
// } // }
// notifyListeners();2 // ];
// updateUserChatHistoryStatusAsync(data);
}
notifyListeners();
} }
void changeStatus(List<Object?>? args) { void changeStatus(List<Object?>? args) {
@ -428,13 +511,14 @@ 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();
var msg = message.text; var msg = message.text;
SingleUserChatModel data = SingleUserChatModel( SingleUserChatModel data = SingleUserChatModel(
chatEventId: chatEventId, chatEventId: chatEventId,
chatSource: 1, chatSource: 1,
contant: msg, contant: msg,
contantNo: uuid.v4(), contantNo: uuid.v4(),
conversationId: uuid.v4(), conversationId: chatCID,
createdDate: DateTime.now(), createdDate: DateTime.now(),
currentUserId: AppState().chatDetails!.response!.id, currentUserId: AppState().chatDetails!.response!.id,
currentUserName: AppState().chatDetails!.response!.userName, currentUserName: AppState().chatDetails!.response!.userName,
@ -461,7 +545,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
notifyListeners(); notifyListeners();
String chatData = 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()}"}'; '{"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":"$chatCID"}';
await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]); await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
} }
@ -485,14 +569,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
if (isFileSelected && !isMsgReply) { if (isFileSelected && !isMsgReply) {
Utils.showLoading(context); 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); 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) {
logger.d("Normal Text Message With Reply"); // logger.d("Normal Text Message With Reply");
if (message.text == null || message.text.isEmpty) { if (message.text == null || message.text.isEmpty) {
return; return;
} }
@ -500,7 +584,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
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);
} }
if (isFileSelected && isMsgReply) { if (isFileSelected && isMsgReply) {
logger.d("Attachment Message With Reply"); // logger.d("Attachment Message With Reply");
Utils.showLoading(context); 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);
@ -665,22 +749,22 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
sFileType = ""; sFileType = "";
} }
void scrollListener() { // void scrollListener() {
_firstAutoscrollExecuted = true; // _firstAutoscrollExecuted = true;
if (scrollController.hasClients && scrollController.position.pixels == scrollController.position.maxScrollExtent) { // if (scrollController.hasClients && scrollController.position.pixels == scrollController.position.maxScrollExtent) {
_shouldAutoscroll = true; // _shouldAutoscroll = true;
} else { // } else {
_shouldAutoscroll = false; // _shouldAutoscroll = false;
} // }
} // }
//
void scrollToBottom() { // void scrollToBottom() {
scrollController.animateTo( // scrollController.animateTo(
scrollController.position.maxScrollExtent + 100, // scrollController.position.maxScrollExtent + 100,
duration: const Duration(milliseconds: 500), // duration: const Duration(milliseconds: 500),
curve: Curves.easeIn, // curve: Curves.easeIn,
); // );
} // }
void msgScroll() { void msgScroll() {
scrollController.animateTo( scrollController.animateTo(

@ -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/";

@ -1,117 +1,133 @@
class IncomingCallData { // To parse this JSON data, do
String? callerID; //
String? receiverID; // final callDataModel = callDataModelFromJson(jsonString);
String? msgID;
String? notfID; import 'dart:convert';
class CallDataModel {
CallDataModel({
this.callerId,
this.callReciverId,
this.notificationForeground,
this.message,
this.title,
this.type,
this.identity,
this.name,
this.isCall,
this.isWebrtc,
this.contant,
this.contantNo,
this.chatEventId,
this.fileTypeId,
this.currentUserId,
this.chatSource,
this.userChatHistoryLineRequestList,
this.server,
});
String? callerId;
String? callReciverId;
String? notificationForeground; String? notificationForeground;
String? count;
String? message; String? message;
String? appointmentNo;
String? title; String? title;
String? projectID;
String? notificationType;
String? background;
String? doctorname;
String? clinicname;
String? speciality;
String? appointmentdate;
String? appointmenttime;
String? type; String? type;
String? sessionId;
String? identity; String? identity;
String? name; String? name;
String? videoUrl;
String? picture;
String? token;
String? isCall; String? isCall;
String? sound; String? isWebrtc;
String? contant;
String? contantNo;
String? chatEventId;
dynamic? fileTypeId;
String? currentUserId;
String? chatSource;
List<UserChatHistoryLineRequestList>? userChatHistoryLineRequestList;
String? server; String? server;
String? isWebRTC;
IncomingCallData( factory CallDataModel.fromRawJson(String str) => CallDataModel.fromJson(json.decode(str));
{this.msgID,
this.notfID, String toRawJson() => json.encode(toJson());
this.notificationForeground,
this.count, factory CallDataModel.fromJson(Map<String, dynamic> json) => CallDataModel(
this.message, callerId: json["callerID"] == null ? null : json["callerID"],
this.appointmentNo, callReciverId: json["callReciverID"] == null ? null : json["callReciverID"],
this.title, notificationForeground: json["notification_foreground"] == null ? null : json["notification_foreground"],
this.projectID, message: json["message"] == null ? null : json["message"],
this.notificationType, title: json["title"] == null ? null : json["title"],
this.background, type: json["type"] == null ? null : json["type"],
this.doctorname, identity: json["identity"] == null ? null : json["identity"],
this.clinicname, name: json["name"] == null ? null : json["name"],
this.speciality, isCall: json["is_call"] == null ? null : json["is_call"],
this.appointmentdate, isWebrtc: json["is_webrtc"] == null ? null : json["is_webrtc"],
this.appointmenttime, contant: json["contant"] == null ? null : json["contant"],
this.type, contantNo: json["contantNo"] == null ? null : json["contantNo"],
this.sessionId, chatEventId: json["chatEventId"] == null ? null : json["chatEventId"],
this.identity, fileTypeId: json["fileTypeId"],
this.name, currentUserId: json["currentUserId"] == null ? null : json["currentUserId"],
this.videoUrl, chatSource: json["chatSource"] == null ? null : json["chatSource"],
this.picture, userChatHistoryLineRequestList: json["userChatHistoryLineRequestList"] == null
this.isCall, ? null
this.sound}); : List<UserChatHistoryLineRequestList>.from(
json["userChatHistoryLineRequestList"].map(
(x) => UserChatHistoryLineRequestList.fromJson(x),
),
),
server: json["server"] == null ? null : json["server"],
);
Map<String, dynamic> toJson() => {
"callerID": callerId == null ? null : callerId,
"callReciverID": callReciverId == null ? null : callReciverId,
"notification_foreground": notificationForeground == null ? null : notificationForeground,
"message": message == null ? null : message,
"title": title == null ? null : title,
"type": type == null ? null : type,
"identity": identity == null ? null : identity,
"name": name == null ? null : name,
"is_call": isCall == null ? null : isCall,
"is_webrtc": isWebrtc == null ? null : isWebrtc,
"contant": contant == null ? null : contant,
"contantNo": contantNo == null ? null : contantNo,
"chatEventId": chatEventId == null ? null : chatEventId,
"fileTypeId": fileTypeId,
"currentUserId": currentUserId == null ? null : currentUserId,
"chatSource": chatSource == null ? null : chatSource,
"userChatHistoryLineRequestList": userChatHistoryLineRequestList == null
? null
: List<dynamic>.from(
userChatHistoryLineRequestList!.map(
(x) => x.toJson(),
),
),
"server": server == null ? null : server,
};
}
class UserChatHistoryLineRequestList {
UserChatHistoryLineRequestList({
this.isSeen,
this.isDelivered,
this.targetUserId,
this.targetUserStatus,
});
bool? isSeen;
bool? isDelivered;
int? targetUserId;
int? targetUserStatus;
IncomingCallData.fromJson(Map<String, dynamic> json) { factory UserChatHistoryLineRequestList.fromJson(Map<String, dynamic> json) => UserChatHistoryLineRequestList(
callerID = json['callerID']; isSeen: json["isSeen"] == null ? null : json["isSeen"],
receiverID = json['PatientID']; isDelivered: json["isDelivered"] == null ? null : json["isDelivered"],
msgID = json['msgID']; targetUserId: json["targetUserId"] == null ? null : json["targetUserId"],
notfID = json['notfID']; targetUserStatus: json["targetUserStatus"] == null ? null : json["targetUserStatus"],
notificationForeground = json['notification_foreground']; );
count = json['count'];
message = json['message'];
appointmentNo = json['AppointmentNo'];
title = json['title'];
projectID = json['ProjectID'];
notificationType = json['NotificationType'];
background = json['background'];
doctorname = json['doctorname'];
clinicname = json['clinicname'];
speciality = json['speciality'];
appointmentdate = json['appointmentdate'];
appointmenttime = json['appointmenttime'];
type = json['type'];
sessionId = json['session_id'];
token = json['token'];
identity = json['identity'];
name = json['name'];
videoUrl = json['videoUrl'];
picture = json['picture'];
isCall = json['is_call'];
sound = json['sound'];
server = json['server'];
isWebRTC = json['is_webrtc'] ?? "true";
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() => {
Map<String, dynamic> data = Map<String, dynamic>(); "isSeen": isSeen == null ? null : isSeen,
data['msgID'] = this.msgID; "isDelivered": isDelivered == null ? null : isDelivered,
data['notfID'] = this.notfID; "targetUserId": targetUserId == null ? null : targetUserId,
data['notification_foreground'] = this.notificationForeground; "targetUserStatus": targetUserStatus == null ? null : targetUserStatus,
data['count'] = this.count; };
data['message'] = this.message;
data['AppointmentNo'] = this.appointmentNo;
data['title'] = this.title;
data['ProjectID'] = this.projectID;
data['NotificationType'] = this.notificationType;
data['background'] = this.background;
data['doctorname'] = this.doctorname;
data['clinicname'] = this.clinicname;
data['speciality'] = this.speciality;
data['appointmentdate'] = this.appointmentdate;
data['appointmenttime'] = this.appointmenttime;
data['type'] = this.type;
data['session_id'] = this.sessionId;
data['token'] = this.token;
data['identity'] = this.identity;
data['name'] = this.name;
data['videoUrl'] = this.videoUrl;
data['picture'] = this.picture;
data['is_call'] = this.isCall;
data['sound'] = this.sound;
data['server'] = this.server;
data['is_webrtc'] = this.isWebRTC;
return data;
}
} }

@ -7,7 +7,7 @@ import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/models/chat/call.dart'; import 'package:mohem_flutter_app/models/chat/call.dart';
class IncomingCall extends StatefulWidget { class IncomingCall extends StatefulWidget {
IncomingCallData incomingCallData; CallDataModel incomingCallData;
bool? isVideoCall; bool? isVideoCall;
IncomingCall({Key? key, required this.incomingCallData, this.isVideoCall}) : super(key: key); IncomingCall({Key? key, required this.incomingCallData, this.isVideoCall}) : super(key: key);

@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:ui'; import 'dart:ui';
import 'package:camera/camera.dart'; import 'package:camera/camera.dart';
@ -7,10 +8,11 @@ import 'package:flutter_svg/flutter_svg.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/classes/utils.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/models/chat/call.dart'; import 'package:mohem_flutter_app/models/chat/call.dart';
class OutGoingCall extends StatefulWidget { class OutGoingCall extends StatefulWidget {
IncomingCallData OutGoingCallData; CallDataModel OutGoingCallData;
bool? isVideoCall; bool? isVideoCall;
OutGoingCall({Key? key, required this.OutGoingCallData, this.isVideoCall}) : super(key: key); OutGoingCall({Key? key, required this.OutGoingCallData, this.isVideoCall}) : super(key: key);
@ -36,6 +38,7 @@ class _OutGoingCallState extends State<OutGoingCall> with SingleTickerProviderSt
milliseconds: 500, milliseconds: 500,
), ),
); );
logger.d(jsonEncode(widget.OutGoingCallData));
//_runAnimation(); //_runAnimation();
// connectSignaling(); // connectSignaling();
WidgetsBinding.instance.addPostFrameCallback( WidgetsBinding.instance.addPostFrameCallback(

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -10,6 +11,7 @@ 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/main.dart';
import 'package:mohem_flutter_app/models/chat/call.dart'; import 'package:mohem_flutter_app/models/chat/call.dart';
import 'package:mohem_flutter_app/ui/chat/call/chat_outgoing_call_screen.dart'; import 'package:mohem_flutter_app/ui/chat/call/chat_outgoing_call_screen.dart';
import 'package:mohem_flutter_app/ui/chat/chat_bubble.dart'; import 'package:mohem_flutter_app/ui/chat/chat_bubble.dart';
@ -17,6 +19,7 @@ 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';
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:signalr_netcore/signalr_client.dart';
import 'package:swipe_to/swipe_to.dart'; import 'package:swipe_to/swipe_to.dart';
class ChatDetailScreen extends StatefulWidget { class ChatDetailScreen extends StatefulWidget {
@ -55,13 +58,14 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
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);
if (userDetails != null) if (userDetails != null) {
data.getSingleUserChatHistory( data.getSingleUserChatHistory(
senderUID: AppState().chatDetails!.response!.id!.toInt(), senderUID: AppState().chatDetails!.response!.id!.toInt(),
receiverUID: userDetails["targetUser"].id, receiverUID: userDetails["targetUser"].id,
loadMore: false, loadMore: false,
isNewChat: userDetails["isNewChat"], isNewChat: userDetails["isNewChat"],
); );
}
return Scaffold( return Scaffold(
backgroundColor: const Color(0xFFF8F8F8), backgroundColor: const Color(0xFFF8F8F8),
@ -72,7 +76,10 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
actions: [ actions: [
IconButton( IconButton(
onPressed: () { onPressed: () {
makeCall("AUDIO"); // makeCall(
// callType: "AUDIO",
// con: data.hubConnection,
// );
}, },
icon: SvgPicture.asset( icon: SvgPicture.asset(
"assets/icons/chat/call.svg", "assets/icons/chat/call.svg",
@ -82,7 +89,10 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
), ),
IconButton( IconButton(
onPressed: () { onPressed: () {
makeCall("VIDEO"); // makeCall(
// callType: "VIDEO",
// con: data.hubConnection,
// );
}, },
icon: SvgPicture.asset( icon: SvgPicture.asset(
"assets/icons/chat/video_call.svg", "assets/icons/chat/video_call.svg",
@ -345,45 +355,34 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
); );
} }
void makeCall(String callType) async { void makeCall({required String callType, required HubConnection con}) async {
// final server = await SelectionDialog( print("================== Make call Triggered ============================");
// context, logger.d(jsonEncode(AppState().chatDetails!.response));
// title: "Select Server", Map<String, dynamic> json = {
// items: ["https://livecareturn.hmg.com:8086", "https://104.197.179.1:8086"] "callerID": AppState().chatDetails!.response!.id!.toString(),
// ).show(); "callReciverID": userDetails["targetUser"].id.toString(),
Map<String, String> json = {
"callerID": "9920",
"PatientID": "1231755",
"msgID": "123",
"notfID": "123",
"notification_foreground": "true", "notification_foreground": "true",
"count": "1", "message": "Aamir is calling ",
"message": "Doctor is calling ", "title": "Video Call",
"AppointmentNo": "123", "type": callType == "VIDEO" ? "Video" : "Audio",
"title": "Rayyan Hospital", "identity": "Aamir.Muhammad",
"ProjectID": "123", "name": "Aamir Saleem Ahmad",
"NotificationType": "10",
"background": "1",
"doctorname": "Dr Sulaiman Al Habib",
"clinicname": "ENT Clinic",
"speciality": "Speciality",
"appointmentdate": "Sun, 15th Dec, 2019",
"appointmenttime": "09:00",
"type": "video",
"session_id":
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTS2I2NjYyOWMzN2ZhOTM3YjFjNDI2Zjg1MTgyNWFmN2M0LTE1OTg3NzQ1MDYiLCJpc3MiOiJTS2I2NjYyOWMzN2ZhOTM3YjFjNDI2Zjg1MTgyNWFmN2M0Iiwic3ViIjoiQUNhYWQ1YTNmOGM2NGZhNjczNTY3NTYxNTc0N2YyNmMyYiIsImV4cCI6MTU5ODc3ODEwNiwiZ3JhbnRzIjp7ImlkZW50aXR5IjoiSGFyb29uMSIsInZpZGVvIjp7InJvb20iOiJTbWFsbERhaWx5U3RhbmR1cCJ9fX0.7XUS5uMQQJfkrBZu9EjQ6STL6R7iXkso6BtO1HmrQKk",
"identity": "Haroon1",
"name": "SmallDailyStandup",
"videoUrl": "video",
"picture": "video",
"is_call": "true", "is_call": "true",
"is_webrtc": "true", "is_webrtc": "true",
"contant": "Start video Call Aamir.Muhammad",
"contantNo": "775d1f11-62d9-6fcc-91f6-21f8c14559fb",
"chatEventId": "3",
"fileTypeId": null,
"currentUserId": "266642",
"chatSource": "1",
"userChatHistoryLineRequestList": [
{"isSeen": false, "isDelivered": false, "targetUserId": 341682, "targetUserStatus": 4}
],
// "server": "https://192.168.8.163:8086", // "server": "https://192.168.8.163:8086",
"server": "https://livecareturn.hmg.com:8086", "server": "https://livecareturn.hmg.com:8086",
}; };
IncomingCallData incomingCallData = IncomingCallData.fromJson(json); CallDataModel incomingCallData = CallDataModel.fromJson(json);
await Navigator.push( await Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(

@ -34,18 +34,18 @@ class _ChatHomeState extends State<ChatHome> {
// TODO: implement initState // TODO: implement initState
super.initState(); super.initState();
data = Provider.of<ChatProviderModel>(context, listen: false); data = Provider.of<ChatProviderModel>(context, listen: false);
data.getUserAutoLoginToken().then((Object? value) { data.getUserAutoLoginToken(context).whenComplete(() {
data.getUserRecentChats(); data.getUserRecentChats();
}); });
} }
@override @override
void dispose() { void dispose() {
super.dispose();
data.clearAll(); data.clearAll();
if (data.hubConInitialized) { if (data.hubConInitialized) {
data.hubConnection.stop(); data.hubConnection.stop();
} }
super.dispose();
} }
@override @override

@ -7,6 +7,7 @@ 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';
@ -134,26 +135,26 @@ 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 != null) if (m.searchedChats![index].unreadMessageCount! > 0)
// 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,
@ -192,6 +193,7 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
AppRoutes.chatDetailed, AppRoutes.chatDetailed,
arguments: {"targetUser": m.searchedChats![index], "isNewChat": false}, arguments: {"targetUser": m.searchedChats![index], "isNewChat": false},
).then((Object? value) { ).then((Object? value) {
// m.GetUserChatHistoryNotDeliveredAsync(userId: int.parse(AppState().chatDetails!.response!.id.toString()));
m.clearSelections(); m.clearSelections();
m.notifyListeners(); m.notifyListeners();
}); });

Loading…
Cancel
Save