Chat Updates & Counter Event Modifications

merge-requests/69/head
Aamir Muhammad 3 years ago
parent ab5de25c81
commit f4f9b442c8

@ -115,6 +115,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
searchedChats = pChatHistory; searchedChats = pChatHistory;
isLoading = false; isLoading = false;
getUserChatHistoryNotDeliveredAsync(
userId: int.parse(
AppState().chatDetails!.response!.id.toString(),
),
);
notifyListeners(); notifyListeners();
} }
@ -122,6 +127,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
await hubConnection.invoke( await hubConnection.invoke(
"GetUserChatHistoryNotDeliveredAsync", "GetUserChatHistoryNotDeliveredAsync",
args: [userId], args: [userId],
).onError(
(Error error, StackTrace stackTrace) => {
logger.d(error),
},
); );
return ""; return "";
} }
@ -220,8 +229,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
'${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatMediaImageUploadUrl}', '${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatMediaImageUploadUrl}',
), ),
); );
request.fields.addAll({'userId': userId, 'fileSource': '1'}); request.fields.addAll(
request.files.add(await MultipartFile.fromPath('files', file.path)); {'userId': userId, 'fileSource': '1'},
);
request.files.add(
await MultipartFile.fromPath(
'files',
file.path,
),
);
request.headers.addAll( request.headers.addAll(
{ {
'Authorization': 'Bearer ${AppState().chatDetails!.response!.token}', 'Authorization': 'Bearer ${AppState().chatDetails!.response!.token}',
@ -256,7 +272,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
options: httpOp, options: httpOp,
) )
.withAutomaticReconnect( .withAutomaticReconnect(
retryDelays: <int>[2000, 5000, 10000, 20000], retryDelays: <int>[
2000,
5000,
10000,
20000,
],
) )
.configureLogging( .configureLogging(
Logger("Loggin"), Logger("Loggin"),
@ -273,11 +294,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
); );
if (hubConnection.state != HubConnectionState.Connected) { if (hubConnection.state != HubConnectionState.Connected) {
await hubConnection.start(); await hubConnection.start();
getUserChatHistoryNotDeliveredAsync( print("Connnnnn Stablished");
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);
@ -343,21 +360,15 @@ 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((element) { searchedChats!.forEach(
if (element.id == item["currentUserId"]) { (ChatUser element) {
var val = element.unreadMessageCount == null ? 0 : element.unreadMessageCount; if (element.id == item["currentUserId"]) {
element.unreadMessageCount = val! + 1; int? val = element.unreadMessageCount ?? 0;
} element.unreadMessageCount = val! + 1;
}); }
// dynamic data = [ element.isLoadingCounter = false;
// { },
// "userChatHistoryId": item["userChatHistoryId"], );
// "TargetUserId": item["targetUserId"],
// "isDelivered": true,
// "isSeen": true,
// }
// ];
// updateUserChatHistoryStatusAsync(data);
} }
notifyListeners(); notifyListeners();
} }

@ -7,7 +7,7 @@ import 'dart:convert';
class CallDataModel { class CallDataModel {
CallDataModel({ CallDataModel({
this.callerId, this.callerId,
this.callReciverId, this.callReceiverID,
this.notificationForeground, this.notificationForeground,
this.message, this.message,
this.title, this.title,
@ -27,7 +27,7 @@ class CallDataModel {
}); });
String? callerId; String? callerId;
String? callReciverId; String? callReceiverID;
String? notificationForeground; String? notificationForeground;
String? message; String? message;
String? title; String? title;
@ -51,7 +51,7 @@ class CallDataModel {
factory CallDataModel.fromJson(Map<String, dynamic> json) => CallDataModel( factory CallDataModel.fromJson(Map<String, dynamic> json) => CallDataModel(
callerId: json["callerID"] == null ? null : json["callerID"], callerId: json["callerID"] == null ? null : json["callerID"],
callReciverId: json["callReciverID"] == null ? null : json["callReciverID"], callReceiverID: json["callReceiverID"] == null ? null : json["callReceiverID"],
notificationForeground: json["notification_foreground"] == null ? null : json["notification_foreground"], notificationForeground: json["notification_foreground"] == null ? null : json["notification_foreground"],
message: json["message"] == null ? null : json["message"], message: json["message"] == null ? null : json["message"],
title: json["title"] == null ? null : json["title"], title: json["title"] == null ? null : json["title"],
@ -78,7 +78,7 @@ class CallDataModel {
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"callerID": callerId == null ? null : callerId, "callerID": callerId == null ? null : callerId,
"callReciverID": callReciverId == null ? null : callReciverId, "callReceiverID": callReceiverID == null ? null : callReceiverID,
"notification_foreground": notificationForeground == null ? null : notificationForeground, "notification_foreground": notificationForeground == null ? null : notificationForeground,
"message": message == null ? null : message, "message": message == null ? null : message,
"title": title == null ? null : title, "title": title == null ? null : title,

@ -19,21 +19,21 @@ class ChatUserModel {
} }
class ChatUser { class ChatUser {
ChatUser({ ChatUser(
this.id, {this.id,
this.userName, this.userName,
this.email, this.email,
this.phone, this.phone,
this.title, this.title,
this.userStatus, this.userStatus,
this.image, this.image,
this.unreadMessageCount, this.unreadMessageCount,
this.userAction, this.userAction,
this.isPin, this.isPin,
this.isFav, this.isFav,
this.isAdmin, this.isAdmin,
this.isTyping, this.isTyping,
}); this.isLoadingCounter});
int? id; int? id;
String? userName; String? userName;
@ -48,6 +48,7 @@ class ChatUser {
bool? isFav; bool? isFav;
bool? isAdmin; bool? isAdmin;
bool? isTyping; bool? isTyping;
bool? isLoadingCounter;
factory ChatUser.fromJson(Map<String, dynamic> json) => ChatUser( factory ChatUser.fromJson(Map<String, dynamic> json) => ChatUser(
id: json["id"] == null ? null : json["id"], id: json["id"] == null ? null : json["id"],
@ -63,6 +64,7 @@ class ChatUser {
isFav: json["isFav"] == null ? null : json["isFav"], isFav: json["isFav"] == null ? null : json["isFav"],
isAdmin: json["isAdmin"] == null ? null : json["isAdmin"], isAdmin: json["isAdmin"] == null ? null : json["isAdmin"],
isTyping: false, isTyping: false,
isLoadingCounter: true,
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {

@ -38,13 +38,14 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
void getMoreChat() async { void getMoreChat() async {
if (userDetails != null) { if (userDetails != null) {
data.paginationVal = data.paginationVal + 10; data.paginationVal = data.paginationVal + 10;
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: true, loadMore: true,
isNewChat: false, isNewChat: false,
); );
}
} }
await Future.delayed( await Future.delayed(
const Duration( const Duration(
@ -76,10 +77,10 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
actions: [ actions: [
IconButton( IconButton(
onPressed: () { onPressed: () {
// makeCall( makeCall(
// callType: "AUDIO", callType: "AUDIO",
// con: data.hubConnection, con: data.hubConnection,
// ); );
}, },
icon: SvgPicture.asset( icon: SvgPicture.asset(
"assets/icons/chat/call.svg", "assets/icons/chat/call.svg",
@ -89,10 +90,10 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
), ),
IconButton( IconButton(
onPressed: () { onPressed: () {
// makeCall( makeCall(
// callType: "VIDEO", callType: "VIDEO",
// con: data.hubConnection, con: data.hubConnection,
// ); );
}, },
icon: SvgPicture.asset( icon: SvgPicture.asset(
"assets/icons/chat/video_call.svg", "assets/icons/chat/video_call.svg",
@ -357,38 +358,41 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
void makeCall({required String callType, required HubConnection con}) async { void makeCall({required String callType, required HubConnection con}) async {
print("================== Make call Triggered ============================"); print("================== Make call Triggered ============================");
logger.d(jsonEncode(AppState().chatDetails!.response));
Map<String, dynamic> json = { Map<String, dynamic> json = {
"callerID": AppState().chatDetails!.response!.id!.toString(), "callerID": AppState().chatDetails!.response!.id!.toString(),
"callReciverID": userDetails["targetUser"].id.toString(), "callReceiverID": userDetails["targetUser"].id.toString(),
"notification_foreground": "true", "notification_foreground": "true",
"message": "Aamir is calling ", "message": "Aamir is calling",
"title": "Video Call", "title": "Video Call",
"type": callType == "VIDEO" ? "Video" : "Audio", "type": callType == "VIDEO" ? "Video" : "Audio",
"identity": "Aamir.Muhammad", "identity": AppState().chatDetails!.response!.userName,
"name": "Aamir Saleem Ahmad", "name": AppState().chatDetails!.response!.title,
"is_call": "true", "is_call": "true",
"is_webrtc": "true", "is_webrtc": "true",
"contant": "Start video Call Aamir.Muhammad", "contant": "Start video Call ${AppState().chatDetails!.response!.userName}",
"contantNo": "775d1f11-62d9-6fcc-91f6-21f8c14559fb", "contantNo": "775d1f11-62d9-6fcc-91f6-21f8c14559fb",
"chatEventId": "3", "chatEventId": "3",
"fileTypeId": null, "fileTypeId": null,
"currentUserId": "266642", "currentUserId": AppState().chatDetails!.response!.id!.toString(),
"chatSource": "1", "chatSource": "1",
"userChatHistoryLineRequestList": [ "userChatHistoryLineRequestList": [
{"isSeen": false, "isDelivered": false, "targetUserId": 341682, "targetUserStatus": 4} {
"isSeen": false,
"isDelivered": false,
"targetUserId": userDetails["targetUser"].id,
"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",
}; };
CallDataModel callData = CallDataModel.fromJson(json);
CallDataModel incomingCallData = CallDataModel.fromJson(json);
await Navigator.push( await Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) => OutGoingCall( builder: (BuildContext context) => OutGoingCall(
isVideoCall: callType == "VIDEO" ? true : false, isVideoCall: callType == "VIDEO" ? true : false,
OutGoingCallData: incomingCallData, OutGoingCallData: callData,
), ),
), ),
); );

@ -135,6 +135,22 @@ 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].isLoadingCounter!)
Flexible(
child: Container(
padding: EdgeInsets.zero,
alignment: Alignment.centerRight,
width: 18,
height: 18,
decoration: const BoxDecoration(
// color: MyColors.redColor,
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
child: CircularProgressIndicator(),
),
),
if (m.searchedChats![index].unreadMessageCount! > 0) if (m.searchedChats![index].unreadMessageCount! > 0)
Flexible( Flexible(
child: Container( child: Container(
@ -193,7 +209,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.GetUserChatHistoryNotDeliveredAsync(userId: int.parse(AppState().chatDetails!.response!.id.toString()));
m.clearSelections(); m.clearSelections();
m.notifyListeners(); m.notifyListeners();
}); });

Loading…
Cancel
Save