Chat Favorite Screen & Fixes

merge-requests/55/head
Aamir Muhammad 3 years ago
parent b8e20633c9
commit fb54403584

@ -91,7 +91,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
notifyListeners(); notifyListeners();
} }
void getSingleUserChatHistory({required String senderUID, required int receiverUID, required bool loadMore}) async { void getSingleUserChatHistory({required String senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false}) async {
isLoading = true; isLoading = true;
if (!loadMore) paginationVal = 0; if (!loadMore) paginationVal = 0;
isChatScreenActive = true; isChatScreenActive = true;
@ -100,8 +100,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
token: AppState().chatDetails!.response!.token, token: AppState().chatDetails!.response!.token,
); );
if (response.statusCode == 204) { if (response.statusCode == 204) {
if (!loadMore) userChatHistory = []; if (isNewChat) {
Utils.showToast("No More Data To Load"); userChatHistory = [];
} else if (loadMore) {
// userChatHistory = [];
Utils.showToast("No More Data To Load");
}
} else { } else {
if (loadMore) { if (loadMore) {
List<SingleUserChatModel> temp = getSingleUserChatModel(response.body); List<SingleUserChatModel> temp = getSingleUserChatModel(response.body);
@ -131,7 +135,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} else { } else {
result = []; result = [];
} }
} catch (e) {} } catch (e) {
if (kDebugMode) {
print(e);
}
}
;
return result; return result;
} }
@ -139,11 +148,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true);
hubConnection = HubConnectionBuilder() hubConnection = HubConnectionBuilder()
.withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp) .withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp)
.withAutomaticReconnect(retryDelays: [2000, 5000, 10000, 20000]) .withAutomaticReconnect(
.configureLogging( retryDelays: <int>[2000, 5000, 10000, 20000],
Logger("Logs Enabled"), ).build();
)
.build();
hubConnection.onclose( hubConnection.onclose(
({Exception? error}) {}, ({Exception? error}) {},
); );
@ -157,6 +164,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
await hubConnection.start(); await hubConnection.start();
hubConnection.on("OnUpdateUserStatusAsync", changeStatus); hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
hubConnection.on("OnSeenChatUserAsync", onChatSeen);
//hubConnection.on("OnUserTypingAsync", onUserTyping); //hubConnection.on("OnUserTypingAsync", onUserTyping);
// hubConnection.on("OnUserCountAsync", userCountAsync); // hubConnection.on("OnUserCountAsync", userCountAsync);
@ -179,6 +187,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
} }
void onChatSeen(List<Object?>? args) {
dynamic items = args!.toList();
logger.d("---------------------------------Chat Seen -------------------------------------");
logger.d(items);
// for (var user in searchedChats!) {
// if (user.id == items.first["id"]) {
// user.userStatus = items.first["userStatus"];
// }
// }
// notifyListeners();
}
void userCountAsync(List<Object?>? args) { void userCountAsync(List<Object?>? args) {
dynamic items = args!.toList(); dynamic items = args!.toList();
//logger.d("---------------------------------User Count Async -------------------------------------"); //logger.d("---------------------------------User Count Async -------------------------------------");

@ -29,7 +29,7 @@ class ChatDetailScreen extends StatelessWidget {
void getMoreChat() async { void getMoreChat() async {
if (userDetails != null) { if (userDetails != null) {
data.paginationVal = data.paginationVal + 10; data.paginationVal = data.paginationVal + 10;
data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true); data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true, isNewChat: false);
} }
await Future.delayed(const Duration(milliseconds: 1000)); await Future.delayed(const Duration(milliseconds: 1000));
_refreshController.refreshCompleted(); _refreshController.refreshCompleted();
@ -39,7 +39,8 @@ class ChatDetailScreen extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
userDetails = ModalRoute.of(context)!.settings.arguments; userDetails = ModalRoute.of(context)!.settings.arguments;
data = Provider.of<ChatProviderModel>(context, listen: false); data = Provider.of<ChatProviderModel>(context, listen: false);
if (userDetails != null) data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: false); if (userDetails != null)
data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: false, isNewChat: userDetails["isNewChat"]);
data.scrollController.addListener(data.scrollListener); data.scrollController.addListener(data.scrollListener);
return Scaffold( return Scaffold(
backgroundColor: const Color(0xFFF8F8F8), backgroundColor: const Color(0xFFF8F8F8),

@ -144,7 +144,7 @@ class ChatHomeScreen extends StatelessWidget {
Navigator.pushNamed( Navigator.pushNamed(
context, context,
AppRoutes.chatDetailed, AppRoutes.chatDetailed,
arguments: {"targetUser": m.searchedChats![index]}, arguments: {"targetUser": m.searchedChats![index], "isNewChat" : false},
).then((Object? value) { ).then((Object? value) {
m.clearSelections(); m.clearSelections();
}); });

@ -71,7 +71,7 @@ class ChatFavoriteUsersScreen extends StatelessWidget {
Navigator.pushNamed( Navigator.pushNamed(
context, context,
AppRoutes.chatDetailed, AppRoutes.chatDetailed,
arguments: {"targetUser": m.favUsersList![index]}, arguments: {"targetUser": m.favUsersList![index], "isNewChat": false},
).then( ).then(
(Object? value) { (Object? value) {
m.clearSelections(); m.clearSelections();

@ -233,7 +233,7 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
Navigator.pushNamed( Navigator.pushNamed(
context, context,
AppRoutes.chatDetailed, AppRoutes.chatDetailed,
arguments: {"targetUser": chatUsersList![index]}, arguments: {"targetUser": chatUsersList![index], "isNewChat": true},
); );
}, },
onLongPress: () {}, onLongPress: () {},

Loading…
Cancel
Save