Chat Favorite Screen & Fixes

merge-requests/55/head
Aamir Muhammad 2 years ago
parent ca4c9584b9
commit 5412dcaf35

@ -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?;

@ -1,8 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/api/chat/chat_provider_model.dart';
@ -23,14 +20,14 @@ class ChatDetailScreen extends StatelessWidget {
dynamic userDetails;
late ChatProviderModel data;
ScrollController scrollController = ScrollController();
RefreshController _refreshController = RefreshController(initialRefresh: false);
final RefreshController _refreshController = RefreshController(initialRefresh: false);
void getMoreChat() async {
if (userDetails != null) {
data.paginationVal = data.paginationVal + 10;
data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true);
}
await Future.delayed(Duration(milliseconds: 1000));
await Future.delayed(const Duration(milliseconds: 1000));
_refreshController.refreshCompleted();
}
@ -61,6 +58,7 @@ class ChatDetailScreen extends StatelessWidget {
child: ListView.builder(
controller: scrollController,
shrinkWrap: true,
reverse: false,
itemCount: m.userChatHistory.length,
padding: const EdgeInsets.only(top: 20),
itemBuilder: (BuildContext context, int i) {
@ -137,10 +135,11 @@ class ChatDetailScreen extends StatelessWidget {
height: 200,
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage(
m.selectedFile,
),
fit: BoxFit.cover),
image: FileImage(
m.selectedFile,
),
fit: BoxFit.cover,
),
borderRadius: const BorderRadius.all(
Radius.circular(0),
),

Loading…
Cancel
Save