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();
}
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;
if (!loadMore) paginationVal = 0;
isChatScreenActive = true;
@ -100,8 +100,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
token: AppState().chatDetails!.response!.token,
);
if (response.statusCode == 204) {
if (!loadMore) userChatHistory = [];
if (isNewChat) {
userChatHistory = [];
} else if (loadMore) {
// userChatHistory = [];
Utils.showToast("No More Data To Load");
}
} else {
if (loadMore) {
List<SingleUserChatModel> temp = getSingleUserChatModel(response.body);
@ -131,7 +135,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} else {
result = [];
}
} catch (e) {}
} catch (e) {
if (kDebugMode) {
print(e);
}
}
;
return result;
}
@ -139,11 +148,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true);
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(
Logger("Logs Enabled"),
)
.build();
.withAutomaticReconnect(
retryDelays: <int>[2000, 5000, 10000, 20000],
).build();
hubConnection.onclose(
({Exception? error}) {},
);
@ -157,6 +164,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
await hubConnection.start();
hubConnection.on("OnUpdateUserStatusAsync", changeStatus);
hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
hubConnection.on("OnSeenChatUserAsync", onChatSeen);
//hubConnection.on("OnUserTypingAsync", onUserTyping);
// 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) {
dynamic items = args!.toList();
//logger.d("---------------------------------User Count Async -------------------------------------");

@ -29,7 +29,7 @@ class ChatDetailScreen extends StatelessWidget {
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);
data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true, isNewChat: false);
}
await Future.delayed(const Duration(milliseconds: 1000));
_refreshController.refreshCompleted();
@ -39,7 +39,8 @@ class ChatDetailScreen extends StatelessWidget {
Widget build(BuildContext context) {
userDetails = ModalRoute.of(context)!.settings.arguments;
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);
return Scaffold(
backgroundColor: const Color(0xFFF8F8F8),

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

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

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

Loading…
Cancel
Save