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

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

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

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

@ -135,6 +135,22 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
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)
Flexible(
child: Container(
@ -193,7 +209,7 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
AppRoutes.chatDetailed,
arguments: {"targetUser": m.searchedChats![index], "isNewChat": false},
).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.notifyListeners();
});

Loading…
Cancel
Save