Chat Count Api / Chat Token Updates / Chat Call UI

merge-requests/57/head
Aamir Muhammad 3 years ago
parent d7c0ef7bfb
commit 44d76f0687

@ -109,7 +109,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
notifyListeners();
}
void getSingleUserChatHistory({required String senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false}) async {
Future GetUserChatHistoryNotDeliveredAsync(int userId) async {
await hubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]);
return "";
}
void getSingleUserChatHistory({required int senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false}) async {
isLoading = true;
if (isNewChat) userChatHistory = [];
if (!loadMore) paginationVal = 0;
@ -134,9 +139,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
}
}
isLoading = false;
await GetUserChatHistoryNotDeliveredAsync(senderUID);
notifyListeners();
}
void updateUserChatHistoryStatusAsync(List data) {
hubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
}
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));
@ -170,7 +180,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
.withAutomaticReconnect(
retryDelays: <int>[2000, 5000, 10000, 20000],
)
.configureLogging(Logger("Loggin"))
.configureLogging(
Logger("Loggin"),
)
.build();
hubConnection.onclose(
({Exception? error}) {},
@ -188,11 +200,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
// hubConnection.on("OnSeenChatUserAsync", onChatSeen);
//hubConnection.on("OnUserTypingAsync", onUserTyping);
// hubConnection.on("OnUserCountAsync", userCountAsync);
hubConnection.on("OnUserCountAsync", userCountAsync);
hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
}
}
@ -223,6 +234,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void userCountAsync(List<Object?>? args) {
dynamic items = args!.toList();
// logger.d(items);
//logger.d("---------------------------------User Count Async -------------------------------------");
//logger.d(items);
// for (var user in searchedChats!) {
@ -247,10 +259,17 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void chatNotDelivered(List<Object?>? args) {
dynamic items = args!.toList();
if (kDebugMode) {
print("--------------------------------- Chat Not Delivered Windows Async -------------------------------------");
for (dynamic item in items[0]) {
dynamic data = [
{
"userChatHistoryId": item["userChatHistoryId"],
"TargetUserId": item["targetUserId"],
"isDelivered": true,
"isSeen": true,
}
];
updateUserChatHistoryStatusAsync(data);
}
logger.d(items);
// for (var user in searchedChats!) {
// if (user.id == items.first["id"]) {
// user.userStatus = items.first["userStatus"];
@ -289,7 +308,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
}
Future<void> onMsgReceived(List<Object?>? parameters) async {
print("msg Received");
List<SingleUserChatModel> data = [];
List<SingleUserChatModel> temp = [];
for (dynamic msg in parameters!) {
@ -307,6 +325,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
// element.unreadMessageCount = val! + 1;
// }
// });
logger.d(jsonEncode(data));
var list = [
{
"userChatHistoryId": data.first.userChatHistoryId,
"TargetUserId": data.first.targetUserId,
"isDelivered": true,
"isSeen": isChatScreenActive ? true : false,
}
];
updateUserChatHistoryStatusAsync(list);
notifyListeners();
// if (isChatScreenActive) scrollToBottom();
}

@ -36,7 +36,7 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
data.paginationVal = data.paginationVal + 10;
if (userDetails != null)
data.getSingleUserChatHistory(
senderUID: AppState().chatDetails!.response!.id.toString(),
senderUID: AppState().chatDetails!.response!.id!.toInt(),
receiverUID: userDetails["targetUser"].id,
loadMore: true,
isNewChat: false,
@ -56,11 +56,12 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
data = Provider.of<ChatProviderModel>(context, listen: false);
if (userDetails != null)
data.getSingleUserChatHistory(
senderUID: AppState().chatDetails!.response!.id.toString(),
senderUID: AppState().chatDetails!.response!.id!.toInt(),
receiverUID: userDetails["targetUser"].id,
loadMore: false,
isNewChat: userDetails["isNewChat"],
);
return Scaffold(
backgroundColor: const Color(0xFFF8F8F8),
appBar: AppBarWidget(context,

Loading…
Cancel
Save