|
|
|
@ -60,8 +60,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
"${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatRecentUrl}",
|
|
|
|
|
token: AppState().chatDetails!.response!.token,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//logger.d(AppState().chatDetails!.response!.token);
|
|
|
|
|
ChatUserModel recentChat = userToList(response.body);
|
|
|
|
|
|
|
|
|
|
Response favRes = await ApiClient().getJsonForResponse(
|
|
|
|
@ -71,6 +69,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
ChatUserModel favUList = userToList(favRes.body);
|
|
|
|
|
if (favUList.response != null) {
|
|
|
|
|
favUsersList = favUList.response!;
|
|
|
|
|
favUsersList.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase()));
|
|
|
|
|
for (dynamic user in recentChat.response!) {
|
|
|
|
|
for (dynamic favUser in favUList.response!) {
|
|
|
|
|
if (user.id == favUser.id) {
|
|
|
|
@ -80,7 +79,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pChatHistory = recentChat.response;
|
|
|
|
|
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;
|
|
|
|
|
isLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
@ -94,8 +93,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
"${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatSingleUserHistoryUrl}/$senderUID/$receiverUID/$paginationVal",
|
|
|
|
|
token: AppState().chatDetails!.response!.token,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
logger.d(response.body);
|
|
|
|
|
if (response.statusCode == 204) {
|
|
|
|
|
if (!loadMore) userChatHistory = [];
|
|
|
|
|
Utils.showToast("No More Data To Load");
|
|
|
|
@ -134,7 +131,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
Future<void> buildHubConnection() async {
|
|
|
|
|
HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true);
|
|
|
|
|
hubConnection = await HubConnectionBuilder()
|
|
|
|
|
hubConnection = HubConnectionBuilder()
|
|
|
|
|
.withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp)
|
|
|
|
|
.withAutomaticReconnect(retryDelays: [2000, 5000, 10000, 20000])
|
|
|
|
|
.configureLogging(
|
|
|
|
@ -162,8 +159,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
|
|
|
|
|
hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
|
|
|
|
|
}
|
|
|
|
|
isLoading = false;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
// notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateUserChatStatus(List<Object?>? args) {
|
|
|
|
@ -171,7 +167,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
for (dynamic cItem in items[0]) {
|
|
|
|
|
for (SingleUserChatModel chat in userChatHistory) {
|
|
|
|
|
if (chat.userChatHistoryId.toString() == cItem["userChatHistoryId"].toString()) {
|
|
|
|
|
logger.d(jsonEncode(chat));
|
|
|
|
|
chat.isSeen = cItem["isSeen"];
|
|
|
|
|
chat.isDelivered = cItem["isDelivered"];
|
|
|
|
|
notifyListeners();
|
|
|
|
@ -182,7 +177,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
|
|
|
|
|
void userCountAsync(List<Object?>? args) {
|
|
|
|
|
List items = args!.toList();
|
|
|
|
|
//print("---------------------------------User Count Async -------------------------------------");
|
|
|
|
|
//logger.d("---------------------------------User Count Async -------------------------------------");
|
|
|
|
|
//logger.d(items);
|
|
|
|
|
// for (var user in searchedChats!) {
|
|
|
|
|
// if (user.id == items.first["id"]) {
|
|
|
|
@ -256,13 +251,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
|
|
|
|
|
}
|
|
|
|
|
userChatHistory.add(data.first);
|
|
|
|
|
notifyListeners();
|
|
|
|
|
logger.d(isChatScreenActive);
|
|
|
|
|
// if (isChatScreenActive) scrollDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onUserTyping(List<Object?>? parameters) {
|
|
|
|
|
print("==================== Typing Active ==================");
|
|
|
|
|
logger.d(parameters);
|
|
|
|
|
// print("==================== Typing Active ==================");
|
|
|
|
|
// logger.d(parameters);
|
|
|
|
|
for (ChatUser user in searchedChats!) {
|
|
|
|
|
if (user.id == parameters![1] && parameters[0] == true) {
|
|
|
|
|
user.isTyping = parameters[0] as bool?;
|
|
|
|
|