sendMessage method

Future<void> sendMessage()

Implementation

Future<void> sendMessage() async {
  final messageRequest = MessageModel(
    messageController.text,
    ChatBotLlm.uuid,
    threadId,
    timestampInMillis: DateTime.now().millisecondsSinceEpoch,
  );
  messageController.clear();
  messages.insert(0, messageRequest);
  isResponseLoading.value = true;

  MessageModel messageResponse = await _apiRepo.sendMessage(messageRequest);

  messageResponse.threadId = messageResponse.response?.threadId ?? "";
  threadId ??= messageResponse.threadId ?? "";

  messages.firstWhereOrNull((element) =>
      element.timestampInMillis == messageRequest.timestampInMillis)
    ?..response = messageResponse.response
    ..isReading = true;
  Fimber.d("messageResponse: $messageResponse");
  readMessage(messageResponse);

  isResponseLoading.value = false;
  showSendIcon.value = false;
}