|
|
|
@ -94,10 +94,9 @@ class ChatVM extends ChangeNotifier {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> onNewMessageReceived({required List<ChatMessageModel> messages, required BuildContext context}) async {
|
|
|
|
Future<void> onNewMessageReceived({required List<ChatMessageModel> messages, required BuildContext context}) async {
|
|
|
|
|
|
|
|
log("message I received in onNewMessageReceived ${messages.first.toString()}");
|
|
|
|
if (AppState().currentAppType == AppType.customer) {
|
|
|
|
if (AppState().currentAppType == AppType.customer) {
|
|
|
|
for (var msg in messages) {
|
|
|
|
for (var msg in messages) {
|
|
|
|
log("printing senderUserID: ${msg.senderUserID}");
|
|
|
|
|
|
|
|
log("printing providerUserId: ${serviceProviderOffersList.first.providerUserId}");
|
|
|
|
|
|
|
|
int providerIndex = serviceProviderOffersList.indexWhere((element) => element.providerUserId == msg.senderUserID);
|
|
|
|
int providerIndex = serviceProviderOffersList.indexWhere((element) => element.providerUserId == msg.senderUserID);
|
|
|
|
if (providerIndex != -1) {
|
|
|
|
if (providerIndex != -1) {
|
|
|
|
serviceProviderOffersList[providerIndex].chatMessages!.add(msg);
|
|
|
|
serviceProviderOffersList[providerIndex].chatMessages!.add(msg);
|
|
|
|
@ -105,9 +104,11 @@ class ChatVM extends ChangeNotifier {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
for (var msg in messages) {
|
|
|
|
for (var msg in messages) {
|
|
|
|
int providerIndex = context.read<RequestsVM>().myFilteredRequests.indexWhere((element) => element.customerUserID == msg.receiverUserID);
|
|
|
|
int providerIndex = context.read<RequestsVM>().myFilteredRequests.indexWhere(
|
|
|
|
|
|
|
|
(element) => element.customerUserID == msg.receiverUserID,
|
|
|
|
|
|
|
|
); // Where we need to call this function for saving a message in chat we will use receiverUserID and in those cases where received ID is null , it means it is a signal R call
|
|
|
|
log("here is it: $providerIndex");
|
|
|
|
log("here is it: $providerIndex");
|
|
|
|
log("here is it: ${msg.senderUserID}");
|
|
|
|
log("here is it: ${msg.receiverUserID}");
|
|
|
|
log("here is it: ${context.read<RequestsVM>().myFilteredRequests.first.customerUserID.toString()}");
|
|
|
|
log("here is it: ${context.read<RequestsVM>().myFilteredRequests.first.customerUserID.toString()}");
|
|
|
|
if (providerIndex != -1) {
|
|
|
|
if (providerIndex != -1) {
|
|
|
|
context.read<RequestsVM>().addChatMessagesInRequestsModel(msg: msg, index: providerIndex);
|
|
|
|
context.read<RequestsVM>().addChatMessagesInRequestsModel(msg: msg, index: providerIndex);
|
|
|
|
@ -222,6 +223,8 @@ class ChatVM extends ChangeNotifier {
|
|
|
|
requestID: requestId,
|
|
|
|
requestID: requestId,
|
|
|
|
senderName: name,
|
|
|
|
senderName: name,
|
|
|
|
senderUserID: userId,
|
|
|
|
senderUserID: userId,
|
|
|
|
|
|
|
|
chatMessageTypeEnum: ChatMessageTypeEnum.freeText,
|
|
|
|
|
|
|
|
receiverUserID: receiverId,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (AppState().currentAppType == AppType.customer) {
|
|
|
|
if (AppState().currentAppType == AppType.customer) {
|
|
|
|
@ -230,7 +233,7 @@ class ChatVM extends ChangeNotifier {
|
|
|
|
serviceProviderOffersList[providerIndex].chatMessages!.add(chatMessageModel);
|
|
|
|
serviceProviderOffersList[providerIndex].chatMessages!.add(chatMessageModel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
int providerIndex = context.read<RequestsVM>().myFilteredRequests.indexWhere((element) => element.customerID == receiverId);
|
|
|
|
int providerIndex = context.read<RequestsVM>().myFilteredRequests.indexWhere((element) => element.customerUserID == receiverId);
|
|
|
|
if (providerIndex != -1) {
|
|
|
|
if (providerIndex != -1) {
|
|
|
|
context.read<RequestsVM>().addChatMessagesInRequestsModel(msg: chatMessageModel, index: providerIndex);
|
|
|
|
context.read<RequestsVM>().addChatMessagesInRequestsModel(msg: chatMessageModel, index: providerIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|