// import 'package:flutter/material.dart'; // import 'package:get_it/get_it.dart'; // // import '../../models/chat/message_list_model.dart'; // import '../../models/chat/message_model.dart'; // import '../../services/chat/message_services.dart'; // import '../../utils/connection.dart'; // // class Message { // // String imageSender; // // String senderName; // // String address; // // String sendAt; // // bool seen; // // bool isMe; // // // // Message( // // {required this.imageSender, // // required this.senderName, // // required this.address, // // required this.sendAt, // // required this.seen, // // required this.isMe}); // // } // // class UserConversation extends ChangeNotifier { // List messagesList = []; // List allConversations = []; // String currentChatId = ""; // int notificationCount = 0; // bool showNotif = false; // MessageService get service => GetIt.I(); // bool loader = false; // static final userConversation = UserConversation._internal(); // // factory UserConversation() { // return userConversation; // } // // void addMessage(MessageModel message) { // messagesList.add(message); // notifyListeners(); // } // // fetchMessagesParId(int id) async { // if (await Connection.checkConnection()) { // // loader = true; // notifyListeners(); // try { // final fetchCategoryResult = await service.getMessageParId(id); // if ((fetchCategoryResult.statusCode == 200 || // fetchCategoryResult.statusCode == 201) && // fetchCategoryResult.data != null) { // // //print(fetchProfileResult.data!.result!.length); // // loader = false; // notifyListeners(); // } else { // loader = false; // notifyListeners(); // } // } catch (e, stackTrace) { // loader = false; // notifyListeners(); // } // } else { // /// No Internet Connection // loader = false; // notifyListeners(); // } // } // // Future fetchChatMessages(int senderId, int recipientId) async { // if (await Connection.checkConnection()) { // loader = true; // notifyListeners(); // try { // final fetchCategoryResult = // await service.getChatMessages(senderId, recipientId); // if ((fetchCategoryResult.statusCode == 200 || // fetchCategoryResult.statusCode == 201) && // fetchCategoryResult.data != null) { // final finished= addMessagesToCurrentConversation(fetchCategoryResult.data!.messages!); // //print("------------> $finished"); // loader = false; // notifyListeners(); // return true; // // } else { // // loader = false; // notifyListeners(); // return false; // } // } catch (e, stackTrace) { // loader = false; // notifyListeners(); // return false; // } // } else { // /// No Internet Connection // loader = false; // notifyListeners(); // return false; // } // } // // fetchNewMessagesCount(int senderId, int recipientId) async { // if (await Connection.checkConnection()) { // loader = true; // notifyListeners(); // try { // final fetchCategoryResult = // await service.countNewMessages(senderId, recipientId); // if ((fetchCategoryResult.statusCode == 200 || // fetchCategoryResult.statusCode == 201) && // fetchCategoryResult.data != null) { // loader = false; // notifyListeners(); // } else { // loader = false; // notifyListeners(); // } // } catch (e, stackTrace) { // loader = false; // notifyListeners(); // } // } else { // /// No Internet Connection // loader = false; // notifyListeners(); // } // } // // fetchAllChatRooms(int myId) async { // if (await Connection.checkConnection()) { // loader = true; // notifyListeners(); // try { // final fetchCategoryResult = await service.getAllChatRooms(myId); // if ((fetchCategoryResult.statusCode == 200 || // fetchCategoryResult.statusCode == 201) && // fetchCategoryResult.data != null) { // // //print(fetchProfileResult.data!.result!.length); // getAllConversations(fetchCategoryResult.data!.messagelist!); // // for (var conversation in allConversations) { // final result = await service.countNewMessages( // conversation.chatroom!.sender!.id!, // conversation.chatroom!.recipient!.id!); // setConversationCount(message: conversation, count: result.data!); // } // //print(allConversations.length); // loader = false; // notifyListeners(); // } else { // loader = false; // notifyListeners(); // } // } catch (e, stackTrace) { // loader = false; // notifyListeners(); // } // } else { // /// No Internet Connection // loader = false; // notifyListeners(); // } // } // // markAsSeen(int senderId, int recipientId) async { // if (await Connection.checkConnection()) { // loader = true; // notifyListeners(); // try { // final fetchCategoryResult = // await service.seenAllMessages(senderId, recipientId); // if ((fetchCategoryResult.statusCode == 200 || // fetchCategoryResult.statusCode == 201) && // fetchCategoryResult.data != null) { // loader = false; // notifyListeners(); // } else { // loader = false; // notifyListeners(); // } // } catch (e, stackTrace) { // loader = false; // notifyListeners(); // } // } else { // /// No Internet Connection // loader = false; // notifyListeners(); // } // } // // setCurrentChatId(String id) { // currentChatId = id; // notifyListeners(); // } // // bool addMessagesToCurrentConversation(List msg) { // loader = true; // notifyListeners(); // //messagesList.addAll(msg); // for (var element in msg) { // if (!messagesList.contains(element)) { // messagesList.add(element); // messagesList.sort((a, b) => // DateTime.fromMillisecondsSinceEpoch(a.timestamp!) // .compareTo(DateTime.fromMillisecondsSinceEpoch(b.timestamp!))); // } // } // // loader = false; // notifyListeners(); // return true; // } // // addOneMessage(MessageModel messageModel) { // if (!messagesList.contains(messageModel)) { // messagesList.add(messageModel); // messagesList.sort((a, b) => // DateTime.fromMillisecondsSinceEpoch(a.timestamp!) // .compareTo(DateTime.fromMillisecondsSinceEpoch(b.timestamp!))); // } // allConversations.sort((a, b) => // DateTime.fromMillisecondsSinceEpoch(a.lastmessagetimestmp!).compareTo( // DateTime.fromMillisecondsSinceEpoch(b.lastmessagetimestmp!))); // allConversations = allConversations.reversed.toList(); // notifyListeners(); // } // // getAllConversations(List conversations) { // allConversations = conversations; // allConversations.sort((a, b) => // DateTime.fromMillisecondsSinceEpoch(a.lastmessagetimestmp!).compareTo( // DateTime.fromMillisecondsSinceEpoch(b.lastmessagetimestmp!))); // allConversations = allConversations.reversed.toList(); // notifyListeners(); // } // // updateConversation( // {required MessageListModel conversation, // required String message, // required int senderId}) { // conversation.lastmessage = message; // conversation.lastmessagesenderid = senderId; // conversation.lastmessagetimestmp = DateTime.now().millisecondsSinceEpoch; // allConversations.sort((a, b) => // DateTime.fromMillisecondsSinceEpoch(a.lastmessagetimestmp!).compareTo( // DateTime.fromMillisecondsSinceEpoch(b.lastmessagetimestmp!))); // allConversations = allConversations.reversed.toList(); // notifyListeners(); // } // // setConversationCount( // {required MessageListModel message, required int count}) { // message.count = 0; // message.count = count; // notifyListeners(); // } // // onDisposeDiscussion() { // messagesList.clear(); // } // // onDisposeConversation() { // allConversations.clear(); // } // // UserConversation._internal(); // // showNotification() { // showNotif = true; // notifyListeners(); // } // // hideNotification() { // showNotif = false; // notifyListeners(); // } // // addAConversation(MessageListModel conversation) { // allConversations.insert(0, conversation); // notifyListeners(); // } // } // // final userConversationSingleton = UserConversation();