import 'package:flutter/material.dart'; import 'package:ftc_mobile_app/models/chat/combined_last_messages_model_class.dart'; import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart'; import 'package:ftc_mobile_app/view/screens/chat/arguments/group_data_args.dart'; import 'package:get/get.dart'; import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart'; import '../../ftc_mobile_app.dart'; import '../../web_services/chat_services.dart'; class InboxScreenController extends GetxController { final GlobalKey screenKey = GlobalKey(); // CombinedMessageModel combinedMessageModel = CombinedMessageModel.empty(); final String privacyPolicy = "A quick preview of the text will be shown here. A quick preview of the text will be shown here. shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here.\n shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here.\n shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here. A quick preview of the text will be shown here."; final checkBoxValue = false.obs; final chatsAndGroups = RxList(); // final sortedChatsAndGroups = RxList(); final canLoadMore = RxBool(false); final onFirstMessageSend = false.obs; // late IO.Socket socket; // final int _limit = 20; // int _skip = 0; bool loadingMore = false; final _listRC = RefreshController(initialRefresh: false); RefreshController get listRC => _listRC; final _listSC = ScrollController(); ScrollController get listSC => _listSC; String myId = ""; @override void onInit() { //Getting my ID // String userJson = LocalStorageManager.getSessionToken( // tokenKey: LocalStorageKeys.kUserModelKey, // ); // UserModel userModel = UserModel.fromJson(json.decode(userJson)); myId = LocalStorageManager.userId; onFirstMessageSend.listen((isTrue) { if (isTrue) { onFirstMessageSend(false); getChatsAndGroupsList(); } }); super.onInit(); } @override void onReady() { // connect(); getChatsAndGroupsList(); super.onReady(); } void onBackButtonPressed() { Get.delete(); Navigator.pop(screenKey.currentState!.context); } // void showPrivacyDialog() { // showDialog( // context: screenKey.currentState!.context, // builder: (BuildContext context) { // return PrivacyPolicyDialog( // privacyPolicy: privacyPolicy, // checkBoxOnChange: (value) { // checkBoxValue.value = value; // }, // ); // }, // ); // } void onRefresh() async { await getChatsAndGroupsList(); _listRC.refreshCompleted(); } void onLoading() async { // if (!loadingMore) { // await _loadMore(); // } _listRC.loadComplete(); } void removeFocus() { FocusScope.of(screenKey.currentContext!).unfocus(); } Future getChatsAndGroupsList() async { final resp = await ChatService().combinedLastMessage(userId: myId).showLoader(); if (resp is CombinedMessageModel) { List messages = []; //Private Messages transform for (final e in resp.personalMessage) { messages.add( MessagesListModel( otherUserId: (e.senderId == myId) ? e.recieverId : e.senderId, image: e.image, title: e.name, previewOfLastMessage: e.message, messageType: e.messageType, date: DateTime.tryParse(e.date)?.millisecondsSinceEpoch ?? DateTime.now().millisecondsSinceEpoch, // messageDateTime: FrequentFunctions.toTimesAgo(e.date), // personalMessageIndex: index, ), ); } //Group Messages transform for (final e in resp.sortedArrayGroup) { messages.add( MessagesListModel( image: e.groupImage, title: e.groupName, previewOfLastMessage: e.lastMessages.message, messageType: MessageType.message.name, // messageType: e.lastMessages.messageType ?? MessageType.message.name, date: DateTime.tryParse(e.date)?.millisecondsSinceEpoch ?? DateTime.now().millisecondsSinceEpoch, // messageDateTime: FrequentFunctions.toTimesAgo(e.date), isGroup: true, groupData: GroupDataArgs( groupId: e.id, groupMembersIds: e.groupMembers, scheduleTime: e.groupWorkingScheduleTime, ), ), ); } chatsAndGroups.value = messages; } else { FrequentFunctions.showToast(message: resp["message"]); } } @override void dispose() { Get.delete(); super.dispose(); } }